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