[12] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | class SurveyRDFWriter
|
---|
| 4 | {
|
---|
[28] | 5 | protected $model;
|
---|
[12] | 6 |
|
---|
[28] | 7 | protected $resourceSurvey;
|
---|
| 8 | protected $surveyUID;
|
---|
[26] | 9 |
|
---|
| 10 | public function __construct($surveyUID)
|
---|
[12] | 11 | {
|
---|
| 12 | // Create empty MemModel
|
---|
| 13 | $factory = new ModelFactory();
|
---|
| 14 | $this->model = $factory->getDefaultModel();
|
---|
| 15 |
|
---|
[26] | 16 | $this->surveyUID = $surveyUID;
|
---|
| 17 |
|
---|
[28] | 18 | }
|
---|
[12] | 19 |
|
---|
[28] | 20 | public function saveSurvey()
|
---|
| 21 | {
|
---|
| 22 | $this->model->saveAs('surveys/survey_'.$this->surveyUID.'.rdf','rdf');
|
---|
| 23 | }
|
---|
| 24 |
|
---|
[12] | 25 | public function createSurvey($sTitle, $sDescription)
|
---|
| 26 | {
|
---|
[26] | 27 | $this->resourceSurvey = new Resource(SURVEY.'/'.$this->surveyUID);
|
---|
[16] | 28 |
|
---|
[26] | 29 | $resourceSurveyType = new Resource(SURVEY);
|
---|
| 30 | $predicateRType = new Resource(RTYPE);
|
---|
| 31 | $this->model->add(new Statement($this->resourceSurvey,$predicateRType,$resourceSurveyType));
|
---|
| 32 |
|
---|
| 33 | $literalSurveyID = new Literal($this->surveyUID);
|
---|
| 34 | $predicateUniqueID = new Resource(UID);
|
---|
| 35 | $this->model->add(new Statement($this->resourceSurvey,$predicateUniqueID,$literalSurveyID));
|
---|
| 36 |
|
---|
[16] | 37 | $predicateTitle = new Resource(TITLE);
|
---|
[12] | 38 | $surveyTitle = new Literal($sTitle);
|
---|
[16] | 39 | $this->model->add(new Statement($this->resourceSurvey,$predicateTitle,$surveyTitle));
|
---|
[12] | 40 |
|
---|
[16] | 41 | $predicateDescription = new Resource(DESCRIPTION);
|
---|
[12] | 42 | $surveyDescription = new Literal($sDescription);
|
---|
[28] | 43 | $this->model->add(new Statement($this->resourceSurvey,$predicateDescription,$surveyDescription));
|
---|
[12] | 44 | }
|
---|
| 45 |
|
---|
[16] | 46 | public function addQuestion($qTitle,$qDescription,$qType,$qAnswers)
|
---|
| 47 | {
|
---|
[26] | 48 | $questionID = md5( uniqid(rand(), true) );
|
---|
| 49 | $resourceQuestion = new Resource(QUESTION.'/'.$questionID);
|
---|
| 50 |
|
---|
| 51 | $resourceQuestionType = new Resource(QUESTION);
|
---|
| 52 | $predicateRType = new Resource(RTYPE);
|
---|
| 53 | $this->model->add(new Statement($resourceQuestion,$predicateRType,$resourceQuestionType));
|
---|
| 54 |
|
---|
| 55 | $predicateUniqueID = new Resource(UID);
|
---|
| 56 | $questionUID = new Literal($questionID);
|
---|
| 57 | $this->model->add(new Statement($resourceQuestion,$predicateUniqueID,$questionUID));
|
---|
| 58 |
|
---|
[16] | 59 | $predicateTitle = new Resource(TITLE);
|
---|
| 60 | $questionTitle = new Literal($qTitle);
|
---|
| 61 | $this->model->add(new Statement($resourceQuestion,$predicateTitle,$questionTitle));
|
---|
| 62 |
|
---|
| 63 | $predicateDescription = new Resource(DESCRIPTION);
|
---|
| 64 | $questionDescription = new Literal($qDescription);
|
---|
| 65 | $this->model->add(new Statement($resourceQuestion,$predicateDescription,$questionDescription));
|
---|
| 66 |
|
---|
[26] | 67 | $predicateQType = new Resource(QTYPE);
|
---|
| 68 | $resourceQuestionType = new Literal($qType);
|
---|
| 69 | $this->model->add(new Statement($resourceQuestion,$predicateQType,$resourceQuestionType));
|
---|
[16] | 70 |
|
---|
| 71 | foreach($qAnswers as $answer)
|
---|
[26] | 72 | {
|
---|
| 73 | $answerID = md5( uniqid(rand(), true) );
|
---|
| 74 | $resourceAnswer = new Resource(ANSWER.'/'.$answerID);
|
---|
| 75 |
|
---|
| 76 | $resourceAnswerType = new Resource(ANSWER);
|
---|
| 77 | $predicateRType = new Resource(RTYPE);
|
---|
| 78 | $this->model->add(new Statement($resourceAnswer,$predicateRType,$resourceAnswerType));
|
---|
| 79 |
|
---|
| 80 | $predicateUniqueID = new Resource(UID);
|
---|
| 81 | $answerUID = new Literal($answerID);
|
---|
| 82 | $this->model->add(new Statement($resourceAnswer,$predicateUniqueID,$answerUID));
|
---|
| 83 |
|
---|
[16] | 84 | $answerTitle = new Literal($answer['Title']);
|
---|
| 85 | $this->model->add(new Statement($resourceAnswer,$predicateTitle,$answerTitle));
|
---|
| 86 |
|
---|
| 87 | $answerDescription = new Literal($answer['Description']);
|
---|
| 88 | $this->model->add(new Statement($resourceAnswer,$predicateDescription,$answerDescription));
|
---|
| 89 |
|
---|
[26] | 90 | $predicateAnswer = new Resource(HAS_ANSWER);
|
---|
| 91 | $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer));
|
---|
[16] | 92 | }
|
---|
| 93 |
|
---|
[26] | 94 | $predicateQuestion = new Resource(HAS_QUESTION);
|
---|
[28] | 95 | $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion));
|
---|
[16] | 96 | }
|
---|
[12] | 97 | }
|
---|
| 98 |
|
---|
| 99 | ?> |
---|