fileName = 'data/sessions/sessioninstances.rdf'; //Ensure the required folder for this connector exists. if(!is_dir('data/sessions')) mkdir('data/sessions'); } /** * function get() * @param type $arguments : An array containing one or more of the following elements: * 'uid', 'title', 'location', 'facilitator', 'starttime', 'endtime' 'notes', 'session', 'resultset' */ public function get($arguments) { $this->load(); //Build the query string $querystring = ' PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> SELECT DISTINCT ?uid, ?title, ?location, ?facilitator, ?starttime, ?endtime, ?of_session, ?has_resultset WHERE { _sessioninstance predicates:resource_type resources:sessioninstance ; predicates:uid ?uid ; predicates:title ?title ; predicates:location ?location ; predicates:facilitator ?facilitator ; predicates:starttime ?starttime ; predicates:endtime ?endtime ; predicates:of_session ?of_session ; ' . $this->createArguments($arguments) . ' }'; //Query the model $results = $this->model->sparqlQuery($querystring); $sessioninstances = array(); if(!empty($results)) { $this->db = new DatabaseInterface(); foreach($results as $result) { //Create a SessionInstance object out of every result. Get all the required fields as well. $notes = $this->getNotes($result['?uid']->label); $resultset = $this->getResultSet($result['?uid']->label); $starttime = new DateTime(); $starttime->setTimestamp(intval($result['?starttime']->label)); $endtime = new DateTime(); $endtime->setTimestamp(intval($result['?endtime']->label)); $sessioninstances[] = new SessionInstance( $result['?uid']->label, $result['?title']->label, $result['?location']->label, $result['?facilitator']->label, $starttime, $endtime, $notes, $result['?of_session'], $resultset ); } } return $sessioninstances; } /** * function getNotes() * param type $uid : The SessionInstance uid for which the notes should be retrieved. */ public function getNotes($uid) { $result = $this->model->findRegex("[(".$uid.")]", "[(has_note)]", null); $iterator = $result->getStatementIterator(); $notes = array(); while($iterator->hasNext()) { $element = $iterator->next(); $notes[] = $element->getLabelObject(); } return $notes; } /** * function getResultSet($uid) * param type $uid : The SessionInstance uid for which the ResultSet should be gotten. */ public function getResultSet($udi) { //TODO: Implement when ResultSet is in. return null; } /** * function set() * @param type $rToolObject: The ResearchToolObject to be saved. */ public function set($rToolObject) { $this->load(); //If evaluation fails, some references are incorrect. //We shouldn't save in this case. Instead - let the user know. This function returns false if the evaluation has failed. //TODO: Decide how to fix invalid references graciously. if(!$rToolObject->evaluate()) return false; $resourceSInstance = new Resource(SESSIONINSTANCE . '/' . $rToolObject->uid); //Remove the old value stored with the given id $this->model->subtract($this->model->find($resourceSInstance, null, null)); //Set the new values $resourceSInstanceType = new Resource(SESSIONINSTANCE); $predicateType = new Resource(RTYPE); $this->model->add(new Statement($resourceSInstance, $predicateType, $resourceSInstanceType)); $sInstanceId = new Literal($rToolObject->uid); $predicateId = new Resource(UID); $this->model->add(new Statement($resourceSInstance, $predicateId, $sInstanceId)); $sInstanceTitle = new Literal($rToolObject->title); $predicateTitle = new Resource(TITLE); $this->model->add(new Statement($resourceSInstance, $predicateTitle, $sInstanceTitle)); $sInstanceLocation = new Literal($rToolObject->location); $predicateLocation = new Resource(LOCATION); $this->model->add(new Statement($resourceSInstance, $predicateLocation, $sInstanceLocation)); $sInstanceFacilitator = new Literal($rToolObject->facilitator->uid); $predicateFacilitator = new Resource(FACILITATOR); $this->model->add(new Statement($resourceSInstance, $predicateFacilitator, $sInstanceFacilitator)); $sInstanceStartTime = new Literal($rToolObject->starttime->getTimestamp()); $predicateStartTime = new Resource(STARTTIME); $this->model->add(new Statement($resourceSInstance, $predicateStartTime, $sInstanceStartTime)); $sInstanceEndTime = new Literal($rToolObject->endtime->getTimestamp()); $predicateEndTime = new Resource(ENDTIME); $this->model->add(new Statement($resourceSInstance, $predicateEndTime, $sInstanceEndTime)); if(isset($rToolObject->notes)) { foreach($rToolObject->notes as $note) { $sInstanceNote = new Literal($note); $predicateNote = new Resource(HAS_NOTE); $this->model->add(new Statement($resourceSInstance, $predicateNote, $sInstanceNote)); } } $sInstanceSession = new Literal($rToolObject->session->uid); $predicateSession = new Resource(OF_SESSION); $this->model->add(new Statement($resourceSInstance, $predicateSession, $sInstanceSession)); if(isset($rToolObject->resultset)) { //$sInstanceResultSet = new Literal($rToolObject->resultset->uid); $sInstanceResultSet = new Literal($rToolObject->resultset); $predicateResultSet = new Resource(HAS_RESULTSET); $this->model->add(new Statement($resourceSInstance, $predicateResultSet, $sInstanceResultSet)); } $this->save(); return true; } } ?>