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

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

start with answer saving

File size: 2.5 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);
[31]27    }
[62]28
[83]29    public function saveSurveyData()
[62]30    {           
[83]31        $this->model->saveAs($this->path.'/answer_'.$this->respondentID.'.rdf','rdf');
[62]32    }
33
34    public function setRespondentData($name)
35    {                           
[83]36        $resourceUser = new Resource(USER . '/' . $this->respondentID);         
[62]37
38        $resourceUserType = new Resource(USER);
39        $predicateRType = new Resource(RTYPE);
40        $this->model->add(new Statement($resourceUser,$predicateRType,$resourceUserType));
41
[83]42        $literalUserName = new Literal($name);
[62]43        $predicateName = new Resource(NAME);
[83]44        $this->model->add(new Statement($resourceUser,$predicateName,$literalUserName));               
[62]45
[83]46        $literalUserID = new Literal($this->respondentID);
[62]47        $predicateUniqueID = new Resource(UID);
48        $this->model->add(new Statement($resourceUser,$predicateUniqueID,$literalUserID));
49
[83]50        $resourceSurvey = new Resource(SURVEY.'/'.$this->surveyID);
51        $predicateRespondent = new Resource(RESPONDENT);
52        $this->model->add(new Statement($resourceSurvey,$predicateRespondent,$resourceUser));
53       
54        $this->saveSurveyData();
[62]55    }
56
57    public function setAnswers($answers)
58    {
59        foreach($answers as $questionID => $answerValue)
[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           
[62]67            $predicateAnswered = new Resource(ANSWERED);       
68            $answer = new Literal($answerValue);
69            $this->model->add(new Statement($resourceQuestion,$predicateAnswered,$answer));
70        }
71    }
[31]72}
73
74?>
Note: See TracBrowser for help on using the repository browser.