source: Dev/trunk/classes/SurveyRDFReader.php @ 44

Last change on this file since 44 was 44, checked in by basvannuland, 14 years ago

added login functionality. Has not been styled

File size: 4.3 KB
RevLine 
[12]1<?php
2
3class SurveyRDFReader
4{
[28]5        protected $model;
[26]6       
[28]7        protected $surveyUID;
[26]8       
9    public function __construct($surveyUID)
10    {
[12]11        // Create empty MemModel
12                $factory = new ModelFactory();
[26]13                $this->model = $factory->getDefaultModel();
14               
15                $this->surveyUID = $surveyUID;
[12]16        }
17       
[26]18        public function loadSurvey()
[12]19        {
[28]20                $this->model->load('surveys/survey_'.$this->surveyUID.'.rdf');
[12]21        }
22       
[26]23        public function getSurveyInfo()
24        {               
25                SurveyRDFReader::loadSurvey();
26       
27                $result = array();
28                $result[] = $this->readSurveyInfo();                           
29                $result[] = $this->readSurveyQuestions();
30               
31                return $result;
32        }
33       
34        public function readSurveyInfo()
[12]35        {
36                $querystring = '
[26]37                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
[16]38                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
[28]39                        SELECT  ?uid ?title ?description
[26]40                        WHERE   
41                        {
42                                _survey         predicates:resource_type        resources:survey ;
[28]43                                                        predicates:uid                          ?uid    ;
44                                                        predicates:title                        ?title  ;
45                                                        predicates:description          ?description
[26]46                        }';
[12]47                       
48                $result = $this->model->sparqlQuery($querystring);
[26]49                               
50                return $result;
51        }
52       
53        public function readSurveyQuestions()
54        {
55                $result = array();
56                $result[] = $this->readSurveyQuestionsTitle();                         
57                $result[] = $this->readSurveyQuestionsDescription();
58                $result[] = $this->readSurveyQuestionsType();
59                $result[] = $this->readSurveyQuestionsID();             
60                               
61                return $result;
62        }
63       
64        public function readSurveyQuestionsTitle()
65        {
66                $querystring = '
67                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
68                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
69                        SELECT  ?questionTitle
70                        WHERE
71                        {       
72                                _question       predicates:resource_type        resources:question ;
73                                                        predicates:title                        ?questionTitle         
74                        }';
75                       
76                $result = $this->model->sparqlQuery($querystring);
[12]77               
78                return $result;
79        }
80       
[26]81        public function readSurveyQuestionsDescription()
[12]82        {
83                $querystring = '
[26]84                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
[16]85                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
[26]86                        SELECT  ?questionDescription
87                        WHERE
88                        {       
89                                _question       predicates:resource_type        resources:question ;
[40]90                                                        predicates:description          ?questionDescription           
[26]91                        }';
[12]92                       
93                $result = $this->model->sparqlQuery($querystring);
94               
95                return $result;
96        }
[26]97       
98        public function readSurveyQuestionsType()
99        {
100                $querystring = '
101                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
102                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
103                        SELECT  ?questionType
104                        WHERE
105                        {       
106                                _question       predicates:resource_type        resources:question ;
107                                                        predicates:question_type        ?questionType                           
108                        }';
109                       
110                $result = $this->model->sparqlQuery($querystring);
111               
112                return $result;
113        }
114       
115        public function readSurveyQuestionsID()
116        {
117                $querystring = '
118                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
119                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
120                        SELECT  ?questionID
121                        WHERE
122                        {       
123                                _question       predicates:resource_type        resources:question ;
124                                                        predicates:uid                          ?questionID                             
125                        }';
126                       
127                $result = $this->model->sparqlQuery($querystring);
128               
129                return $result;
130        }
131       
[44]132        public function readSurveyAnswers($questionID)
[26]133        {
134                $querystring = '
135                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
136                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
137                        SELECT  ?answerTitle
138                        WHERE
139                        {
140                                _question               predicates:resource_type        resources:question ;
[44]141                                                                predicates:uid                          "' . $questionID . '"  ;
[26]142                                                                predicates:has_answer           _answer .
143                                _answer                 predicates:title                        ?answerTitle                                                           
144                        }';
145                       
146                $result = $this->model->sparqlQuery($querystring);
147               
148                return $result;
149        }
[31]150       
151        public function getSurveyTitleByID($surveyID)
152        {
153               
154        // Create empty MemModel
155                $factory = new ModelFactory();
156                $tempmodel= $factory->getDefaultModel();
[40]157                $tempmodel->load('surveys/survey_'.$surveyID.'.rdf');
[31]158               
159                $querystring = '
160                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
161                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
162                        SELECT  ?title
163                        WHERE   
164                        {
165                                _survey         predicates:resource_type        resources:survey ;
166                                                        predicates:title                        ?title 
167                        }';
168                       
169                $result = $tempmodel->sparqlQuery($querystring);
170                               
171                return $result;
172        }
[12]173}
174
175?>
Note: See TracBrowser for help on using the repository browser.