Changeset 298


Ignore:
Timestamp:
03/01/12 15:02:59 (13 years ago)
Author:
jkraaijeveld
Message:

[Server] Made the models compliant with the Visio design in terms of ApplicationInstance?, SurveyInstance?, SessionInstance? and all of their fields.
[Server] Now stores references as RDF Resources for all models.
[Server] Changed some possible get() arguments to be more consistent.

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  
    5050                if(is_string($this->question))
    5151                {
    52                         $result = Question::get(array("uid" => $this->question));
     52                        $ans = ResearchToolObject::stripUri($this->question);
     53                        $result = Question::get(array("uid" => $ans["uid"]));
    5354                        if(!isset($result[0]))
    5455                                return false;
     
    7172                        PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
    7273                        PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
    73                         SELECT DISTINCT ?uid, ?question_code
     74                        SELECT DISTINCT ?uid, ?to_question
    7475                        WHERE
    7576                        {
     
    7778
    7879                                predicates:uid ?uid ;
    79                                 predicates:question_code ?question_code ;
     80                                predicates:to_question ?to_question ;
    8081                                ' . ResearchToolObject::createArguments($arguments) . '
    8182                        }';
     
    8384                //Query the model
    8485                $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.
    8687                $answers = array();
    8788                if(!empty($results))
     
    8990                        foreach($results as $result)
    9091                        {
    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));
    9293                        }
    9394                }
     
    142143                $model->add(new Statement($resourceAnswer, $predicateId, $answerId));
    143144
    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);
    146147                $model->add(new Statement($resourceAnswer, $predicateQId, $questionId));
    147148
  • Dev/branches/jos-branch/server/classes/models/AnswerSet.php

    r285 r298  
    4646                if(is_string($this->survey))
    4747                {
    48                         $result = Survey::get(array("uid" => $this->survey));
     48                        $surv = ResearchToolObject::stripUri($this->survey);
     49                        $result = Survey::get(array("uid" => $surv["uid"]));
    4950                        if(!isset($result[0]))
    5051                                return false;
     
    5354                if(is_string($this->respondent))
    5455                {
    55                         $result = Respondent::get(array("uid" => $this->respondent));
     56                        $resp = ResearchToolObject::stripUri($this->respondent);
     57                        $result = Respondent::get(array("uid" => $resp["uid"]));
    5658                        if(!isset($result[0]))
    5759                                return false;
     
    6365                        foreach($this->answers as $answer)
    6466                        {
    65                                 $result = Answer::get(array("uid" => $answer));
     67                                $answ = ResearchToolObject::stripUri($answer);
     68                                $result = Answer::get(array("uid" => $answ["uid"]));
    6669                                if(!isset($result[0]))
    6770                                        return false;
     
    9194                $model = ResearchToolObject::load(AnswerSet::$filename);
    9295
    93 
    9496                $resourceAnswerSet = new Resource(ANSWERSET . '/' . $this->uid);
    9597                //Remove the old value stored with the given id
     
    105107                $model->add(new Statement($resourceAnswerSet, $predicateId, $answerSetId));
    106108
    107                 $surveyId = new Literal($this->survey->uid);
     109                $surveyId = new Resource(SURVEY . '/' . $this->survey->uid);
    108110                $predicateSurvey = new Resource(FOR_SURVEY);
    109111                $model->add(new Statement($resourceAnswerSet, $predicateSurvey, $surveyId));
    110112
    111                 $respondentId = new Literal($this->respondent->uid);
     113                $respondentId = new Resource(RESPONDENT . '/' . $this->respondent->uid);
    112114                $predicateRespondent = new Resource(BY_RESPONDENT);
    113115                $model->add(new Statement($resourceAnswerSet, $predicateRespondent, $respondentId));
     
    121123                        foreach($this->answers as $answer)
    122124                        {
    123                                 $answerId = new Literal($answer->uid);
     125                                $answerId = new Resource(ANSWER . '/' . $answer->uid);
    124126                                $predicateAnswer = new Resource(GIVEN_ANSWER);
    125127                                $model->add(new Statement($resourceAnswerSet, $predicateAnswer, $answerId));
     
    160162                        foreach($results as $result)
    161163                        {
    162                                 $survey = $result['?for_survey']->label;
    163                                 $respondent = $result['?by_respondent']->label;
     164                                $survey = $result['?for_survey']->uri;
     165                                $respondent = $result['?by_respondent']->uri;
    164166                                $datetime = new DateTime();
    165167                                $datetime->setTimestamp(intval($result['?datetime']->label));
  • Dev/branches/jos-branch/server/classes/models/ApplicationInstance.php

    r287 r298  
    128128        {
    129129                $model = ResearchToolObject::load(ApplicationInstance::$filename);
    130                 $model->writeAsHTMLTable();
    131 
    132130                //Build the query string
    133131                $querystring = '
     
    162160                }
    163161                return $aInstances;
    164 
    165 
    166162        }
    167163
  • Dev/branches/jos-branch/server/classes/models/ResearchToolObject.php

    r287 r298  
    6161                        {
    6262                                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;
    6464                                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;
    6868                                case "title" : $addition = "predicates:title '" . $arguments[$key] . "'\n"; break;
    6969                                case "description" : $addition = "predicates:description '" . $arguments[$key] . "'\n"; break;
     
    7575                                case "email" : $addition = "predicates:email '" . $arguments[$key] . "'\n"; break;
    7676                                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;
    7878                                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;
    8383                                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;
    8585                                case "starttime" : $addition = "predicates:starttime '" . $arguments[$key] . "'\n"; break;
    8686                                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;
    8888                                case "resultset" : $addition = "predicates:has_resultset '" . $arguments[$key] . "'\n"; break;
    8989                                case "of_application" : $addition = "predicates:of_application <" . APPLICATION . '/' .  $arguments[$key] . ">\n"; break;
    9090                                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;
    9194                        }
    9295                        $argumentString = $argumentString . $addition;
  • Dev/branches/jos-branch/server/classes/models/Session.php

    r285 r298  
    4848                if(is_string($this->creator))
    4949                {
    50                         $result = User::get(array("uid" => $this->creator));
     50                        $crea = ResearchToolObject::stripUri($this->creator);
     51                        $result = User::get(array("uid" => $crea["uid"]));
    5152                        if(!isset($result[0]))
    5253                                return false;
     
    5455                }
    5556                if(!empty($this->pipeline) && is_string($this->pipeline[0]))
    56                 {
     57                {       
    5758                        $newPipeline = array();
    5859                        foreach($this->pipeline as $element)
    5960                        {
    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                                }
    6571                                if(!isset($result[0]))
    6672                                        return false;
     
    107113                $model->add(new Statement($resourceSession, $predicateTitle, $sessionTitle));
    108114
    109                 $sessionCreator = new Literal($this->creator->uid);
     115                $sessionCreator = new Resource(USER . '/' . $this->creator->uid);
    110116                $predicateCreator = new Resource(CREATOR);
    111117                $model->add(new Statement($resourceSession, $predicateCreator, $sessionCreator));
     
    121127                        foreach($this->pipeline as $element)
    122128                        {
    123                                 $sessionObject = new Literal($element->uid);
     129                                $sessionObject = null;
    124130                                $predicateObject = null;
    125131                                if(get_class($element) == "Application")
     132                                {
     133                                        $sessionObject = new Resource(APPLICATION . '/' . $element->uid);
    126134                                        $predicateObject = new Resource(HAS_APPLICATION);
     135                                }
    127136                                else if(get_class($element) == "Survey")
     137                                {
     138                                        $sessionObject = new Resource(SURVEY . '/' . $element->uid);
    128139                                        $predicateObject = new Resource(HAS_SURVEY);
     140                                }
    129141                                if(isset($predicateObject))
    130142                                        $model->add(new Statement($resourceSession, $predicateObject, $sessionObject));
     
    132144                }
    133145
    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                
    144146                return $model->saveAs(Session::$filename, 'rdf');
    145147        }
     
    178180                                //Create a session object out of every result, get all required fields as well.
    179181                                $pipeline = Session::getPipeline($model, $result['?uid']->label);
    180                                 $creator = $result['?creator']->label;
     182                                $creator = $result['?creator']->uri;
    181183                                $creationdate = new DateTime();
    182184                                $creationdate->setTimestamp(intval($result['?creationdate']->label));
  • Dev/branches/jos-branch/server/classes/models/SessionInstance.php

    r285 r298  
    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
  • Dev/branches/jos-branch/server/classes/models/Survey.php

    r285 r298  
    3232        public function evaluate()
    3333        {
     34
    3435                if(is_string($this->creator))
    3536                {
    36                         $result = User::get(array("uid" => $this->creator));   
     37                        $crea = ResearchToolObject::stripUri($this->creator);
     38                        $result = User::get(array("uid" => $crea["uid"]));     
    3739                        if(!isset($result[0]))
    3840                                return false;
     
    4547                        foreach($this->questions as $question)
    4648                        {
    47                                 $result = Question::get(array("code" => $question));
     49                                $ques = ResearchToolObject::stripUri($question);
     50                                $result = Question::get(array("uid" => $ques["uid"]));
    4851                                if(!isset($result[0]))
    4952                                        return false;
     
    9396       
    9497                $predicateCreator = new Resource(CREATOR);
    95                 $surveyCreator = new Literal($this->creator->uid);
     98                $surveyCreator = new Resource(USER . '/' . $this->creator->uid);
    9699                $model->add(new Statement($resourceSurvey, $predicateCreator, $surveyCreator));
    97100
     
    100103            foreach($this->questions as $question)
    101104            {
    102                 $questionUid = new Literal($question->uid);
     105                                $questionUid = new Resource(QUESTION . '/' . $question->uid);
    103106                $predicateQuid = new Resource(HAS_QUESTION);
    104107                $model->add(new Statement($resourceSurvey,$predicateQuid,$questionUid));
     
    145148            {
    146149                                $questions = Survey::getQuestions($model, $result['?uid']->label);
    147                                 $creator = $result['?creator']->label;
     150                                $creator = $result['?creator']->uri;
    148151                $surveys[] = new Survey($result['?uid']->label, $result['?title']->label, $result['?description']->label, $creator, $questions);
    149152            }
  • Dev/branches/jos-branch/server/classes/models/SurveyInstance.php

    r286 r298  
    2626     * @param type $answersets: A list of answersets.
    2727     */
    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)
    2929    {
    3030        if(!isset($uid))
     
    3737        $this->starttime = $starttime;
    3838        $this->endtime = $endtime;
    39         $this->open = $open;
     39                $this->open = $open;
    4040        $this->presetanswers = $presetanswers;
    4141        $this->answersets = $answersets;
     
    5151        if(is_string($this->survey))
    5252        {
    53             $result = Survey::get(array("uid" => $this->survey));
     53                        $surv = ResearchToolObject::stripUri($this->survey);
     54            $result = Survey::get(array("uid" => $surv["uid"]));
    5455            if(!isset($result[0]))
    5556            {
     
    6566                foreach($this->presetanswers as $answer)
    6667                {
    67                         $result = Answer::get(array("uid" => $answer));
     68                                                $ans = ResearchToolObject::stripUri($answer);
     69                        $result = Answer::get(array("uid" => $ans["uid"]));
    6870                        if(!isset($result[0]))
    6971                                return false;
     
    7981                foreach($this->answersets as $answerSet)
    8082                {
    81                         $result = AnswerSet::get(array("uid" => $answerSet));
     83                                                $aset = ResearchToolObject::stripUri($answerSet);
     84                        $result = AnswerSet::get(array("uid" => $aset["uid"]));
    8285                        if(!isset($result[0]))
    8386                        {
     
    132135        $predicateEndTime = new Resource(ENDTIME);
    133136        $model->add(new Statement($resourceSI, $predicateEndTime, $SIEndTime));
    134 
    135         $SIOpen = new Literal($this->open);
     137        $SIOpen = new Literal((bool) $this->open);
    136138        $predicateOpen = new Resource(OPEN);
    137139        $model->add(new Statement($resourceSI, $predicateOpen, $SIOpen));
     
    141143                foreach($this->presetanswers as $answer)
    142144                {
    143                         $answerId = new Literal($answer->uid);
     145                        $answerId = new Resource(ANSWER . '/' . $answer->uid);
    144146                        $predicateAnswer = new Resource(PRESET_ANSWER);
    145147                        $model->add(new Statement($resourceSI, $predicateAnswer, $answerId));
     
    151153                foreach($this->answersets as $answer)
    152154                {
    153                         $answerSetId = new Literal($answer->uid);
     155                        $answerSetId = new Resource(ANSWERSET . '/' . $answer->uid);
    154156                        $predicateAnswerSet = new Resource(HAS_ANSWERSET);
    155157                        $model->add(new Statement($resourceSI, $predicateAnswerSet, $answerSetId));
     
    163165        * Gets the array of SurveyInstance objects belonging tothe arguments supplied.
    164166        * @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'
    166168        */
    167169        public static function get($arguments)
     
    195197                                $endTime = new DateTime();
    196198                                $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]);
    203202                        }
    204203                }
     
    207206
    208207        /**
    209          * function getPresetAnswers()
     208         * function getFields()
    210209         * @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.
    212212         */
    213         private static function getPresetAnswers($model, $uid)
     213        private static function getFields($model, $uid)
    214214        {
    215                 $result = $model->findRegex("[(".$uid.")]", "[(preset_answer)]", null);
     215                $result = $model->findRegex("[(".$uid.")]", "[(preset_answer)|(has_answerset)]", null);
    216216                $iterator = $result->getStatementIterator();
    217217                $answers = array();
     218                $sets = array();
    218219                while($iterator->hasNext())
    219220                {
    220221                        $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();
    222226                }
    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);
    242228        }
    243229
  • Dev/branches/jos-branch/server/rdfConstants.php

    r285 r298  
    6969define('OF_SURVEY', SURVEYTOOL_PREDICATES_NAMESPACE . 'of_survey');
    7070define('PRESET_ANSWER', SURVEYTOOL_PREDICATES_NAMESPACE . 'preset_answer');
     71define('TO_QUESTION', SURVEYTOOL_PREDICATES_NAMESPACE . 'to_question');
     72define('HAS_APPLICATIONINSTANCE', SURVEYTOOL_PREDICATES_NAMESPACE . 'has_applicationinstance');
     73define('HAS_SURVEYINSTANCE', SURVEYTOOL_PREDICATES_NAMESPACE . 'has_surveyinstance');
    7174?>
Note: See TracChangeset for help on using the changeset viewer.