source: Dev/trunk/classes/QuestionRDFWriter.php @ 101

Last change on this file since 101 was 85, checked in by basvannuland, 14 years ago

Base for all databases done. not tested. Need frontend to properly test.

File size: 2.4 KB
Line 
1<?php
2class 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,$qID,$qCode,$qCategory,$qAnswers)
27    {
28        $resourceQuestion = new Resource(QUESTION.'/'.$qID);
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        $predicateUniqueID = new Resource(UID);
47        $questionUID = new Literal($qID);
48        $this->model->add(new Statement($resourceQuestion,$predicateUniqueID,$questionUID));
49       
50        $predicateQCode = new Resource(QCODE);
51        $questionQCode = new Literal($qCode);
52        $this->model->add(new Statement($resourceQuestion,$predicateQCode,$questionQCode));
53       
54        $predicateQCategory = new Resource(QCATEGORY);
55        $questionQCategory = new Literal($qCategory);
56        $this->model->add(new Statement($resourceQuestion,$predicateQCategory,$questionQCategory));
57
58        foreach($qAnswers as $answer)
59        {               
60            $answerValue = new Literal($answer);
61            $predicateAnswer = new Resource(HAS_ANSWER);       
62            $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$answerValue));
63        }       
64    }
65}
66?>
Note: See TracBrowser for help on using the repository browser.