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

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