[31] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | class SurveyAnswerRDFReader extends SurveyRDFReader
|
---|
| 4 | {
|
---|
[40] | 5 | protected $tempModel;
|
---|
| 6 |
|
---|
[31] | 7 | public function __construct($surveyUID)
|
---|
| 8 | {
|
---|
| 9 | parent::__construct($surveyUID);
|
---|
[40] | 10 |
|
---|
| 11 | / Create empty MemModel
|
---|
| 12 | $factory = new ModelFactory();
|
---|
| 13 | $this->tempModel = $factory->getDefaultModel();
|
---|
[31] | 14 | }
|
---|
| 15 |
|
---|
| 16 | public function loadSurvey()
|
---|
| 17 | {
|
---|
[40] | 18 | parent::loadSurvey();
|
---|
| 19 |
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | public function getAnswerByQuestion($questionID)
|
---|
| 23 | {
|
---|
| 24 | $this->tempModel->loadModel($this->model);
|
---|
| 25 |
|
---|
[31] | 26 | $answerPath = 'surveys/answers_'.$this->surveyUID;
|
---|
| 27 | $answers = array();
|
---|
| 28 |
|
---|
| 29 | if($handle = opendir('$answerPath'))
|
---|
| 30 | {
|
---|
| 31 | while (false !== ($file = readdir($handle))) {
|
---|
| 32 | if(strstr($file, 'answer_'))
|
---|
| 33 | $answers[] = substr($file,0,strlen($file)-4);
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | foreach($answers as $answer)
|
---|
| 38 | {
|
---|
[40] | 39 | $this->tempModel->load($answerPath.'/'.$answer);
|
---|
[31] | 40 | }
|
---|
[40] | 41 |
|
---|
| 42 | $this->tempModel->visualize();
|
---|
| 43 |
|
---|
| 44 | $querystring = '
|
---|
| 45 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 46 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 47 | SELECT ?answered
|
---|
| 48 | WHERE
|
---|
| 49 | {
|
---|
| 50 | _question predicates:resource_type resources:question ;
|
---|
| 51 | predicates:uid "'.$questionID.'" ;
|
---|
| 52 | predicates:answered ?answered
|
---|
| 53 | }';
|
---|
| 54 |
|
---|
| 55 | $result = $this->tempModel->sparqlQuery($querystring);
|
---|
| 56 |
|
---|
| 57 | $this->tempModel->close();
|
---|
| 58 |
|
---|
| 59 | $this->tempModel->visualize();
|
---|
| 60 |
|
---|
| 61 | return $result;
|
---|
[31] | 62 | }
|
---|
| 63 |
|
---|
[40] | 64 | public function getAnswerByRespondent($respondentID)
|
---|
[31] | 65 | {
|
---|
[40] | 66 | $this->tempModel->loadModel($this->model);
|
---|
| 67 |
|
---|
| 68 | $answerPath = 'surveys/answers_'.$this->surveyUID;
|
---|
| 69 |
|
---|
| 70 | $this->tempModel->load($answerPath . '/$answer_' . $respondentID);
|
---|
| 71 |
|
---|
| 72 | $this->tempModel->visualize();
|
---|
| 73 |
|
---|
| 74 | $querystring = '
|
---|
[31] | 75 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 76 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 77 | SELECT ?answered
|
---|
| 78 | WHERE
|
---|
| 79 | {
|
---|
| 80 | _question predicates:resource_type resources:question ;
|
---|
[40] | 81 | predicates:answered ?answered
|
---|
| 82 | }';
|
---|
| 83 |
|
---|
| 84 | $result = $this->tempModel->sparqlQuery($querystring);
|
---|
| 85 |
|
---|
| 86 | $this->tempModel->close();
|
---|
| 87 |
|
---|
| 88 | $this->tempModel->visualize();
|
---|
| 89 |
|
---|
| 90 | return $result;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | public function getAnswerByRespondentAndQuestion($respondentID,$questionID)
|
---|
| 94 | {
|
---|
| 95 | $this->tempModel->loadModel($this->model);
|
---|
| 96 |
|
---|
| 97 | $answerPath = 'surveys/answers_'.$this->surveyUID;
|
---|
| 98 |
|
---|
| 99 | $this->tempModel->load($answerPath . '/$answer_' . $respondentID);
|
---|
| 100 |
|
---|
| 101 | $this->tempModel->visualize();
|
---|
| 102 |
|
---|
| 103 | $querystring = '
|
---|
| 104 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
| 105 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
| 106 | SELECT ?answered
|
---|
| 107 | WHERE
|
---|
| 108 | {
|
---|
| 109 | _question predicates:resource_type resources:question ;
|
---|
[31] | 110 | predicates:uid "'.$questionID.'" ;
|
---|
| 111 | predicates:answered ?answered
|
---|
| 112 | }';
|
---|
| 113 |
|
---|
[40] | 114 | $result = $this->tempModel->sparqlQuery($querystring);
|
---|
| 115 |
|
---|
| 116 | $this->tempModel->close();
|
---|
| 117 |
|
---|
| 118 | $this->tempModel->visualize();
|
---|
[31] | 119 |
|
---|
| 120 | return $result;
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | ?> |
---|