- Timestamp:
- 03/03/12 19:09:19 (13 years ago)
- Location:
- Dev/branches/rest-dojo-ui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui
- Property svn:mergeinfo changed
/Dev/branches/jos-branch merged: 298
- Property svn:mergeinfo changed
-
Dev/branches/rest-dojo-ui/server/classes/models/SessionInstance.php
r274 r302 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
Note: See TracChangeset
for help on using the changeset viewer.