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

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

Start with new separate question db

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