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