model = ModelFactory::getDefaultModel(); //Ensure the required file exists before loading if(file_exists($this->fileName)) $this->model->load($this->fileName); } /** * function save() * Saves the MemModel into the given file. */ public function save() { $this->model->saveAs($this->fileName,'rdf'); } /** * 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 function get($arguments) { $this->load(); //Determine which arguments are supplied $keys = array_keys($arguments); //Set default values for arguments $uid = "?uid"; $name = "?name"; $password = "?password"; //Set the arguments if they are supplied if(in_array("uid", $keys)) $uid = "\"".$arguments["uid"]."\""; if(in_array("name", $keys)) $name = '\''.$arguments["name"].'\''; if(in_array("password", $keys)) $password = "\"".$arguments["password"]."\""; //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 ; predicates:uid ' . $uid . ' predicates:name ' . $name . ' predicates:password ' . $password . ' }'; //Query the model $results = $this->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; } /** * Save the given User object in the file. * @param type $rToolObject */ public function set($rToolObject) { $this->load(); $resourceRespondent = new Resource(RESPONDENT . '/' . $rToolObject->uid); //Remove the old value stored with the given id $this->model->subtract($this->model->find($resourceRespondent, null, null)); //Set the new values $resourceRespondentType = new Resource(RESPONDENT); $predicateRType = new Resource(RTYPE); $this->model->add(new Statement($resourceRespondent,$predicateRType,$resourceRespondentType)); $literalRespondentID = new Literal($rToolObject->uid); $predicateUniqueID = new Resource(UID); $this->model->add(new Statement($resourceRespondent,$predicateUniqueID,$literalRespondentID)); $literalRespondentName = new Literal($rToolObject->name); $predicateName = new Resource(NAME); $this->model->add(new Statement($resourceRespondent,$predicateName,$literalRespondentName)); $literalPassword = new Literal($rToolObject->password); $predicatePassword = new Resource(PASSWORD); $this->model->add(new Statement($resourceRespondent,$predicatePassword,$literalPassword)); $this->save(); } } ?>