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 Application objects belonging to arguments supplied. * @param type $arguments : An array containing zero or more of the following keys: * 'uid', 'title', 'description', 'style' */ public function get($arguments) { $this->load(); //Determine which arguments are supplied $keys = array_keys($arguments); //Set default values for arguments $uid = "?uid"; $title = "?title"; $description = "?description"; $style = "?style"; //Set the arguments if they are supplied if(in_array("uid", $keys)) $uid = "\"".$arguments["uid"]."\""; if(in_array("title", $keys)) $title = '\''.$arguments["title"].'\''; if(in_array("description", $keys)) $description = "\"".$arguments["description"]."\""; if(in_array("style", $keys)) $style = "\"".$arguments["style"]."\""; //Create the querystring $querystring = ' PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> SELECT ?uid, ?title, ?description, ?style WHERE { _application predicates:resource_type resources:application ; predicates:uid ?uid ; predicates:title ?title ; predicates:description ?description ; predicates:style ?style ; predicates:uid ' . $uid . ' predicates:title ' . $title . ' predicates:description ' . $description . ' predicates:style ' . $style . ' }'; //Query the model $results = $this->model->sparqlQuery($querystring); $applications = array(); if(!empty($results)) { //Run over all results and create appropriate Application objets foreach($results as $result) { $applications[] = new Application($result['?uid']->label, $result['?title']->label, $result['?description']->label, $result['?style']->label); } } return $applications; } /** * function set() * Finds the required databaseentry matching the given object and removes * it from the rdf file. Then adds the new RDF entry matching the object. * @param type $rToolObject: The ResearchToolObject to be saved. */ public function set($rToolObject) { $this->load(); $resourceApplication = new Resource(APPLICATION.'/'.$rToolObject->uid); //Remove the old value stored with the given id $this->model->subtract($this->model->find($resourceApplication, null, null)); //Add the new statements to the model $resourceApplicationType = new Resource(APPLICATION); $predicateRType = new Resource(RTYPE); $this->model->add(new Statement($resourceApplication,$predicateRType,$resourceApplicationType)); $literalApplicationID = new Literal($rToolObject->uid); $predicateUniqueID = new Resource(UID); $this->model->add(new Statement($resourceApplication,$predicateUniqueID,$literalApplicationID)); $applicationTitle = new Literal($rToolObject->title); $predicateTitle = new Resource(TITLE); $this->model->add(new Statement($resourceApplication,$predicateTitle,$applicationTitle)); $applicationDescription = new Literal($rToolObject->description); $predicateDescription = new Resource(DESCRIPTION); $this->model->add(new Statement($resourceApplication,$predicateDescription,$applicationDescription)); $applicationStyle = new Literal($rToolObject->style); $predicateStyle = new Resource(STYLE); $this->model->add(new Statement($resourceApplication,$predicateStyle,$applicationStyle)); $this->save(); } } ?>