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

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

start with dashboard database

File size: 2.9 KB
RevLine 
[12]1<?php
2
3class SurveyRDFReader
4{
[62]5    protected $model;
6
7    protected $surveyUID;
8    protected $filePath;
9
[26]10    public function __construct($surveyUID)
11    {
[12]12        // Create empty MemModel
[62]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    {
[91]22        if(file_exists($this->filePath))
23        {
24            $this->model->load($this->filePath);
25            return true;
26        }
27        else
28        {
29            return false;
30        }
[62]31    }
32
33    public function getSurveyInfo()
34    {           
[82]35        $this->loadSurvey();
[62]36
37        $result = array();
[82]38        $result['info'] = $this->readSurveyInfo();                             
39        $result['questionIDs'] = $this->readSurveyQuestionIDs();
[62]40
41        return $result;
42    }
43
44    public function readSurveyInfo()
45    {
46        $querystring = '
47            PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
48            PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
49            SELECT  ?uid ?title ?description ?creator
50            WHERE       
51            {
52                    _survey     predicates:resource_type        resources:survey ;
53                                predicates:uid                  ?uid    ;
54                                predicates:title                ?title  ;
55                                predicates:description          ?description ;
56                                predicates:creator              ?creator
57            }';
58
59        $result = $this->model->sparqlQuery($querystring);
60
61        return $result;
62    }
[82]63   
64    public function readSurveyQuestionIDs()
[62]65    {
66        $querystring = '
67            PREFIX      predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
68            PREFIX      resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
69            SELECT      ?questionID
70            WHERE
71            {   
[82]72                    _survey     predicates:resource_type        resources:survey ;
73                                predicates:has_question         ?questionID                             
[62]74            }';
75
76        $result = $this->model->sparqlQuery($querystring);
77
78        return $result;
79    }
80
81    public function getSurveyTitleByID($surveyID)
82    {
[31]83        // Create empty MemModel
[62]84        $factory = new ModelFactory();
85        $tempmodel= $factory->getDefaultModel();
86        $tempmodel->load('data/surveys/survey_'.$surveyID.'.rdf');
[12]87
[62]88        $querystring = '
89            PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
90            PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
91            SELECT  ?title
92            WHERE       
93            {
94                    _survey     predicates:resource_type        resources:survey ;
95                                predicates:title                ?title 
96            }';
97
98        $result = $tempmodel->sparqlQuery($querystring);
99
100        return $result;
101    }
102}
[12]103?>
Note: See TracBrowser for help on using the repository browser.