[12] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | class SurveyRDFWriter
|
---|
| 4 | {
|
---|
| 5 | var $model;
|
---|
| 6 |
|
---|
| 7 | var $resourceSurvey;
|
---|
| 8 | /**
|
---|
| 9 | * Use SurveyRDFWriter::getInstance() instead of this
|
---|
| 10 | * constructor.
|
---|
| 11 | */
|
---|
| 12 | public function __construct()
|
---|
| 13 | {
|
---|
| 14 | // Create empty MemModel
|
---|
| 15 | $factory = new ModelFactory();
|
---|
| 16 | $this->model = $factory->getDefaultModel();
|
---|
| 17 |
|
---|
| 18 | $this->initResources();
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | function initResources()
|
---|
| 22 | {
|
---|
| 23 |
|
---|
[16] | 24 | $this->resourceSurvey = new Resource(SURVEY);
|
---|
[12] | 25 | }
|
---|
| 26 |
|
---|
| 27 | public function createSurvey($sTitle, $sDescription)
|
---|
| 28 | {
|
---|
[16] | 29 |
|
---|
| 30 | $predicateTitle = new Resource(TITLE);
|
---|
[12] | 31 | $surveyTitle = new Literal($sTitle);
|
---|
[16] | 32 | $this->model->add(new Statement($this->resourceSurvey,$predicateTitle,$surveyTitle));
|
---|
[12] | 33 |
|
---|
[16] | 34 | $predicateDescription = new Resource(DESCRIPTION);
|
---|
[12] | 35 | $surveyDescription = new Literal($sDescription);
|
---|
[16] | 36 | $this->model->add(new Statement($this->resourceSurvey,$predicateDescription,$surveyDescription));
|
---|
[12] | 37 | }
|
---|
| 38 |
|
---|
[16] | 39 | public function addQuestion($qTitle,$qDescription,$qType,$qAnswers)
|
---|
| 40 | {
|
---|
| 41 | $resourceQuestion = new Resource(QUESTION);
|
---|
| 42 | $predicateQuestion = new Resource(HAS_QUESTION);
|
---|
| 43 | $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion));
|
---|
| 44 |
|
---|
| 45 | $predicateTitle = new Resource(TITLE);
|
---|
| 46 | $questionTitle = new Literal($qTitle);
|
---|
| 47 | $this->model->add(new Statement($resourceQuestion,$predicateTitle,$questionTitle));
|
---|
| 48 |
|
---|
| 49 | $predicateDescription = new Resource(DESCRIPTION);
|
---|
| 50 | $questionDescription = new Literal($qDescription);
|
---|
| 51 | $this->model->add(new Statement($resourceQuestion,$predicateDescription,$questionDescription));
|
---|
| 52 |
|
---|
| 53 | $predicateType = new Resource(TYPE);
|
---|
| 54 | $resourceQuestionType = new Resource(QUESTION_TYPE);
|
---|
| 55 | $this->model->add(new Statement($resourceQuestion,$predicateType,$resourceQuestionType));
|
---|
| 56 |
|
---|
| 57 | foreach($qAnswers as $answer)
|
---|
| 58 | {
|
---|
| 59 | $resourceAnswer = new Resource(ANSWER);
|
---|
| 60 | $predicateAnswer = new Resource(HAS_ANSWER);
|
---|
| 61 | $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer));
|
---|
| 62 |
|
---|
| 63 | $predicateTitle = new Resource(TITLE);
|
---|
| 64 | $answerTitle = new Literal($answer['Title']);
|
---|
| 65 | $this->model->add(new Statement($resourceAnswer,$predicateTitle,$answerTitle));
|
---|
| 66 |
|
---|
| 67 | $predicateDescription = new Resource(DESCRIPTION);
|
---|
| 68 | $answerDescription = new Literal($answer['Description']);
|
---|
| 69 | $this->model->add(new Statement($resourceAnswer,$predicateDescription,$answerDescription));
|
---|
| 70 |
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[12] | 76 | public function saveSurvey($sTitle)
|
---|
| 77 | {
|
---|
| 78 | $this->model->saveAs('surveys/'.$sTitle.'.rdf','rdf');
|
---|
| 79 |
|
---|
| 80 | return true;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | ?> |
---|