Ignore:
Timestamp:
07/29/11 14:51:06 (14 years ago)
Author:
basvannuland
Message:

updates to the database system. ao New file structure

File:
1 edited

Legend:

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

    r51 r62  
    11<?php
    22
    3 class SurveyAnswerRDFReader extends SurveyRDFReader
     3class SurveyAnswerRDFReader
    44{       
    5         protected $tempModel;
    6         protected $answerPath;
    7        
    8     public function __construct($surveyUID)
     5    protected $model;
     6    protected $filePath;
     7
     8    public function __construct($surveyUID,$sessionID)
    99    {
    10         parent::__construct($surveyUID);
    11                
    12                 // Create empty MemModel
    13                 $factory = new ModelFactory();
    14                 $this->tempModel = $factory->getDefaultModel();
    15                 $this->answerPath = 'data/surveys/answers_'.$this->surveyUID;
    16         }
    17        
    18         public function loadSurvey()
    19         {
    20                 parent::loadSurvey();           
    21                
    22         }
    23        
    24         public function getAnswerByQuestion($questionID)
    25         {
    26                 $this->tempModel->loadModel($this->model);
    27                
    28                 $answers = array();
    29                
    30                 if($handle = opendir($this->answerPath))
    31                 {
    32                         while (false !== ($file = readdir($handle))) {
    33                                 if(strstr($file, 'answer_'))
    34                                         $answers[] = substr($file,0,strlen($file)-4);
    35                         }
    36                 }
    37                
    38                 foreach($answers as $answer)
    39                 {
    40                         $this->tempModel->load($this->answerPath.'/'.$answer);
    41                 }
    42                
    43                 $this->tempModel->visualize();
    44        
    45                 $querystring = '
    46                         PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
    47                         PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
    48                         SELECT  ?answered
    49                         WHERE   
    50                         {
    51                                 _question       predicates:resource_type        resources:question ;
    52                                                         predicates:uid                          "'.$questionID.'"       ;
    53                                                         predicates:answered             ?answered       
    54                         }';
    55                        
    56                 $result = $this->tempModel->sparqlQuery($querystring);
    57                
    58                 $this->tempModel->close();             
    5910
    60                 $this->tempModel->visualize();
    61                                
    62                 return $result;
    63         }
    64        
    65         public function getAnswerByRespondent($respondentID)
    66         {
    67                 $this->tempModel->loadModel($this->model);
    68                
    69                 $this->tempModel->load($this->answerPath . '/$answer_' . $respondentID);
    70                
    71                 $this->tempModel->visualize();
    72        
    73                 $querystring = '
    74                         PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
    75                         PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
    76                         SELECT  ?answered
    77                         WHERE   
    78                         {
    79                                 _question       predicates:resource_type        resources:question ;
    80                                                         predicates:answered             ?answered       
    81                         }';
    82                        
    83                 $result = $this->tempModel->sparqlQuery($querystring);
    84                
    85                 $this->tempModel->close();             
     11        // Create empty MemModel
     12        $factory = new ModelFactory();
     13        $this->model = $factory->getDefaultModel();
     14        $this->filePath = 'data/surveys/survey_'.$surveyUID . '.rdf';
     15       
     16        $this->model->load($this->filePath);
     17    }
    8618
    87                 $this->tempModel->visualize();
    88                                
    89                 return $result;
    90         }
    91        
    92         public function getAnswerByRespondentAndQuestion($respondentID,$questionID)
    93         {
    94                 $this->tempModel->loadModel($this->model);
    95                                
    96                 $this->tempModel->load($this->answerPath . '/$answer_' . $respondentID);
    97                
    98                 $this->tempModel->visualize();
    99        
    100                 $querystring = '
    101                         PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
    102                         PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
    103                         SELECT  ?answered
    104                         WHERE   
    105                         {
    106                                 _question       predicates:resource_type        resources:question ;
    107                                                         predicates:uid                          "'.$questionID.'"       ;
    108                                                         predicates:answered             ?answered       
    109                         }';
    110                        
    111                 $result = $this->tempModel->sparqlQuery($querystring);
    112                
    113                 $this->tempModel->close();             
     19    public function loadAnsers($userID)
     20    {
     21        $this->model->load($this->filePath.'/answer_'.$this->userUID.'.rdf');
     22    }
    11423
    115                 $this->tempModel->visualize();
    116                                
    117                 return $result;
    118         }
     24    public function getAnswers()
     25    {
     26        $querystring = '
     27            PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
     28            PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
     29            SELECT  ?answered
     30            WHERE       
     31            {
     32                    _answer        predicates:answered          ?answered       
     33            }';
     34
     35        $result = $this->model->sparqlQuery($querystring);
     36
     37        return $result;
     38    }
     39
     40    public function getAnswerByQuestionID($questionID)
     41    {
     42        $querystring = '
     43            PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
     44            PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
     45            SELECT  ?answered
     46            WHERE       
     47            {
     48                    _question   predicates:resource_type        resources:question ;
     49                                predicates:uid                  "'.$questionID.'"       ;
     50                                predicates:answered             ?answered       
     51            }';
     52
     53        $result = $this->model->sparqlQuery($querystring);
     54
     55        return $result;
     56    }
     57
     58    public function getAnswerByRespondent($respondentID)
     59    {
     60        $this->tempModel->loadModel($this->model);
     61
     62        $this->tempModel->load($this->answerPath . '/$answer_' . $respondentID);
     63
     64        $this->tempModel->visualize();
     65
     66        $querystring = '
     67            PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
     68            PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
     69            SELECT  ?answered
     70            WHERE       
     71            {
     72                    _question   predicates:resource_type        resources:question ;
     73                                predicates:answered             ?answered       
     74            }';
     75
     76        $result = $this->tempModel->sparqlQuery($querystring);
     77
     78        $this->tempModel->close();             
     79
     80        $this->tempModel->visualize();
     81
     82        return $result;
     83    }
     84
     85    public function getAnswerByRespondentAndQuestion($respondentID,$questionID)
     86    {
     87        $this->tempModel->loadModel($this->model);
     88
     89        $this->tempModel->load($this->answerPath . '/$answer_' . $respondentID);
     90
     91        $this->tempModel->visualize();
     92
     93        $querystring = '
     94            PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
     95            PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
     96            SELECT  ?answered
     97            WHERE       
     98            {
     99                    _question   predicates:resource_type        resources:question ;
     100                                predicates:uid                  "'.$questionID.'"       ;
     101                                predicates:answered             ?answered       
     102            }';
     103
     104        $result = $this->tempModel->sparqlQuery($querystring);
     105
     106        $this->tempModel->close();             
     107
     108        $this->tempModel->visualize();
     109
     110        return $result;
     111    }
    119112}
    120113
Note: See TracChangeset for help on using the changeset viewer.