Changeset 298 for Dev/branches/jos-branch
- Timestamp:
- 03/01/12 15:02:59 (13 years ago)
- Location:
- Dev/branches/jos-branch/server
- Files:
-
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/jos-branch/server/classes/models/Answer.php
r285 r298 50 50 if(is_string($this->question)) 51 51 { 52 $result = Question::get(array("uid" => $this->question)); 52 $ans = ResearchToolObject::stripUri($this->question); 53 $result = Question::get(array("uid" => $ans["uid"])); 53 54 if(!isset($result[0])) 54 55 return false; … … 71 72 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 72 73 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 73 SELECT DISTINCT ?uid, ? question_code74 SELECT DISTINCT ?uid, ?to_question 74 75 WHERE 75 76 { … … 77 78 78 79 predicates:uid ?uid ; 79 predicates: question_code ?question_code;80 predicates:to_question ?to_question ; 80 81 ' . ResearchToolObject::createArguments($arguments) . ' 81 82 }'; … … 83 84 //Query the model 84 85 $results = $model->sparqlQuery($querystring); 85 //An answer can have multiple values, get all these values for the answer instances found.86 //An answer can have multiple values, get all these values for the answer instances found. 86 87 $answers = array(); 87 88 if(!empty($results)) … … 89 90 foreach($results as $result) 90 91 { 91 $answers[] = new Answer($result['?uid']->label, $result['? question_code']->label, Answer::getValues($model, $result['?uid']->label));92 $answers[] = new Answer($result['?uid']->label, $result['?to_question']->uri, Answer::getValues($model, $result['?uid']->label)); 92 93 } 93 94 } … … 142 143 $model->add(new Statement($resourceAnswer, $predicateId, $answerId)); 143 144 144 $questionId = new Literal($this->question->uid);145 $predicateQId = new Resource( QCODE);145 $questionId = new Resource(QUESTION . '/' . $this->question->uid); 146 $predicateQId = new Resource(TO_QUESTION); 146 147 $model->add(new Statement($resourceAnswer, $predicateQId, $questionId)); 147 148 -
Dev/branches/jos-branch/server/classes/models/AnswerSet.php
r285 r298 46 46 if(is_string($this->survey)) 47 47 { 48 $result = Survey::get(array("uid" => $this->survey)); 48 $surv = ResearchToolObject::stripUri($this->survey); 49 $result = Survey::get(array("uid" => $surv["uid"])); 49 50 if(!isset($result[0])) 50 51 return false; … … 53 54 if(is_string($this->respondent)) 54 55 { 55 $result = Respondent::get(array("uid" => $this->respondent)); 56 $resp = ResearchToolObject::stripUri($this->respondent); 57 $result = Respondent::get(array("uid" => $resp["uid"])); 56 58 if(!isset($result[0])) 57 59 return false; … … 63 65 foreach($this->answers as $answer) 64 66 { 65 $result = Answer::get(array("uid" => $answer)); 67 $answ = ResearchToolObject::stripUri($answer); 68 $result = Answer::get(array("uid" => $answ["uid"])); 66 69 if(!isset($result[0])) 67 70 return false; … … 91 94 $model = ResearchToolObject::load(AnswerSet::$filename); 92 95 93 94 96 $resourceAnswerSet = new Resource(ANSWERSET . '/' . $this->uid); 95 97 //Remove the old value stored with the given id … … 105 107 $model->add(new Statement($resourceAnswerSet, $predicateId, $answerSetId)); 106 108 107 $surveyId = new Literal($this->survey->uid);109 $surveyId = new Resource(SURVEY . '/' . $this->survey->uid); 108 110 $predicateSurvey = new Resource(FOR_SURVEY); 109 111 $model->add(new Statement($resourceAnswerSet, $predicateSurvey, $surveyId)); 110 112 111 $respondentId = new Literal($this->respondent->uid);113 $respondentId = new Resource(RESPONDENT . '/' . $this->respondent->uid); 112 114 $predicateRespondent = new Resource(BY_RESPONDENT); 113 115 $model->add(new Statement($resourceAnswerSet, $predicateRespondent, $respondentId)); … … 121 123 foreach($this->answers as $answer) 122 124 { 123 $answerId = new Literal($answer->uid);125 $answerId = new Resource(ANSWER . '/' . $answer->uid); 124 126 $predicateAnswer = new Resource(GIVEN_ANSWER); 125 127 $model->add(new Statement($resourceAnswerSet, $predicateAnswer, $answerId)); … … 160 162 foreach($results as $result) 161 163 { 162 $survey = $result['?for_survey']-> label;163 $respondent = $result['?by_respondent']-> label;164 $survey = $result['?for_survey']->uri; 165 $respondent = $result['?by_respondent']->uri; 164 166 $datetime = new DateTime(); 165 167 $datetime->setTimestamp(intval($result['?datetime']->label)); -
Dev/branches/jos-branch/server/classes/models/ApplicationInstance.php
r287 r298 128 128 { 129 129 $model = ResearchToolObject::load(ApplicationInstance::$filename); 130 $model->writeAsHTMLTable();131 132 130 //Build the query string 133 131 $querystring = ' … … 162 160 } 163 161 return $aInstances; 164 165 166 162 } 167 163 -
Dev/branches/jos-branch/server/classes/models/ResearchToolObject.php
r287 r298 61 61 { 62 62 case "uid" : $addition = "predicates:uid '" . $arguments[$key] . "'\n"; break; 63 case " question" : $addition = "predicates:question_code '" . $arguments[$key] . "'\n"; break;63 case "to_question" : $addition = "predicates:to_question <" . QUESTION . '/' . $arguments[$key] . ">\n"; break; 64 64 case "values": foreach($arguments[$key] as $value) { $addition = $addition . "predicates:answered '" . $value . "'\n"; } break; 65 case "survey" : $addition = "predicates:for_survey '" . $arguments[$key] . "'\n"; break;66 case "respondent" : $addition = "predicates:by_respondent '" . $arguments[$key] . "'\n"; break;67 case "answers" : foreach($arguments[$key] as $answer) { $addition = $addition . "predicates:given_answer '" . $answer . "'\n"; } break;65 case "survey" : $addition = "predicates:for_survey <" . SURVEY . '/' . $arguments[$key] . ">\n"; break; 66 case "respondent" : $addition = "predicates:by_respondent <" . RESPONDENT . '/' . $arguments[$key] . ">\n"; break; 67 case "answers" : foreach($arguments[$key] as $answer) { $addition = $addition . "predicates:given_answer <" . ANSWER . '/' . $answer . ">\n"; } break; 68 68 case "title" : $addition = "predicates:title '" . $arguments[$key] . "'\n"; break; 69 69 case "description" : $addition = "predicates:description '" . $arguments[$key] . "'\n"; break; … … 75 75 case "email" : $addition = "predicates:email '" . $arguments[$key] . "'\n"; break; 76 76 case "password" : $addition = "predicates:password '" . $arguments[$key] . "'\n"; break; 77 case "creator" : $addition = "predicates:creator '" . $arguments[$key] . "'\n"; break;77 case "creator" : $addition = "predicates:creator <" . USER . '/' . $arguments[$key] . ">\n"; break; 78 78 case "creationdate" : $addition = "predicates:creationdate '" . $arguments[$key] . "'\n"; break; 79 case "applications" : foreach($arguments[$key] as $application) { $addition = $addition . "predicates:has_application '" . $application . "'\n"; } break;80 case "surveys" : foreach($arguments[$key] as $survey) { $addition = $addition . "predicates:has_survey '" . $survey . "'\n"; } break;81 case "answersets" : foreach($arguments[$key] as $answerset) { $addition = $addition . "predicates:has_answerset '" . $answerset . "'\n"; } break;82 case "questions" : foreach($arguments[$key] as $question) { $addition = $addition . "predicates:has_question '" . $question . "'\n"; } break;79 case "applications" : foreach($arguments[$key] as $application) { $addition = $addition . "predicates:has_application <" . APPLICATION . '/' . $application . ">\n"; } break; 80 case "surveys" : foreach($arguments[$key] as $survey) { $addition = $addition . "predicates:has_survey <" . SURVEY . '/' . $survey . ">\n"; } break; 81 case "answersets" : foreach($arguments[$key] as $answerset) { $addition = $addition . "predicates:has_answerset <" . ANSWERSET . '/' . $answerset . ">\n"; } break; 82 case "questions" : foreach($arguments[$key] as $question) { $addition = $addition . "predicates:has_question <" . QUESTION . '/' . $question . ">\n"; } break; 83 83 case "location" : $addition = "predicates:location '" . $arguments[$key] . "'\n"; break; 84 case "facilitator" : $addition = "predicates:facilitator '" . $arguments[$key] . "'\n"; break;84 case "facilitator" : $addition = "predicates:facilitator <" . USER . '/' . $arguments[$key] . ">\n"; break; 85 85 case "starttime" : $addition = "predicates:starttime '" . $arguments[$key] . "'\n"; break; 86 86 case "endtime" : $addition = "predicates:endtime '" . $arguments[$key] . "'\n"; break; 87 case "session" : $addition = "predicates:of_session '" . $arguments[$key] . "'\n"; break;87 case "session" : $addition = "predicates:of_session <" . SURVEY . '/' . $arguments[$key] . ">\n"; break; 88 88 case "resultset" : $addition = "predicates:has_resultset '" . $arguments[$key] . "'\n"; break; 89 89 case "of_application" : $addition = "predicates:of_application <" . APPLICATION . '/' . $arguments[$key] . ">\n"; break; 90 90 case "open" : $addition = "predicates:open '" . $arguments[$key] . "\n"; break; 91 case "applicationinstances" : foreach($arguments[$key] as $instance) { $addition = $addition . "predicates:has_applicationinstance <" . APPLICATIONINSTANCE . '/' . $instance . ">\n"; } break; 92 case "has_surveyinstance" : foreach($arguments[$key] as $instance) { $addition = $addition . "predicates:has_surveyinstance <" . SURVEYINSTANCE . '/' . $instance . ">\n"; } break; 93 case "preset_answers" : foreach($arguments[$key] as $instance) { $addition = $addition . "predicates:preset_answer <" . ANSWER . '/' . $instance . ">\n"; } break; 91 94 } 92 95 $argumentString = $argumentString . $addition; -
Dev/branches/jos-branch/server/classes/models/Session.php
r285 r298 48 48 if(is_string($this->creator)) 49 49 { 50 $result = User::get(array("uid" => $this->creator)); 50 $crea = ResearchToolObject::stripUri($this->creator); 51 $result = User::get(array("uid" => $crea["uid"])); 51 52 if(!isset($result[0])) 52 53 return false; … … 54 55 } 55 56 if(!empty($this->pipeline) && is_string($this->pipeline[0])) 56 { 57 { 57 58 $newPipeline = array(); 58 59 foreach($this->pipeline as $element) 59 60 { 60 //Check if the element's UID can be found in surveys, if not: 61 //Check applications. If it isn't in either: invalid reference. 62 $result = Survey::get(array("uid" => $element)); 63 if(!isset($result[0])) 64 $result = Application::get(array("uid" => $element)); 61 $ele = ResearchToolObject::stripUri($element); 62 $result; 63 if($ele["type"] == "survey") 64 { 65 $result = Survey::get(array("uid" => $ele["uid"])); 66 } 67 else if($ele["type"] == "application") 68 { 69 $result = Application::get(array("uid" => $ele["uid"])); 70 } 65 71 if(!isset($result[0])) 66 72 return false; … … 107 113 $model->add(new Statement($resourceSession, $predicateTitle, $sessionTitle)); 108 114 109 $sessionCreator = new Literal($this->creator->uid);115 $sessionCreator = new Resource(USER . '/' . $this->creator->uid); 110 116 $predicateCreator = new Resource(CREATOR); 111 117 $model->add(new Statement($resourceSession, $predicateCreator, $sessionCreator)); … … 121 127 foreach($this->pipeline as $element) 122 128 { 123 $sessionObject = n ew Literal($element->uid);129 $sessionObject = null; 124 130 $predicateObject = null; 125 131 if(get_class($element) == "Application") 132 { 133 $sessionObject = new Resource(APPLICATION . '/' . $element->uid); 126 134 $predicateObject = new Resource(HAS_APPLICATION); 135 } 127 136 else if(get_class($element) == "Survey") 137 { 138 $sessionObject = new Resource(SURVEY . '/' . $element->uid); 128 139 $predicateObject = new Resource(HAS_SURVEY); 140 } 129 141 if(isset($predicateObject)) 130 142 $model->add(new Statement($resourceSession, $predicateObject, $sessionObject)); … … 132 144 } 133 145 134 if(isset($this->answersets))135 {136 foreach($this->answersets as $answerset)137 {138 $sessionAnswerSet = new Literal($answerset->uid);139 $predicateAnswerSet = new Resource(HAS_ANSWERSET);140 $model->add(new Statement($resourceSession, $predicateAnswerSet, $sessionAnswerSet));141 }142 }143 144 146 return $model->saveAs(Session::$filename, 'rdf'); 145 147 } … … 178 180 //Create a session object out of every result, get all required fields as well. 179 181 $pipeline = Session::getPipeline($model, $result['?uid']->label); 180 $creator = $result['?creator']-> label;182 $creator = $result['?creator']->uri; 181 183 $creationdate = new DateTime(); 182 184 $creationdate->setTimestamp(intval($result['?creationdate']->label)); -
Dev/branches/jos-branch/server/classes/models/SessionInstance.php
r285 r298 22 22 public $notes; 23 23 public $session; 24 public $resultset; 24 public $surveyinstances; 25 public $applicationinstances; 25 26 26 27 /** … … 34 35 * @param type $notes 35 36 * @param type $session 36 * @param type $resultset 37 */ 38 public function __construct($uid = null, $title = null, $location = null, $facilitator = null, $starttime = null, $endtime = null, $notes = null, $session = null, $resultset = null) 37 * @param type $surveyinstances 38 * @param type $applicationinstances 39 */ 40 public function __construct($uid = null, $title = null, $location = null, $facilitator = null, $starttime = null, $endtime = null, $notes = null, $session = null, $surveyinstances = null, $applicationinstances = null) 39 41 { 40 42 if(!isset($uid)) … … 50 52 $this->notes = $notes; 51 53 $this->session = $session; 52 $this->resultset = $resultset; 54 $this->surveyinstances = $surveyinstances; 55 $this->applicationinstances = $applicationinstances; 53 56 } 54 57 … … 61 64 if(is_string($this->facilitator)) 62 65 { 63 $result = User::get(array("uid" => $this->facilitator)); 66 $faci = ResearchToolObject::stripUri($this->facilitator); 67 $result = User::get(array("uid" => $faci["uid"])); 64 68 if(!isset($result[0])) 65 69 return false; … … 69 73 if(is_string($this->session)) 70 74 { 71 $result = Session::get(array("uid" => $this->session)); 75 $sess = ResearchToolObject::stripUri($this->session); 76 $result = Session::get(array("uid" => $sess["uid"])); 72 77 if(!isset($result[0])) 73 78 return false; 74 79 $this->session = $result[0]; 75 80 } 76 77 if(is_string($this->resultset)) 78 { 79 $result = ResultSet::get(array("uid" => $this->resultset)); 80 if(!isset($result[0])) 81 return false; 82 $this->resultset = $result[0]; 81 if(!empty($this->surveyinstances) && is_string($this->surveyinstances[0])) 82 { 83 $newSurveyInstances = array(); 84 foreach($this->surveyinstances as $surveyInstance) 85 { 86 $sins = ResearchToolObject::stripUri($surveyInstance); 87 $result = SurveyInstance::get(array("uid" => $sins["uid"])); 88 if(!isset($result[0])) 89 return false; 90 $newSurveyInstances[] = $result[0]; 91 } 92 $this->surveyinstances = $newSurveyInstances; 93 } 94 95 if(!empty($this->applicationinstances) && is_string($this->applicationinstances[0])) 96 { 97 $newApplicationInstances = array(); 98 foreach($this->applicationinstances as $applicationInstance) 99 { 100 $ains = ResearchToolObject::stripUri($applicationInstance); 101 $result = ApplicationInstance::get(array("uid" => $ains["uid"])); 102 if(!isset($result[0])) 103 return false; 104 $newApplicationInstances[] = $result[0]; 105 } 106 $this->applicationinstances = $newApplicationInstances; 83 107 } 84 108 return true; … … 124 148 $model->add(new Statement($resourceSInstance, $predicateLocation, $sInstanceLocation)); 125 149 126 $sInstanceFacilitator = new Literal($this->facilitator->uid);150 $sInstanceFacilitator = new Resource(USER . '/' . $this->facilitator->uid); 127 151 $predicateFacilitator = new Resource(FACILITATOR); 128 152 $model->add(new Statement($resourceSInstance, $predicateFacilitator, $sInstanceFacilitator)); … … 146 170 } 147 171 148 $sInstanceSession = new Literal($this->session->uid);172 $sInstanceSession = new Resource(SESSION . '/' . $this->session->uid); 149 173 $predicateSession = new Resource(OF_SESSION); 150 174 $model->add(new Statement($resourceSInstance, $predicateSession, $sInstanceSession)); 151 175 152 if(isset($this->resultset)) 153 { 154 //$sInstanceResultSet = new Literal($this->resultset->uid); 155 $sInstanceResultSet = new Literal($this->resultset); 156 $predicateResultSet = new Resource(HAS_RESULTSET); 157 $model->add(new Statement($resourceSInstance, $predicateResultSet, $sInstanceResultSet)); 158 } 176 if(isset($this->surveyinstances)) 177 { 178 foreach($this->surveyinstances as $surveyinstance) 179 { 180 $sInstanceSurveyInstance = new Resource(SURVEYINSTANCE . '/' . $surveyinstance->uid); 181 $predicateSurveyInstance = new Resource(HAS_SURVEYINSTANCE); 182 $model->add(new Statement($resourceSInstance, $predicateSurveyInstance, $sInstanceSurveyInstance)); 183 } 184 } 185 186 if(isset($this->applicationinstances)) 187 { 188 foreach($this->applicationinstances as $applicationinstance) 189 { 190 $sInstanceAppInstance = new Resource(APPLICATIONINSTANCE . '/' . $applicationinstance->uid); 191 $predicateAppInstance = new Resource(HAS_APPLICATIONINSTANCE); 192 $model->add(new Statement($resourceSInstance, $predicateAppInstance, $sInstanceAppInstance)); 193 } 194 } 195 159 196 $model->saveAs(SessionInstance::$filename, 'rdf'); 160 197 return true; … … 164 201 * function get() 165 202 * @param type $arguments : An array containing one or more of the following elements: 166 * 'uid', 'title', 'location', 'facilitator', 'starttime', 'endtime' 'notes', 'session', ' resultset'203 * 'uid', 'title', 'location', 'facilitator', 'starttime', 'endtime' 'notes', 'session', 'applicationinstances', 'surveyinstances' 167 204 */ 168 205 public static function get($arguments) … … 174 211 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 175 212 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 176 SELECT DISTINCT ?uid, ?title, ?location, ?facilitator, ?starttime, ?endtime, ?of_session , ?has_resultset213 SELECT DISTINCT ?uid, ?title, ?location, ?facilitator, ?starttime, ?endtime, ?of_session 177 214 WHERE 178 215 { … … 185 222 predicates:endtime ?endtime ; 186 223 predicates:of_session ?of_session ; 187 predicates:has_resultset ?has_resultset ;188 224 ' . ResearchToolObject::createArguments($arguments) . ' 189 225 }'; … … 196 232 { 197 233 //Create a SessionInstance object out of every result. Get all the required fields as well. 198 $ notes = SessionInstance::getNotes($model, $result['?uid']->label);234 $fields = SessionInstance::getFields($model, $result['?uid']->label); 199 235 $resultset = isset($result['?has_resultset']) ? $result['?has_resultset']->label : null; 200 236 $starttime = new DateTime(); … … 206 242 $result['?title']->label, 207 243 $result['?location']->label, 208 $result['?facilitator']-> label,244 $result['?facilitator']->uri, 209 245 $starttime, 210 246 $endtime, 211 $notes, 212 $result['?of_session'], 213 $resultset 247 $fields[0], 248 $result['?of_session']->uri, 249 $fields[1], 250 $fields[2] 214 251 ); 215 252 } … … 219 256 220 257 /** 221 * function getNotes() 222 * param type $uid : The SessionInstance uid for which the notes should be retrieved. 223 */ 224 public static function getNotes($model, $uid) 225 { 226 $result = $model->findRegex("[(".$uid.")]", "[(has_note)]", null); 258 * function getFields() 259 * param type $uid : The SessionInstance uid for which the fields should be retrieved. 260 * returns : An array with [0] => all notes, [1] => all SurveyInstances and [2] => all ApplicationInstances. 261 */ 262 public static function getFields($model, $uid) 263 { 264 $result = $model->findRegex("[(".$uid.")]", "[(has_note)|(has_applicationinstance)|(has_surveyinstance)]", null); 227 265 $iterator = $result->getStatementIterator(); 228 266 $notes = array(); 267 $applicationinstances = array(); 268 $surveyinstances = array(); 229 269 while($iterator->hasNext()) 230 270 { 231 271 $element = $iterator->next(); 232 $notes[] = $element->getLabelObject(); 233 } 234 return $notes; 272 if($element->getLabelPredicate() == HAS_NOTE) 273 $notes[] = $element->getLabelObject(); 274 else if($element->getLabelPredicate() == HAS_APPLICATIONINSTANCE) 275 $applicationinstances[] = $element->getLabelObject(); 276 else if($element->getLabelPredicate() == HAS_SURVEYINSTANCE) 277 $surveyinstances[] = $element->getLabelObject(); 278 } 279 return array($notes, $surveyinstances, $applicationinstances); 235 280 } 236 281 -
Dev/branches/jos-branch/server/classes/models/Survey.php
r285 r298 32 32 public function evaluate() 33 33 { 34 34 35 if(is_string($this->creator)) 35 36 { 36 $result = User::get(array("uid" => $this->creator)); 37 $crea = ResearchToolObject::stripUri($this->creator); 38 $result = User::get(array("uid" => $crea["uid"])); 37 39 if(!isset($result[0])) 38 40 return false; … … 45 47 foreach($this->questions as $question) 46 48 { 47 $result = Question::get(array("code" => $question)); 49 $ques = ResearchToolObject::stripUri($question); 50 $result = Question::get(array("uid" => $ques["uid"])); 48 51 if(!isset($result[0])) 49 52 return false; … … 93 96 94 97 $predicateCreator = new Resource(CREATOR); 95 $surveyCreator = new Literal($this->creator->uid);98 $surveyCreator = new Resource(USER . '/' . $this->creator->uid); 96 99 $model->add(new Statement($resourceSurvey, $predicateCreator, $surveyCreator)); 97 100 … … 100 103 foreach($this->questions as $question) 101 104 { 102 $questionUid = new Literal($question->uid);105 $questionUid = new Resource(QUESTION . '/' . $question->uid); 103 106 $predicateQuid = new Resource(HAS_QUESTION); 104 107 $model->add(new Statement($resourceSurvey,$predicateQuid,$questionUid)); … … 145 148 { 146 149 $questions = Survey::getQuestions($model, $result['?uid']->label); 147 $creator = $result['?creator']-> label;150 $creator = $result['?creator']->uri; 148 151 $surveys[] = new Survey($result['?uid']->label, $result['?title']->label, $result['?description']->label, $creator, $questions); 149 152 } -
Dev/branches/jos-branch/server/classes/models/SurveyInstance.php
r286 r298 26 26 * @param type $answersets: A list of answersets. 27 27 */ 28 public function __construct($uid = null, $survey = null, $starttime = null, $endtime = null, $open = null, $presetanswers = null, $answersets = null)28 public function __construct($uid = null, $survey = null, $starttime = null, $endtime = null, $open = 0, $presetanswers = null, $answersets = null) 29 29 { 30 30 if(!isset($uid)) … … 37 37 $this->starttime = $starttime; 38 38 $this->endtime = $endtime; 39 39 $this->open = $open; 40 40 $this->presetanswers = $presetanswers; 41 41 $this->answersets = $answersets; … … 51 51 if(is_string($this->survey)) 52 52 { 53 $result = Survey::get(array("uid" => $this->survey)); 53 $surv = ResearchToolObject::stripUri($this->survey); 54 $result = Survey::get(array("uid" => $surv["uid"])); 54 55 if(!isset($result[0])) 55 56 { … … 65 66 foreach($this->presetanswers as $answer) 66 67 { 67 $result = Answer::get(array("uid" => $answer)); 68 $ans = ResearchToolObject::stripUri($answer); 69 $result = Answer::get(array("uid" => $ans["uid"])); 68 70 if(!isset($result[0])) 69 71 return false; … … 79 81 foreach($this->answersets as $answerSet) 80 82 { 81 $result = AnswerSet::get(array("uid" => $answerSet)); 83 $aset = ResearchToolObject::stripUri($answerSet); 84 $result = AnswerSet::get(array("uid" => $aset["uid"])); 82 85 if(!isset($result[0])) 83 86 { … … 132 135 $predicateEndTime = new Resource(ENDTIME); 133 136 $model->add(new Statement($resourceSI, $predicateEndTime, $SIEndTime)); 134 135 $SIOpen = new Literal($this->open); 137 $SIOpen = new Literal((bool) $this->open); 136 138 $predicateOpen = new Resource(OPEN); 137 139 $model->add(new Statement($resourceSI, $predicateOpen, $SIOpen)); … … 141 143 foreach($this->presetanswers as $answer) 142 144 { 143 $answerId = new Literal($answer->uid);145 $answerId = new Resource(ANSWER . '/' . $answer->uid); 144 146 $predicateAnswer = new Resource(PRESET_ANSWER); 145 147 $model->add(new Statement($resourceSI, $predicateAnswer, $answerId)); … … 151 153 foreach($this->answersets as $answer) 152 154 { 153 $answerSetId = new Literal($answer->uid);155 $answerSetId = new Resource(ANSWERSET . '/' . $answer->uid); 154 156 $predicateAnswerSet = new Resource(HAS_ANSWERSET); 155 157 $model->add(new Statement($resourceSI, $predicateAnswerSet, $answerSetId)); … … 163 165 * Gets the array of SurveyInstance objects belonging tothe arguments supplied. 164 166 * @param type $arguments: An array containing zero or more of the following keys: 165 * 'uid', 'of_survey', 'starttime', 'endtime', 'open', 'preset_answers', ' has_answerset'167 * 'uid', 'of_survey', 'starttime', 'endtime', 'open', 'preset_answers', 'answersets' 166 168 */ 167 169 public static function get($arguments) … … 195 197 $endTime = new DateTime(); 196 198 $endTime->setTimestamp(intval($result['?endtime']->label)); 197 $open = false; 198 if ($result['?open'] == 'true') 199 $open = true; 200 $presetAnswers = SurveyInstance::getPresetAnswers($model, $result['?uid']->label); 201 $answerSets = SurveyInstance::getAnswerSets($model, $result['?uid']->label); 202 $sInstances[] = new SurveyInstance($result['?uid']->label, $result['?of_survey']->uri, $startTime, $endTime, $open, $presetAnswers, $answerSets); 199 $open = (bool) $result['?open']; 200 $fields = SurveyInstance::getFields($model, $result['?uid']->label); 201 $sInstances[] = new SurveyInstance($result['?uid']->label, $result['?of_survey']->uri, $startTime, $endTime, $open, $fields[0], $fields[1]); 203 202 } 204 203 } … … 207 206 208 207 /** 209 * function get PresetAnswers()208 * function getFields() 210 209 * @param type $model : The RDF model to query against. 211 * @param type $uid : The UID of the SurveyInstance for which the preset answers should be retrieved. 210 * @param type $uid : The UID of the SurveyInstance for which the preset answers and answersets should be retrieved. 211 * returns : an array with [0] => all preset answers and [1] => all answersets. 212 212 */ 213 private static function get PresetAnswers($model, $uid)213 private static function getFields($model, $uid) 214 214 { 215 $result = $model->findRegex("[(".$uid.")]", "[(preset_answer) ]", null);215 $result = $model->findRegex("[(".$uid.")]", "[(preset_answer)|(has_answerset)]", null); 216 216 $iterator = $result->getStatementIterator(); 217 217 $answers = array(); 218 $sets = array(); 218 219 while($iterator->hasNext()) 219 220 { 220 221 $element = $iterator->next(); 221 $answers[] = $element->getLabelObject(); 222 if($element->getLabelPredicate() == PRESET_ANSWER) 223 $answers[] = $element->getLabelObject(); 224 else if($element->getLabelPredicate() == HAS_ANSWERSET) 225 $sets[] = $element->getLabelObject(); 222 226 } 223 return $answers; 224 } 225 226 /** 227 * function getAnswerSets() 228 * @param type $model : The RDF model to query against. 229 * @param type $uid : The UID of the SurveyInstance for which the preset answers should be retrieved. 230 */ 231 private static function getAnswerSets($model, $uid) 232 { 233 $result = $model->findRegex("[(".$uid.")]", "[(has_answerset)]", null); 234 $iterator = $result->getStatementIterator(); 235 $answersets = array(); 236 while($iterator->hasNext()) 237 { 238 $element = $iterator->next(); 239 $answersets[] = $element->getLabelObject(); 240 } 241 return $answersets; 227 return array($answers, $sets); 242 228 } 243 229 -
Dev/branches/jos-branch/server/rdfConstants.php
r285 r298 69 69 define('OF_SURVEY', SURVEYTOOL_PREDICATES_NAMESPACE . 'of_survey'); 70 70 define('PRESET_ANSWER', SURVEYTOOL_PREDICATES_NAMESPACE . 'preset_answer'); 71 define('TO_QUESTION', SURVEYTOOL_PREDICATES_NAMESPACE . 'to_question'); 72 define('HAS_APPLICATIONINSTANCE', SURVEYTOOL_PREDICATES_NAMESPACE . 'has_applicationinstance'); 73 define('HAS_SURVEYINSTANCE', SURVEYTOOL_PREDICATES_NAMESPACE . 'has_surveyinstance'); 71 74 ?>
Note: See TracChangeset
for help on using the changeset viewer.