source: Dev/trunk/classes/SurveyAnswerRDFReader.php @ 58

Last change on this file since 58 was 51, checked in by fpvanagthoven, 14 years ago

Start on survey page. There's something weird in surveycreationtool though. Should fix that.

File size: 2.9 KB
Line 
1<?php
2
3class SurveyAnswerRDFReader extends SurveyRDFReader
4{       
5        protected $tempModel;
6        protected $answerPath;
7       
8    public function __construct($surveyUID)
9    {
10        parent::__construct($surveyUID);
11               
12                // Create empty MemModel
13                $factory = new ModelFactory();
14                $this->tempModel = $factory->getDefaultModel();
15                $this->answerPath = 'data/surveys/answers_'.$this->surveyUID;
16        }
17       
18        public function loadSurvey()
19        {
20                parent::loadSurvey();           
21               
22        }
23       
24        public function getAnswerByQuestion($questionID)
25        {
26                $this->tempModel->loadModel($this->model);
27               
28                $answers = array();
29               
30                if($handle = opendir($this->answerPath))
31                {
32                        while (false !== ($file = readdir($handle))) {
33                                if(strstr($file, 'answer_'))
34                                        $answers[] = substr($file,0,strlen($file)-4);
35                        }
36                }
37               
38                foreach($answers as $answer)
39                {
40                        $this->tempModel->load($this->answerPath.'/'.$answer);
41                }
42               
43                $this->tempModel->visualize();
44       
45                $querystring = '
46                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
47                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
48                        SELECT  ?answered
49                        WHERE   
50                        {
51                                _question       predicates:resource_type        resources:question ;
52                                                        predicates:uid                          "'.$questionID.'"       ;
53                                                        predicates:answered             ?answered       
54                        }';
55                       
56                $result = $this->tempModel->sparqlQuery($querystring);
57               
58                $this->tempModel->close();             
59
60                $this->tempModel->visualize();
61                               
62                return $result;
63        }
64       
65        public function getAnswerByRespondent($respondentID)
66        {
67                $this->tempModel->loadModel($this->model);
68               
69                $this->tempModel->load($this->answerPath . '/$answer_' . $respondentID);
70               
71                $this->tempModel->visualize();
72       
73                $querystring = '
74                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
75                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
76                        SELECT  ?answered
77                        WHERE   
78                        {
79                                _question       predicates:resource_type        resources:question ;
80                                                        predicates:answered             ?answered       
81                        }';
82                       
83                $result = $this->tempModel->sparqlQuery($querystring);
84               
85                $this->tempModel->close();             
86
87                $this->tempModel->visualize();
88                               
89                return $result;
90        }
91       
92        public function getAnswerByRespondentAndQuestion($respondentID,$questionID)
93        {
94                $this->tempModel->loadModel($this->model);
95                               
96                $this->tempModel->load($this->answerPath . '/$answer_' . $respondentID);
97               
98                $this->tempModel->visualize();
99       
100                $querystring = '
101                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
102                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
103                        SELECT  ?answered
104                        WHERE   
105                        {
106                                _question       predicates:resource_type        resources:question ;
107                                                        predicates:uid                          "'.$questionID.'"       ;
108                                                        predicates:answered             ?answered       
109                        }';
110                       
111                $result = $this->tempModel->sparqlQuery($querystring);
112               
113                $this->tempModel->close();             
114
115                $this->tempModel->visualize();
116                               
117                return $result;
118        }
119}
120
121?>
Note: See TracBrowser for help on using the repository browser.