[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 |
|
---|
[82] | 50 | public function setUserData($uID)
|
---|
[62] | 51 | {
|
---|
[82] | 52 | $userID = new Literal($uID);
|
---|
[62] | 53 |
|
---|
| 54 | $predicateCreator = new Resource(CREATOR);
|
---|
[82] | 55 | $this->model->add(new Statement($this->resourceSurvey,$predicateCreator,$userID));
|
---|
[62] | 56 | }
|
---|
| 57 |
|
---|
[82] | 58 | public function addQuestion($qID)
|
---|
| 59 | {
|
---|
| 60 | $questionID = new Literal($qID);
|
---|
| 61 | $predicateQuestion = new Resource(HAS_QUESTION);
|
---|
| 62 | $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$questionID));
|
---|
| 63 | }
|
---|
[12] | 64 | }
|
---|
| 65 |
|
---|
| 66 | ?> |
---|