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

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

new classes for survey answers writing and reading
added idtags as part of info

File size: 4.3 KB
Line 
1<?php
2
3class SurveyRDFReader
4{
5        protected $model;
6       
7        protected $surveyUID;
8       
9    public function __construct($surveyUID)
10    {
11        // Create empty MemModel
12                $factory = new ModelFactory();
13                $this->model = $factory->getDefaultModel();
14               
15                $this->surveyUID = $surveyUID;
16        }
17       
18        public function loadSurvey()
19        {
20                $this->model->load('surveys/survey_'.$this->surveyUID.'.rdf');
21        }
22       
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()
35        {
36                $querystring = '
37                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
38                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
39                        SELECT  ?uid ?title ?description
40                        WHERE   
41                        {
42                                _survey         predicates:resource_type        resources:survey ;
43                                                        predicates:uid                          ?uid    ;
44                                                        predicates:title                        ?title  ;
45                                                        predicates:description          ?description
46                        }';
47                       
48                $result = $this->model->sparqlQuery($querystring);
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);
77               
78                return $result;
79        }
80       
81        public function readSurveyQuestionsDescription()
82        {
83                $querystring = '
84                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
85                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
86                        SELECT  ?questionDescription
87                        WHERE
88                        {       
89                                _question       predicates:resource_type        resources:question ;
90                                                        predicates:description  ?questionDescription           
91                        }';
92                       
93                $result = $this->model->sparqlQuery($querystring);
94               
95                return $result;
96        }
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       
132        public function readSurveyAnswers($qID)
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 ;
141                                                                predicates:uid                          "' . $qID . '"  ;
142                                                                predicates:has_answer           _answer .
143                                _answer                 predicates:title                        ?answerTitle                                                           
144                        }';
145                       
146                $result = $this->model->sparqlQuery($querystring);
147               
148                return $result;
149        }
150       
151        public function getSurveyTitleByID($surveyID)
152        {
153                echo $surveyID.'<br/>';
154               
155        // Create empty MemModel
156                $factory = new ModelFactory();
157                $tempmodel= $factory->getDefaultModel();
158                $tempmodel->load('surveys/'.$surveyID.'.rdf');
159               
160                $querystring = '
161                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
162                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
163                        SELECT  ?title
164                        WHERE   
165                        {
166                                _survey         predicates:resource_type        resources:survey ;
167                                                        predicates:title                        ?title 
168                        }';
169                       
170                $result = $tempmodel->sparqlQuery($querystring);
171                               
172                return $result;
173        }
174}
175
176?>
Note: See TracBrowser for help on using the repository browser.