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 User objects belonging to arguments supplied. * @param type $arguments : An array containing zero or more of the following keys: * 'uid', 'name', 'password', 'style' */ 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 { _user predicates:resource_type resources:user ; predicates:uid ?uid ; predicates:name ?name ; predicates:password ?password ; predicates:uid ' . $uid . ' predicates:name ' . $name . ' predicates:password ' . $password . ' }'; echo $querystring; //Query the model $results = $this->model->sparqlQuery($querystring); $users = array(); if(!empty($results)) { //Run over all results and create appropriate Application objets foreach($results as $result) { $users[] = new User($result['?uid']->label, $result['?name']->label, $result['?password']->label); } } return $users; } /** * Save the given User object in the file. * @param type $rToolObject */ public function set($rToolObject) { $this->load(); $resourceUser = new Resource(USER . '/' . $rToolObject->uid); //Remove the old value stored with the given id $this->model->subtract($this->model->find($resourceUser, null, null)); $resourceUserType = new Resource(USER); $predicateRType = new Resource(RTYPE); $this->model->add(new Statement($resourceUser,$predicateRType,$resourceUserType)); $literalUserID = new Literal($rToolObject->uid); $predicateUniqueID = new Resource(UID); $this->model->add(new Statement($resourceUser,$predicateUniqueID,$literalUserID)); $literalUserName = new Literal($rToolObject->name); $predicateName = new Resource(NAME); $this->model->add(new Statement($resourceUser,$predicateName,$literalUserName)); $literalPassword = new Literal($rToolObject->password); $predicatePassword = new Resource(PASSWORD); $this->model->add(new Statement($resourceUser,$predicatePassword,$literalPassword)); $this->save(); } } ?>