uid = $uid; $this->name = $name; $this->password = $password; } /** * function save() * Saves the current object into the database */ public function save() { //Ensure the required folder exists. if(!is_dir('data/users/')) mkdir('data/users/'); $model = ResearchToolObject::load(Respondent::$filename); $resourceRespondent = new Resource(RESPONDENT . '/' . $this->uid); //Remove the old value stored with the given id $model->subtract($model->find($resourceRespondent, null, null)); //Set the new values $resourceRespondentType = new Resource(RESPONDENT); $predicateRType = new Resource(RTYPE); $model->add(new Statement($resourceRespondent,$predicateRType,$resourceRespondentType)); $literalRespondentID = new Literal($this->uid); $predicateUniqueID = new Resource(UID); $model->add(new Statement($resourceRespondent,$predicateUniqueID,$literalRespondentID)); $literalRespondentName = new Literal($this->name); $predicateName = new Resource(NAME); $model->add(new Statement($resourceRespondent,$predicateName,$literalRespondentName)); $literalPassword = new Literal($this->password); $predicatePassword = new Resource(PASSWORD); $model->add(new Statement($resourceRespondent,$predicatePassword,$literalPassword)); $model->saveAs(Respondent::$filename, 'rdf'); return true; } /** * static function get($arguments) * Gets the array of Respondent objects belonging to arguments supplied. * @param type $arguments : An array containing zero or more of the following keys: 'uid', 'name', 'password' */ public static function get($arguments) { $model = ResearchToolObject::load(Respondent::$filename); //Create the querystring $querystring = ' PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> SELECT ?uid, ?name, ?password WHERE { _respondent predicates:resource_type resources:respondent ; predicates:uid ?uid ; predicates:name ?name ; predicates:password ?password ; ' . ResearchToolObject::createArguments($arguments) . ' }'; //Query the model $results = $model->sparqlQuery($querystring); $respondents = array(); if(!empty($results)) { //Run over all results and create appropriate Respondent objets foreach($results as $result) { $respondents[] = new Respondent($result['?uid']->label, $result['?name']->label, $result['?password']->label); } } return $respondents; } }