Ignore:
Timestamp:
03/03/12 19:09:19 (13 years ago)
Author:
hendrikvanantwerpen
Message:

Merge jos-branch 285:298

Location:
Dev/branches/rest-dojo-ui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui

  • Dev/branches/rest-dojo-ui/server/classes/models/SessionInstance.php

    r274 r302  
    2222        public $notes;
    2323        public $session;
    24         public $resultset;
     24        public $surveyinstances;
     25        public $applicationinstances;
    2526
    2627        /**
     
    3435         * @param type $notes
    3536         * @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)
    3941        {
    4042                if(!isset($uid))
     
    5052                $this->notes = $notes;
    5153                $this->session = $session;
    52                 $this->resultset = $resultset;
     54                $this->surveyinstances = $surveyinstances;
     55                $this->applicationinstances = $applicationinstances;
    5356        }
    5457
     
    6164                if(is_string($this->facilitator))
    6265                {
    63                         $result = User::get(array("uid" => $this->facilitator));
     66                        $faci = ResearchToolObject::stripUri($this->facilitator);
     67                        $result = User::get(array("uid" => $faci["uid"]));
    6468                        if(!isset($result[0]))
    6569                                return false;
     
    6973                if(is_string($this->session))
    7074                {
    71                         $result = Session::get(array("uid" => $this->session));
     75                        $sess = ResearchToolObject::stripUri($this->session);
     76                        $result = Session::get(array("uid" => $sess["uid"]));
    7277                        if(!isset($result[0]))
    7378                                return false;
    7479                        $this->session = $result[0];
    7580                }
    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;
    83107                }
    84108                return true;
     
    124148                $model->add(new Statement($resourceSInstance, $predicateLocation, $sInstanceLocation));
    125149
    126                 $sInstanceFacilitator = new Literal($this->facilitator->uid);
     150                $sInstanceFacilitator = new Resource(USER . '/' . $this->facilitator->uid);
    127151                $predicateFacilitator = new Resource(FACILITATOR);
    128152                $model->add(new Statement($resourceSInstance, $predicateFacilitator, $sInstanceFacilitator));
     
    146170                }
    147171
    148                 $sInstanceSession = new Literal($this->session->uid);
     172                $sInstanceSession = new Resource(SESSION . '/' . $this->session->uid);
    149173                $predicateSession = new Resource(OF_SESSION);
    150174                $model->add(new Statement($resourceSInstance, $predicateSession, $sInstanceSession));
    151175
    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
    159196                $model->saveAs(SessionInstance::$filename, 'rdf');
    160197                return true;
     
    164201         * function get()
    165202         * @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'
    167204         */
    168205        public static function get($arguments)
     
    174211                        PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
    175212                        PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
    176                         SELECT DISTINCT ?uid, ?title, ?location, ?facilitator, ?starttime, ?endtime, ?of_session, ?has_resultset
     213                        SELECT DISTINCT ?uid, ?title, ?location, ?facilitator, ?starttime, ?endtime, ?of_session
    177214                        WHERE
    178215                        {
     
    185222                                predicates:endtime ?endtime ;
    186223                                predicates:of_session ?of_session ;
    187                                 predicates:has_resultset ?has_resultset ;
    188224                                ' . ResearchToolObject::createArguments($arguments) . '
    189225        }';
     
    196232                        {
    197233                                //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);
    199235                                $resultset = isset($result['?has_resultset']) ? $result['?has_resultset']->label : null;
    200236                                $starttime = new DateTime();
     
    206242                                        $result['?title']->label,
    207243                                        $result['?location']->label,
    208                                         $result['?facilitator']->label,
     244                                        $result['?facilitator']->uri,
    209245                                        $starttime,
    210246                                        $endtime,
    211                                         $notes,
    212                                         $result['?of_session'],
    213                                         $resultset
     247                                        $fields[0],
     248                                        $result['?of_session']->uri,
     249                                        $fields[1],
     250                                        $fields[2]
    214251                                );
    215252                        }
     
    219256       
    220257        /**
    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);
    227265                $iterator = $result->getStatementIterator();
    228266                $notes = array();
     267                $applicationinstances = array();
     268                $surveyinstances = array();
    229269                while($iterator->hasNext())
    230270                {
    231271                        $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);
    235280        }
    236281
Note: See TracChangeset for help on using the changeset viewer.