uid = $uid; $this->title = $title; $this->description = $description; $this->style = $style; } /** * function save() * Saves the current object into the database. */ public function save() { //Ensure the required folder exists. if(!is_dir('data/applications/')) mkdir('data/applications/'); $model = ResearchToolObject::load(Application::$filename); $resourceApplication = new Resource(APPLICATION.'/'.$this->uid); //Remove the old value stored with the given id $model->subtract($model->find($resourceApplication, null, null)); //Add the new statements to the model $resourceApplicationType = new Resource(APPLICATION); $predicateRType = new Resource(RTYPE); $model->add(new Statement($resourceApplication,$predicateRType,$resourceApplicationType)); $literalApplicationID = new Literal($this->uid); $predicateUniqueID = new Resource(UID); $model->add(new Statement($resourceApplication,$predicateUniqueID,$literalApplicationID)); $applicationTitle = new Literal($this->title); $predicateTitle = new Resource(TITLE); $model->add(new Statement($resourceApplication,$predicateTitle,$applicationTitle)); $applicationDescription = new Literal($this->description); $predicateDescription = new Resource(DESCRIPTION); $model->add(new Statement($resourceApplication,$predicateDescription,$applicationDescription)); $applicationStyle = new Literal($this->style); $predicateStyle = new Resource(STYLE); $model->add(new Statement($resourceApplication,$predicateStyle,$applicationStyle)); $model->saveAs(Application::$filename, 'rdf'); return true; } /** * static 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 static function get($arguments) { $model = ResearchToolObject::load(Application::$filename); //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 ; ' . ResearchToolObject::createArguments($arguments) . ' }'; //Query the model $results = $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; } } ?>