source: Dev/trunk/classes/SurveyRDFWriter.php @ 29

Last change on this file since 29 was 28, checked in by basvannuland, 14 years ago

added uid to data return

File size: 3.6 KB
Line 
1<?php
2
3class 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 addQuestion($qTitle,$qDescription,$qType,$qAnswers)
47        {
48                $questionID = md5( uniqid(rand(), true) );
49                $resourceQuestion = new Resource(QUESTION.'/'.$questionID);
50                               
51                $resourceQuestionType = new Resource(QUESTION);
52                $predicateRType = new Resource(RTYPE);
53                $this->model->add(new Statement($resourceQuestion,$predicateRType,$resourceQuestionType));
54                               
55                $predicateUniqueID = new Resource(UID);
56                $questionUID = new Literal($questionID);
57                $this->model->add(new Statement($resourceQuestion,$predicateUniqueID,$questionUID));
58                               
59                $predicateTitle = new Resource(TITLE);         
60                $questionTitle = new Literal($qTitle);
61                $this->model->add(new Statement($resourceQuestion,$predicateTitle,$questionTitle));     
62               
63                $predicateDescription = new Resource(DESCRIPTION);
64                $questionDescription = new Literal($qDescription);
65                $this->model->add(new Statement($resourceQuestion,$predicateDescription,$questionDescription));         
66               
67                $predicateQType = new Resource(QTYPE);
68                $resourceQuestionType = new Literal($qType);
69                $this->model->add(new Statement($resourceQuestion,$predicateQType,$resourceQuestionType));
70               
71                foreach($qAnswers as $answer)
72                {               
73                        $answerID = md5( uniqid(rand(), true) );       
74                        $resourceAnswer = new Resource(ANSWER.'/'.$answerID);
75                               
76                        $resourceAnswerType = new Resource(ANSWER);
77                        $predicateRType = new Resource(RTYPE);
78                        $this->model->add(new Statement($resourceAnswer,$predicateRType,$resourceAnswerType)); 
79
80                        $predicateUniqueID = new Resource(UID);
81                        $answerUID = new Literal($answerID);
82                        $this->model->add(new Statement($resourceAnswer,$predicateUniqueID,$answerUID));                       
83                                               
84                        $answerTitle = new Literal($answer['Title']);
85                        $this->model->add(new Statement($resourceAnswer,$predicateTitle,$answerTitle));
86                       
87                        $answerDescription = new Literal($answer['Description']);
88                        $this->model->add(new Statement($resourceAnswer,$predicateDescription,$answerDescription));
89                       
90                        $predicateAnswer = new Resource(HAS_ANSWER);   
91                        $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer));
92                }
93               
94                $predicateQuestion = new Resource(HAS_QUESTION);
95                $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion));           
96        }
97}
98
99?>
Note: See TracBrowser for help on using the repository browser.