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

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

updates to the database system. ao New file structure

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