Ignore:
Timestamp:
08/25/11 17:52:09 (14 years ago)
Author:
basvannuland
Message:

start with answer saving

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/classes/SurveyAnswerRDFWriter.php

    r62 r83  
    33class SurveyAnswerRDFWriter
    44{
    5     protected $userUID;
    6     protected $filePath;
     5    protected $surveyID;
     6    protected $respondentID;
     7    protected $path;
    78
    8     public function __construct($surveyUID,$sessionID,$userID)
     9    public function __construct($surveyID,$sessionID,$respondentID)
    910    {
    1011        // Create empty MemModel
     
    1213        $this->model = $factory->getDefaultModel();
    1314       
    14         $this->filePath = 'data/sessions/' .  $sessionID . '/survey_'.$surveyUID . '/';
    15         $this->userID = $userID;
     15        $basePath = 'data/sessions/';
     16        $sessionPath = $basePath . $sessionID . '/';
     17        $this->path  = $sessionPath .'survey_'.$surveyID . '/';
     18        $this->surveyID = $surveyID;
     19        $this->respondentID = $respondentID;
    1620       
    17         if (!is_dir($this->filePath))
    18             mkdir($this->filePath);             
     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);
    1927    }
    2028
    21     public function saveSurvey()
     29    public function saveSurveyData()
    2230    {           
    23         $this->model->saveAs($this->filePath.'/answer_'.$this->userUID.'.rdf','rdf');
     31        $this->model->saveAs($this->path.'/answer_'.$this->respondentID.'.rdf','rdf');
    2432    }
    2533
    2634    public function setRespondentData($name)
    2735    {                           
    28         $resourceUser = new Resource(USER . '/' . $this->userID);               
     36        $resourceUser = new Resource(USER . '/' . $this->respondentID);         
    2937
    3038        $resourceUserType = new Resource(USER);
     
    3240        $this->model->add(new Statement($resourceUser,$predicateRType,$resourceUserType));
    3341
    34         $LiteralUserName = new Literal($name);
     42        $literalUserName = new Literal($name);
    3543        $predicateName = new Resource(NAME);
    36         $this->model->add(new Statement($resourceUser,$predicateUniqueID,$LiteralUserName));           
     44        $this->model->add(new Statement($resourceUser,$predicateName,$literalUserName));               
    3745
    38         $literalUserID = new Literal($this->userUID);
     46        $literalUserID = new Literal($this->respondentID);
    3947        $predicateUniqueID = new Resource(UID);
    4048        $this->model->add(new Statement($resourceUser,$predicateUniqueID,$literalUserID));
    4149
    42         $predicateRespondent = new Resource(REPONDENT);
    43         $this->model->add(new Statement($this->resourceSurvey,$predicateRespondent,$resourceUser));
     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();
    4455    }
    4556
     
    4758    {
    4859        foreach($answers as $questionID => $answerValue)
    49         {                                       
     60        {
    5061            $resourceQuestion = new Resource(QUESTION.'/'.$questionID);
    5162
     63            $resourceQuestionType = new Resource(QUESTION);
     64            $predicateRType = new Resource(RTYPE);
     65            $this->model->add(new Statement($resourceQuestion,$predicateRType,$resourceQuestionType));
     66           
    5267            $predicateAnswered = new Resource(ANSWERED);       
    5368            $answer = new Literal($answerValue);
Note: See TracChangeset for help on using the changeset viewer.