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

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

new file structure. surveys/users/application DBs in data folder

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