[12] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | class 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 | {
|
---|
| 22 | $this->model->load($this->filePath);
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 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()
|
---|
| 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 readSurveyQuestions()
|
---|
| 57 | {
|
---|
| 58 | $result = array();
|
---|
| 59 | $result[] = $this->readSurveyQuestionsTitle();
|
---|
| 60 | $result[] = $this->readSurveyQuestionsDescription();
|
---|
| 61 | $result[] = $this->readSurveyQuestionsType();
|
---|
| 62 | $result[] = $this->readSurveyQuestionsID();
|
---|
| 63 |
|
---|
| 64 | return $result;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | public function readSurveyQuestionsTitle()
|
---|
| 68 | {
|
---|
| 69 | $querystring = '
|
---|
| 70 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 71 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 72 | SELECT ?questionTitle
|
---|
| 73 | WHERE
|
---|
| 74 | {
|
---|
| 75 | _question predicates:resource_type resources:question ;
|
---|
| 76 | predicates:title ?questionTitle
|
---|
| 77 | }';
|
---|
| 78 |
|
---|
| 79 | $result = $this->model->sparqlQuery($querystring);
|
---|
| 80 |
|
---|
| 81 | return $result;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | public function readSurveyQuestionsDescription()
|
---|
| 85 | {
|
---|
| 86 | $querystring = '
|
---|
| 87 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 88 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 89 | SELECT ?questionDescription
|
---|
| 90 | WHERE
|
---|
| 91 | {
|
---|
| 92 | _question predicates:resource_type resources:question ;
|
---|
| 93 | predicates:description ?questionDescription
|
---|
| 94 | }';
|
---|
| 95 |
|
---|
| 96 | $result = $this->model->sparqlQuery($querystring);
|
---|
| 97 |
|
---|
| 98 | return $result;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | public function readSurveyQuestionsType()
|
---|
| 102 | {
|
---|
| 103 | $querystring = '
|
---|
| 104 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 105 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 106 | SELECT ?questionType
|
---|
| 107 | WHERE
|
---|
| 108 | {
|
---|
| 109 | _question predicates:resource_type resources:question ;
|
---|
| 110 | predicates:question_type ?questionType
|
---|
| 111 | }';
|
---|
| 112 |
|
---|
| 113 | $result = $this->model->sparqlQuery($querystring);
|
---|
| 114 |
|
---|
| 115 | return $result;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | public function readSurveyQuestionsID()
|
---|
| 119 | {
|
---|
| 120 | $querystring = '
|
---|
| 121 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 122 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 123 | SELECT ?questionID
|
---|
| 124 | WHERE
|
---|
| 125 | {
|
---|
| 126 | _question predicates:resource_type resources:question ;
|
---|
| 127 | predicates:uid ?questionID
|
---|
| 128 | }';
|
---|
| 129 |
|
---|
| 130 | $result = $this->model->sparqlQuery($querystring);
|
---|
| 131 |
|
---|
| 132 | return $result;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | public function readSurveyAnswers($questionID)
|
---|
| 136 | {
|
---|
| 137 | $querystring = '
|
---|
| 138 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 139 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 140 | SELECT ?answerDescription
|
---|
| 141 | WHERE
|
---|
| 142 | {
|
---|
| 143 | _question predicates:resource_type resources:question ;
|
---|
| 144 | predicates:uid "' . $questionID . '" ;
|
---|
| 145 | predicates:has_answer _answer .
|
---|
| 146 | _answer predicates:description ?answerDescription
|
---|
| 147 | }';
|
---|
| 148 |
|
---|
| 149 | $result = $this->model->sparqlQuery($querystring);
|
---|
| 150 |
|
---|
| 151 | return $result;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | public function getSurveyTitleByID($surveyID)
|
---|
| 155 | {
|
---|
[31] | 156 | // Create empty MemModel
|
---|
[62] | 157 | $factory = new ModelFactory();
|
---|
| 158 | $tempmodel= $factory->getDefaultModel();
|
---|
| 159 | $tempmodel->load('data/surveys/survey_'.$surveyID.'.rdf');
|
---|
[12] | 160 |
|
---|
[62] | 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 | }
|
---|
| 175 | }
|
---|
[12] | 176 | ?>
|
---|