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

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

start with answer saving

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