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

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

made some changes to way rdf database is constructed.
Made an interface class to write to db and read from db.
interface returns array with survey information in the same way it gets it from the surveyCreationTool.
TODO, override existing survey when it is modified.

File size: 3.6 KB
Line 
1<?php
2
3class SurveyRDFReader
4{
5        var $model;
6       
7        var $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/'.$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  ?title ?description
40                        WHERE   
41                        {
42                                _survey         predicates:resource_type        resources:survey ;
43                                                        predicates:title                        ?title ;
44                                                        predicates:description          ?description
45                        }';
46                       
47                $result = $this->model->sparqlQuery($querystring);
48                               
49                return $result;
50        }
51       
52        public function readSurveyQuestions()
53        {
54                $result = array();
55                $result[] = $this->readSurveyQuestionsTitle();                         
56                $result[] = $this->readSurveyQuestionsDescription();
57                $result[] = $this->readSurveyQuestionsType();
58                $result[] = $this->readSurveyQuestionsID();             
59                               
60                return $result;
61        }
62       
63        public function readSurveyQuestionsTitle()
64        {
65                $querystring = '
66                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
67                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
68                        SELECT  ?questionTitle
69                        WHERE
70                        {       
71                                _question       predicates:resource_type        resources:question ;
72                                                        predicates:title                        ?questionTitle         
73                        }';
74                       
75                $result = $this->model->sparqlQuery($querystring);
76               
77                return $result;
78        }
79       
80        public function readSurveyQuestionsDescription()
81        {
82                $querystring = '
83                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
84                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
85                        SELECT  ?questionDescription
86                        WHERE
87                        {       
88                                _question       predicates:resource_type        resources:question ;
89                                                        predicates:description  ?questionDescription           
90                        }';
91                       
92                $result = $this->model->sparqlQuery($querystring);
93               
94                return $result;
95        }
96       
97        public function readSurveyQuestionsType()
98        {
99                $querystring = '
100                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
101                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
102                        SELECT  ?questionType
103                        WHERE
104                        {       
105                                _question       predicates:resource_type        resources:question ;
106                                                        predicates:question_type        ?questionType                           
107                        }';
108                       
109                $result = $this->model->sparqlQuery($querystring);
110               
111                return $result;
112        }
113       
114        public function readSurveyQuestionsID()
115        {
116                $querystring = '
117                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
118                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
119                        SELECT  ?questionID
120                        WHERE
121                        {       
122                                _question       predicates:resource_type        resources:question ;
123                                                        predicates:uid                          ?questionID                             
124                        }';
125                       
126                $result = $this->model->sparqlQuery($querystring);
127               
128                return $result;
129        }
130       
131        public function readSurveyAnswers($qID)
132        {
133                $querystring = '
134                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
135                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
136                        SELECT  ?answerTitle
137                        WHERE
138                        {
139                                _question               predicates:resource_type        resources:question ;
140                                                                predicates:uid                          "' . $qID . '"  ;
141                                                                predicates:has_answer           _answer .
142                                _answer                 predicates:title                        ?answerTitle                                                           
143                        }';
144                       
145                $result = $this->model->sparqlQuery($querystring);
146               
147                return $result;
148        }
149}
150
151?>
Note: See TracBrowser for help on using the repository browser.