[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 |
|
---|
[40] | 46 | public function setUserData($userID)
|
---|
| 47 | {
|
---|
| 48 | $resourceUser = new Resource(USER . '/' . $userID);
|
---|
| 49 |
|
---|
| 50 | $predicateCreator = new Resource(CREATOR);
|
---|
| 51 | $this->model->add(new Statement($this->resourceSurvey,$predicateCreator,$resourceUser));
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | public function setApplicationData($applicationID)
|
---|
| 55 | {
|
---|
[44] | 56 | $resourceApplication = new Resource(APPLICATION . '/' . $applicationID);
|
---|
[40] | 57 |
|
---|
| 58 | $predicatePartOf = new Resource(PART_OF);
|
---|
| 59 | $this->model->add(new Statement($this->resourceSurvey,$predicatePartOf,$resourceApplication));
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[31] | 62 | public function addQuestion($qTitle,$qDescription,$qType,$qID,$qAnswers)
|
---|
[16] | 63 | {
|
---|
[31] | 64 | $questionID = $qID;
|
---|
[26] | 65 | $resourceQuestion = new Resource(QUESTION.'/'.$questionID);
|
---|
| 66 |
|
---|
| 67 | $resourceQuestionType = new Resource(QUESTION);
|
---|
| 68 | $predicateRType = new Resource(RTYPE);
|
---|
| 69 | $this->model->add(new Statement($resourceQuestion,$predicateRType,$resourceQuestionType));
|
---|
| 70 |
|
---|
| 71 | $predicateUniqueID = new Resource(UID);
|
---|
| 72 | $questionUID = new Literal($questionID);
|
---|
| 73 | $this->model->add(new Statement($resourceQuestion,$predicateUniqueID,$questionUID));
|
---|
| 74 |
|
---|
[16] | 75 | $predicateTitle = new Resource(TITLE);
|
---|
| 76 | $questionTitle = new Literal($qTitle);
|
---|
| 77 | $this->model->add(new Statement($resourceQuestion,$predicateTitle,$questionTitle));
|
---|
| 78 |
|
---|
| 79 | $predicateDescription = new Resource(DESCRIPTION);
|
---|
| 80 | $questionDescription = new Literal($qDescription);
|
---|
| 81 | $this->model->add(new Statement($resourceQuestion,$predicateDescription,$questionDescription));
|
---|
| 82 |
|
---|
[26] | 83 | $predicateQType = new Resource(QTYPE);
|
---|
| 84 | $resourceQuestionType = new Literal($qType);
|
---|
| 85 | $this->model->add(new Statement($resourceQuestion,$predicateQType,$resourceQuestionType));
|
---|
[16] | 86 |
|
---|
| 87 | foreach($qAnswers as $answer)
|
---|
[26] | 88 | {
|
---|
| 89 | $answerID = md5( uniqid(rand(), true) );
|
---|
| 90 | $resourceAnswer = new Resource(ANSWER.'/'.$answerID);
|
---|
| 91 |
|
---|
| 92 | $resourceAnswerType = new Resource(ANSWER);
|
---|
| 93 | $predicateRType = new Resource(RTYPE);
|
---|
| 94 | $this->model->add(new Statement($resourceAnswer,$predicateRType,$resourceAnswerType));
|
---|
| 95 |
|
---|
| 96 | $predicateUniqueID = new Resource(UID);
|
---|
| 97 | $answerUID = new Literal($answerID);
|
---|
| 98 | $this->model->add(new Statement($resourceAnswer,$predicateUniqueID,$answerUID));
|
---|
| 99 |
|
---|
[16] | 100 | $answerTitle = new Literal($answer['Title']);
|
---|
| 101 | $this->model->add(new Statement($resourceAnswer,$predicateTitle,$answerTitle));
|
---|
| 102 |
|
---|
| 103 | $answerDescription = new Literal($answer['Description']);
|
---|
| 104 | $this->model->add(new Statement($resourceAnswer,$predicateDescription,$answerDescription));
|
---|
| 105 |
|
---|
[26] | 106 | $predicateAnswer = new Resource(HAS_ANSWER);
|
---|
| 107 | $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer));
|
---|
[16] | 108 | }
|
---|
| 109 |
|
---|
[26] | 110 | $predicateQuestion = new Resource(HAS_QUESTION);
|
---|
[28] | 111 | $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion));
|
---|
[16] | 112 | }
|
---|
[12] | 113 | }
|
---|
| 114 |
|
---|
| 115 | ?> |
---|