1 | <?php
|
---|
2 |
|
---|
3 | class SurveyRDFWriter
|
---|
4 | {
|
---|
5 | protected $model;
|
---|
6 |
|
---|
7 | protected $resourceSurvey;
|
---|
8 | protected $surveyUID;
|
---|
9 | protected $filePath;
|
---|
10 |
|
---|
11 | public function __construct($surveyUID)
|
---|
12 | {
|
---|
13 | // Create empty MemModel
|
---|
14 | $factory = new ModelFactory();
|
---|
15 | $this->model = $factory->getDefaultModel();
|
---|
16 |
|
---|
17 | $this->surveyUID = $surveyUID;
|
---|
18 | $this->filePath = 'data/surveys/survey_'.$this->surveyUID.'.rdf';
|
---|
19 |
|
---|
20 | }
|
---|
21 |
|
---|
22 | public function saveSurvey()
|
---|
23 | {
|
---|
24 | $this->model->saveAs($this->filePath);
|
---|
25 | }
|
---|
26 |
|
---|
27 | public function createSurvey($sTitle, $sDescription)
|
---|
28 | {
|
---|
29 | $this->resourceSurvey = new Resource(SURVEY.'/'.$this->surveyUID);
|
---|
30 |
|
---|
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 |
|
---|
39 | $predicateTitle = new Resource(TITLE);
|
---|
40 | $surveyTitle = new Literal($sTitle);
|
---|
41 | $this->model->add(new Statement($this->resourceSurvey,$predicateTitle,$surveyTitle));
|
---|
42 |
|
---|
43 | $predicateDescription = new Resource(DESCRIPTION);
|
---|
44 | $surveyDescription = new Literal($sDescription);
|
---|
45 | $this->model->add(new Statement($this->resourceSurvey,$predicateDescription,$surveyDescription));
|
---|
46 | }
|
---|
47 |
|
---|
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 | {
|
---|
58 | $resourceApplication = new Resource(APPLICATION . '/' . $applicationID);
|
---|
59 |
|
---|
60 | $predicatePartOf = new Resource(PART_OF);
|
---|
61 | $this->model->add(new Statement($this->resourceSurvey,$predicatePartOf,$resourceApplication));
|
---|
62 | }
|
---|
63 |
|
---|
64 | public function addQuestion($qTitle,$qDescription,$qType,$qID,$qAnswers)
|
---|
65 | {
|
---|
66 | $questionID = $qID;
|
---|
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 |
|
---|
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 |
|
---|
85 | $predicateQType = new Resource(QTYPE);
|
---|
86 | $resourceQuestionType = new Literal($qType);
|
---|
87 | $this->model->add(new Statement($resourceQuestion,$predicateQType,$resourceQuestionType));
|
---|
88 |
|
---|
89 | foreach($qAnswers as $answer)
|
---|
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 |
|
---|
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 |
|
---|
108 | $predicateAnswer = new Resource(HAS_ANSWER);
|
---|
109 | $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer));
|
---|
110 | }
|
---|
111 |
|
---|
112 | $predicateQuestion = new Resource(HAS_QUESTION);
|
---|
113 | $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion));
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | ?> |
---|