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