source: Dev/trunk/classes/SurveyAnswerRDFWriter.php @ 99

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

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

File size: 2.7 KB
Line 
1<?php
2
3class SurveyAnswerRDFWriter
4{
5    protected $surveyID;
6    protected $respondentID;
7    protected $path;
8
9    public function __construct($surveyID,$sessionID,$respondentID)
10    {
11        // Create empty MemModel
12        $factory = new ModelFactory();
13        $this->model = $factory->getDefaultModel();
14       
15        $basePath = 'data/sessions/';
16        $sessionPath = $basePath . $sessionID . '/';
17        $this->path  = $sessionPath .'survey_'.$surveyID . '/';
18        $this->surveyID = $surveyID;
19        $this->respondentID = $respondentID;
20       
21        if (!is_dir($basePath))
22            mkdir($basePath);
23        if (!is_dir($sessionPath))
24             mkdir($sessionPath);
25        if (!is_dir($this->path))
26              mkdir($this->path);
27        if(file_exists($this->path.'/answer_'.$this->respondentID.'.rdf'))
28            $this->model->load($this->path.'/answer_'.$this->respondentID.'.rdf');
29    }
30
31    public function saveSurveyData()
32    {
33        $this->model->saveAs($this->path.'/answer_'.$this->respondentID.'.rdf','rdf');
34    }
35
36    public function setRespondentData($name)
37    {                           
38        $resourceUser = new Resource(USER . '/' . $this->respondentID);         
39
40        $resourceUserType = new Resource(USER);
41        $predicateRType = new Resource(RTYPE);
42        $this->model->add(new Statement($resourceUser,$predicateRType,$resourceUserType));
43
44        $literalUserName = new Literal($name);
45        $predicateName = new Resource(NAME);
46        $this->model->add(new Statement($resourceUser,$predicateName,$literalUserName));               
47
48        $literalUserID = new Literal($this->respondentID);
49        $predicateUniqueID = new Resource(UID);
50        $this->model->add(new Statement($resourceUser,$predicateUniqueID,$literalUserID));
51
52        $resourceSurvey = new Resource(SURVEY.'/'.$this->surveyID);
53        $predicateRespondent = new Resource(RESPONDENT);
54        $this->model->add(new Statement($resourceSurvey,$predicateRespondent,$resourceUser));
55    }
56
57    public function setAnswers($answers)
58    {
59        foreach($answers as $questionID => $answerValues)
60        {
61            $resourceQuestion = new Resource(QUESTION.'/'.$questionID);
62
63            $resourceQuestionType = new Resource(QUESTION);
64            $predicateRType = new Resource(RTYPE);
65            $this->model->add(new Statement($resourceQuestion,$predicateRType,$resourceQuestionType));
66           
67            foreach($answerValues as $answerValue)
68            {
69                $predicateAnswered = new Resource(ANSWERED);   
70                $answer = new Literal($answerValue);
71                $this->model->add(new Statement($resourceQuestion,$predicateAnswered,$answer));
72            }
73        }
74    }
75}
76
77?>
Note: See TracBrowser for help on using the repository browser.