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/SurveyRDFReader.php

    r16 r26  
    44{
    55        var $model;
    6                
    7         public function SurveyRDFReader()
    8         {
     6       
     7        var $surveyUID;
     8       
     9    public function __construct($surveyUID)
     10    {
    911        // Create empty MemModel
    1012                $factory = new ModelFactory();
    11                 $this->model = $factory->getDefaultModel();     
     13                $this->model = $factory->getDefaultModel();
     14               
     15                $this->surveyUID = $surveyUID;
    1216        }
    1317       
    14         public function loadSurvey($sTitle)
     18        public function loadSurvey()
    1519        {
    16                 $this->model->load('surveys/'.$sTitle.'.rdf');
     20                $this->model->load('surveys/'.$this->surveyUID.'.rdf');
    1721        }
    1822       
    19         public function readSurveyTitle()
     23        public function getSurveyInfo()
     24        {               
     25                SurveyRDFReader::loadSurvey();
     26       
     27                $result = array();
     28                $result[] = $this->readSurveyInfo();                           
     29                $result[] = $this->readSurveyQuestions();
     30               
     31                return $result;
     32        }
     33       
     34        public function readSurveyInfo()
    2035        {
    2136                $querystring = '
    22                         PREFIX  predicates: <' .SURVEYTOOL_PREDICATES_NAMESPACE . '>
     37                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
    2338                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
    24                         SELECT  ?title
    25                         WHERE   { resources:survey predicates:title ?title }';
     39                        SELECT  ?title ?description
     40                        WHERE   
     41                        {
     42                                _survey         predicates:resource_type        resources:survey ;
     43                                                        predicates:title                        ?title ;
     44                                                        predicates:description          ?description
     45                        }';
     46                       
     47                $result = $this->model->sparqlQuery($querystring);
     48                               
     49                return $result;
     50        }
     51       
     52        public function readSurveyQuestions()
     53        {
     54                $result = array();
     55                $result[] = $this->readSurveyQuestionsTitle();                         
     56                $result[] = $this->readSurveyQuestionsDescription();
     57                $result[] = $this->readSurveyQuestionsType();
     58                $result[] = $this->readSurveyQuestionsID();             
     59                               
     60                return $result;
     61        }
     62       
     63        public function readSurveyQuestionsTitle()
     64        {
     65                $querystring = '
     66                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
     67                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
     68                        SELECT  ?questionTitle
     69                        WHERE
     70                        {       
     71                                _question       predicates:resource_type        resources:question ;
     72                                                        predicates:title                        ?questionTitle         
     73                        }';
    2674                       
    2775                $result = $this->model->sparqlQuery($querystring);
     
    3078        }
    3179       
    32         public function readSurveyDescription()
     80        public function readSurveyQuestionsDescription()
    3381        {
    3482                $querystring = '
    35                         PREFIX  predicates: <' .SURVEYTOOL_PREDICATES_NAMESPACE . '>
     83                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
    3684                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
    37                         SELECT  ?description
    38                         WHERE   { resources:survey predicates:description ?description }';
     85                        SELECT  ?questionDescription
     86                        WHERE
     87                        {       
     88                                _question       predicates:resource_type        resources:question ;
     89                                                        predicates:description  ?questionDescription           
     90                        }';
     91                       
     92                $result = $this->model->sparqlQuery($querystring);
     93               
     94                return $result;
     95        }
     96       
     97        public function readSurveyQuestionsType()
     98        {
     99                $querystring = '
     100                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
     101                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
     102                        SELECT  ?questionType
     103                        WHERE
     104                        {       
     105                                _question       predicates:resource_type        resources:question ;
     106                                                        predicates:question_type        ?questionType                           
     107                        }';
     108                       
     109                $result = $this->model->sparqlQuery($querystring);
     110               
     111                return $result;
     112        }
     113       
     114        public function readSurveyQuestionsID()
     115        {
     116                $querystring = '
     117                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
     118                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
     119                        SELECT  ?questionID
     120                        WHERE
     121                        {       
     122                                _question       predicates:resource_type        resources:question ;
     123                                                        predicates:uid                          ?questionID                             
     124                        }';
     125                       
     126                $result = $this->model->sparqlQuery($querystring);
     127               
     128                return $result;
     129        }
     130       
     131        public function readSurveyAnswers($qID)
     132        {
     133                $querystring = '
     134                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
     135                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
     136                        SELECT  ?answerTitle
     137                        WHERE
     138                        {
     139                                _question               predicates:resource_type        resources:question ;
     140                                                                predicates:uid                          "' . $qID . '"  ;
     141                                                                predicates:has_answer           _answer .
     142                                _answer                 predicates:title                        ?answerTitle                                                           
     143                        }';
    39144                       
    40145                $result = $this->model->sparqlQuery($querystring);
Note: See TracChangeset for help on using the changeset viewer.