[137] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | class 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 | if(file_exists($this->filePath))
|
---|
| 23 | {
|
---|
| 24 | $this->model->load($this->filePath);
|
---|
| 25 | return true;
|
---|
| 26 | }
|
---|
| 27 | else
|
---|
| 28 | {
|
---|
| 29 | return false;
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | public function getSurveyInfo()
|
---|
| 34 | {
|
---|
| 35 | $this->loadSurvey();
|
---|
| 36 |
|
---|
| 37 | $result = array();
|
---|
| 38 | $result['info'] = $this->readSurveyInfo();
|
---|
| 39 | $result['questionIDs'] = $this->readSurveyQuestionIDs();
|
---|
| 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 | }
|
---|
| 63 |
|
---|
| 64 | public function readSurveyQuestionIDs()
|
---|
| 65 | {
|
---|
| 66 | $querystring = '
|
---|
| 67 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 68 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 69 | SELECT ?questionID
|
---|
| 70 | WHERE
|
---|
| 71 | {
|
---|
| 72 | _survey predicates:resource_type resources:survey ;
|
---|
| 73 | predicates:has_question ?questionID
|
---|
| 74 | }';
|
---|
| 75 |
|
---|
| 76 | $result = $this->model->sparqlQuery($querystring);
|
---|
| 77 |
|
---|
| 78 | return $result;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public function getSurveyTitleByID($surveyID)
|
---|
| 82 | {
|
---|
| 83 | // Create empty MemModel
|
---|
| 84 | $factory = new ModelFactory();
|
---|
| 85 | $tempmodel= $factory->getDefaultModel();
|
---|
| 86 | $tempmodel->load('data/surveys/survey_'.$surveyID.'.rdf');
|
---|
| 87 |
|
---|
| 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 | }
|
---|
| 103 | ?>
|
---|