Ignore:
Timestamp:
07/20/11 18:05:04 (14 years ago)
Author:
basvannuland
Message:

made some changes to way rdf database is constructed.
Made an interface class to write to db and read from db.
interface returns array with survey information in the same way it gets it from the surveyCreationTool.
TODO, override existing survey when it is modified.

File:
1 edited

Legend:

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

    r16 r26  
    66               
    77        var $resourceSurvey;
    8     /**
    9     * Use SurveyRDFWriter::getInstance() instead of this
    10     * constructor.
    11     */
    12     public function __construct()
     8        var $surveyUID;
     9       
     10    public function __construct($surveyUID)
    1311    {
    1412        // Create empty MemModel
     
    1614                $this->model = $factory->getDefaultModel();
    1715               
    18                 $this->initResources();
     16                $this->surveyUID = $surveyUID;
     17               
    1918    }
    20 
    21         function initResources()
    22         {
    23                
    24                 $this->resourceSurvey = new Resource(SURVEY);
    25         }
    2619       
    2720        public function createSurvey($sTitle, $sDescription)
    2821        {               
     22                $this->resourceSurvey = new Resource(SURVEY.'/'.$this->surveyUID);
     23               
     24                $resourceSurveyType = new Resource(SURVEY);
     25                $predicateRType = new Resource(RTYPE);
     26                $this->model->add(new Statement($this->resourceSurvey,$predicateRType,$resourceSurveyType));
     27               
     28                $literalSurveyID = new Literal($this->surveyUID);
     29                $predicateUniqueID = new Resource(UID);
     30                $this->model->add(new Statement($this->resourceSurvey,$predicateUniqueID,$literalSurveyID));
    2931               
    3032                $predicateTitle = new Resource(TITLE);         
     
    3436                $predicateDescription = new Resource(DESCRIPTION);
    3537                $surveyDescription = new Literal($sDescription);
    36                 $this->model->add(new Statement($this->resourceSurvey,$predicateDescription,$surveyDescription));               
     38                $this->model->add(new Statement($this->resourceSurvey,$predicateDescription,$surveyDescription));
     39               
    3740        }
    3841       
    3942        public function addQuestion($qTitle,$qDescription,$qType,$qAnswers)
    4043        {
    41                 $resourceQuestion = new Resource(QUESTION);
    42                 $predicateQuestion = new Resource(HAS_QUESTION);
    43                 $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion));
    44                
     44                $questionID = md5( uniqid(rand(), true) );
     45                $resourceQuestion = new Resource(QUESTION.'/'.$questionID);
     46                               
     47                $resourceQuestionType = new Resource(QUESTION);
     48                $predicateRType = new Resource(RTYPE);
     49                $this->model->add(new Statement($resourceQuestion,$predicateRType,$resourceQuestionType));
     50                               
     51                $predicateUniqueID = new Resource(UID);
     52                $questionUID = new Literal($questionID);
     53                $this->model->add(new Statement($resourceQuestion,$predicateUniqueID,$questionUID));
     54                               
    4555                $predicateTitle = new Resource(TITLE);         
    4656                $questionTitle = new Literal($qTitle);
     
    5161                $this->model->add(new Statement($resourceQuestion,$predicateDescription,$questionDescription));         
    5262               
    53                 $predicateType = new Resource(TYPE);
    54                 $resourceQuestionType = new Resource(QUESTION_TYPE);
    55                 $this->model->add(new Statement($resourceQuestion,$predicateType,$resourceQuestionType));
     63                $predicateQType = new Resource(QTYPE);
     64                $resourceQuestionType = new Literal($qType);
     65                $this->model->add(new Statement($resourceQuestion,$predicateQType,$resourceQuestionType));
    5666               
    5767                foreach($qAnswers as $answer)
    58                 {
    59                         $resourceAnswer = new Resource(ANSWER);
    60                         $predicateAnswer = new Resource(HAS_ANSWER);   
    61                         $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer));
    62                        
    63                         $predicateTitle = new Resource(TITLE);
     68                {               
     69                        $answerID = md5( uniqid(rand(), true) );       
     70                        $resourceAnswer = new Resource(ANSWER.'/'.$answerID);
     71                               
     72                        $resourceAnswerType = new Resource(ANSWER);
     73                        $predicateRType = new Resource(RTYPE);
     74                        $this->model->add(new Statement($resourceAnswer,$predicateRType,$resourceAnswerType)); 
     75
     76                        $predicateUniqueID = new Resource(UID);
     77                        $answerUID = new Literal($answerID);
     78                        $this->model->add(new Statement($resourceAnswer,$predicateUniqueID,$answerUID));                       
     79                                               
    6480                        $answerTitle = new Literal($answer['Title']);
    6581                        $this->model->add(new Statement($resourceAnswer,$predicateTitle,$answerTitle));
    6682                       
    67                         $predicateDescription = new Resource(DESCRIPTION);
    6883                        $answerDescription = new Literal($answer['Description']);
    6984                        $this->model->add(new Statement($resourceAnswer,$predicateDescription,$answerDescription));
    7085                       
     86                        $predicateAnswer = new Resource(HAS_ANSWER);   
     87                        $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer));
    7188                }
    7289               
     90                $predicateQuestion = new Resource(HAS_QUESTION);
     91                $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion));
    7392               
    7493        }
    7594       
    76         public function saveSurvey($sTitle)
    77         {
    78                 $this->model->saveAs('surveys/'.$sTitle.'.rdf','rdf');
    79                
    80                 return true;
     95        public function saveSurvey()
     96        {       
     97                $this->model->saveAs('surveys/'.$this->surveyUID.'.rdf','rdf');
    8198        }
    8299
Note: See TracChangeset for help on using the changeset viewer.