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