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