1 | <?php |
---|
2 | class QuestionRDFWriter |
---|
3 | { |
---|
4 | protected $model; |
---|
5 | |
---|
6 | protected $filePath = 'data/questions/'; |
---|
7 | |
---|
8 | public function __construct() |
---|
9 | { |
---|
10 | // Create empty MemModel |
---|
11 | $factory = new ModelFactory(); |
---|
12 | $this->model = $factory->getDefaultModel(); |
---|
13 | |
---|
14 | if (!is_dir($this->filePath)) |
---|
15 | mkdir($this->filePath); |
---|
16 | |
---|
17 | if(file_exists($this->filePath.'questions.rdf')) |
---|
18 | $this->model->load($this->filePath.'questions.rdf'); |
---|
19 | } |
---|
20 | |
---|
21 | public function saveQuestions() |
---|
22 | { |
---|
23 | $this->model->saveAs($this->filePath.'questions.rdf','rdf'); |
---|
24 | } |
---|
25 | |
---|
26 | public function createQuestion($qTitle,$qDescription,$qType,$qCode,$qCategory,$qAnswers) |
---|
27 | { |
---|
28 | $resourceQuestion = new Resource(QUESTION.'/'.$qCode); |
---|
29 | |
---|
30 | $resourceQuestionType = new Resource(QUESTION); |
---|
31 | $predicateRType = new Resource(RTYPE); |
---|
32 | $this->model->add(new Statement($resourceQuestion,$predicateRType,$resourceQuestionType)); |
---|
33 | |
---|
34 | $predicateTitle = new Resource(TITLE); |
---|
35 | $questionTitle = new Literal($qTitle); |
---|
36 | $this->model->add(new Statement($resourceQuestion,$predicateTitle,$questionTitle)); |
---|
37 | |
---|
38 | $predicateDescription = new Resource(DESCRIPTION); |
---|
39 | $questionDescription = new Literal($qDescription); |
---|
40 | $this->model->add(new Statement($resourceQuestion,$predicateDescription,$questionDescription)); |
---|
41 | |
---|
42 | $predicateQType = new Resource(QTYPE); |
---|
43 | $resourceQuestionType = new Literal($qType); |
---|
44 | $this->model->add(new Statement($resourceQuestion,$predicateQType,$resourceQuestionType)); |
---|
45 | |
---|
46 | $predicateQCode = new Resource(QCODE); |
---|
47 | $questionQCode = new Literal($qCode); |
---|
48 | $this->model->add(new Statement($resourceQuestion,$predicateQCode,$questionQCode)); |
---|
49 | |
---|
50 | $predicateQCategory = new Resource(QCATEGORY); |
---|
51 | $questionQCategory = new Literal($qCategory); |
---|
52 | $this->model->add(new Statement($resourceQuestion,$predicateQCategory,$questionQCategory)); |
---|
53 | |
---|
54 | foreach($qAnswers as $answer) |
---|
55 | { |
---|
56 | $answerValue = new Literal($answer); |
---|
57 | $predicateAnswer = new Resource(HAS_ANSWER); |
---|
58 | $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$answerValue)); |
---|
59 | } |
---|
60 | } |
---|
61 | } |
---|
62 | ?> |
---|