[12] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | class SurveyRDFReader
|
---|
| 4 | {
|
---|
[28] | 5 | protected $model;
|
---|
[26] | 6 |
|
---|
[28] | 7 | protected $surveyUID;
|
---|
[45] | 8 | protected $filePath;
|
---|
[26] | 9 |
|
---|
| 10 | public function __construct($surveyUID)
|
---|
| 11 | {
|
---|
[12] | 12 | // Create empty MemModel
|
---|
| 13 | $factory = new ModelFactory();
|
---|
[26] | 14 | $this->model = $factory->getDefaultModel();
|
---|
| 15 |
|
---|
| 16 | $this->surveyUID = $surveyUID;
|
---|
[45] | 17 | $this->filePath = 'data/surveys/survey_'.$this->surveyUID.'.rdf';
|
---|
[12] | 18 | }
|
---|
| 19 |
|
---|
[26] | 20 | public function loadSurvey()
|
---|
[12] | 21 | {
|
---|
[45] | 22 | $this->model->load($this->filePath);
|
---|
[12] | 23 | }
|
---|
| 24 |
|
---|
[26] | 25 | public function getSurveyInfo()
|
---|
| 26 | {
|
---|
| 27 | SurveyRDFReader::loadSurvey();
|
---|
| 28 |
|
---|
| 29 | $result = array();
|
---|
| 30 | $result[] = $this->readSurveyInfo();
|
---|
| 31 | $result[] = $this->readSurveyQuestions();
|
---|
| 32 |
|
---|
| 33 | return $result;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public function readSurveyInfo()
|
---|
[12] | 37 | {
|
---|
| 38 | $querystring = '
|
---|
[26] | 39 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
[16] | 40 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
[28] | 41 | SELECT ?uid ?title ?description
|
---|
[26] | 42 | WHERE
|
---|
| 43 | {
|
---|
| 44 | _survey predicates:resource_type resources:survey ;
|
---|
[28] | 45 | predicates:uid ?uid ;
|
---|
| 46 | predicates:title ?title ;
|
---|
| 47 | predicates:description ?description
|
---|
[26] | 48 | }';
|
---|
[12] | 49 |
|
---|
| 50 | $result = $this->model->sparqlQuery($querystring);
|
---|
[26] | 51 |
|
---|
| 52 | return $result;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public function readSurveyQuestions()
|
---|
| 56 | {
|
---|
| 57 | $result = array();
|
---|
| 58 | $result[] = $this->readSurveyQuestionsTitle();
|
---|
| 59 | $result[] = $this->readSurveyQuestionsDescription();
|
---|
| 60 | $result[] = $this->readSurveyQuestionsType();
|
---|
| 61 | $result[] = $this->readSurveyQuestionsID();
|
---|
| 62 |
|
---|
| 63 | return $result;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | public function readSurveyQuestionsTitle()
|
---|
| 67 | {
|
---|
| 68 | $querystring = '
|
---|
| 69 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 70 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 71 | SELECT ?questionTitle
|
---|
| 72 | WHERE
|
---|
| 73 | {
|
---|
| 74 | _question predicates:resource_type resources:question ;
|
---|
| 75 | predicates:title ?questionTitle
|
---|
| 76 | }';
|
---|
| 77 |
|
---|
| 78 | $result = $this->model->sparqlQuery($querystring);
|
---|
[12] | 79 |
|
---|
| 80 | return $result;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[26] | 83 | public function readSurveyQuestionsDescription()
|
---|
[12] | 84 | {
|
---|
| 85 | $querystring = '
|
---|
[26] | 86 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
[16] | 87 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
[26] | 88 | SELECT ?questionDescription
|
---|
| 89 | WHERE
|
---|
| 90 | {
|
---|
| 91 | _question predicates:resource_type resources:question ;
|
---|
[40] | 92 | predicates:description ?questionDescription
|
---|
[26] | 93 | }';
|
---|
[12] | 94 |
|
---|
| 95 | $result = $this->model->sparqlQuery($querystring);
|
---|
| 96 |
|
---|
| 97 | return $result;
|
---|
| 98 | }
|
---|
[26] | 99 |
|
---|
| 100 | public function readSurveyQuestionsType()
|
---|
| 101 | {
|
---|
| 102 | $querystring = '
|
---|
| 103 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 104 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 105 | SELECT ?questionType
|
---|
| 106 | WHERE
|
---|
| 107 | {
|
---|
| 108 | _question predicates:resource_type resources:question ;
|
---|
| 109 | predicates:question_type ?questionType
|
---|
| 110 | }';
|
---|
| 111 |
|
---|
| 112 | $result = $this->model->sparqlQuery($querystring);
|
---|
| 113 |
|
---|
| 114 | return $result;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | public function readSurveyQuestionsID()
|
---|
| 118 | {
|
---|
| 119 | $querystring = '
|
---|
| 120 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 121 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 122 | SELECT ?questionID
|
---|
| 123 | WHERE
|
---|
| 124 | {
|
---|
| 125 | _question predicates:resource_type resources:question ;
|
---|
| 126 | predicates:uid ?questionID
|
---|
| 127 | }';
|
---|
| 128 |
|
---|
| 129 | $result = $this->model->sparqlQuery($querystring);
|
---|
| 130 |
|
---|
| 131 | return $result;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[44] | 134 | public function readSurveyAnswers($questionID)
|
---|
[26] | 135 | {
|
---|
| 136 | $querystring = '
|
---|
| 137 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 138 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 139 | SELECT ?answerTitle
|
---|
| 140 | WHERE
|
---|
| 141 | {
|
---|
| 142 | _question predicates:resource_type resources:question ;
|
---|
[44] | 143 | predicates:uid "' . $questionID . '" ;
|
---|
[26] | 144 | predicates:has_answer _answer .
|
---|
| 145 | _answer predicates:title ?answerTitle
|
---|
| 146 | }';
|
---|
| 147 |
|
---|
| 148 | $result = $this->model->sparqlQuery($querystring);
|
---|
| 149 |
|
---|
| 150 | return $result;
|
---|
| 151 | }
|
---|
[31] | 152 |
|
---|
| 153 | public function getSurveyTitleByID($surveyID)
|
---|
| 154 | {
|
---|
| 155 |
|
---|
| 156 | // Create empty MemModel
|
---|
| 157 | $factory = new ModelFactory();
|
---|
| 158 | $tempmodel= $factory->getDefaultModel();
|
---|
[45] | 159 | $tempmodel->load('data/surveys/survey_'.$surveyID.'.rdf');
|
---|
[31] | 160 |
|
---|
| 161 | $querystring = '
|
---|
| 162 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 163 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 164 | SELECT ?title
|
---|
| 165 | WHERE
|
---|
| 166 | {
|
---|
| 167 | _survey predicates:resource_type resources:survey ;
|
---|
| 168 | predicates:title ?title
|
---|
| 169 | }';
|
---|
| 170 |
|
---|
| 171 | $result = $tempmodel->sparqlQuery($querystring);
|
---|
| 172 |
|
---|
| 173 | return $result;
|
---|
| 174 | }
|
---|
[12] | 175 | }
|
---|
| 176 |
|
---|
| 177 | ?>
|
---|