Changeset 40 for Dev/trunk


Ignore:
Timestamp:
07/22/11 17:28:23 (14 years ago)
Author:
basvannuland
Message:

added database readers and writers for application info and facilitator info

possible to store survey application and creator info

Location:
Dev/trunk
Files:
5 added
7 edited

Legend:

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

    r33 r40  
    1616 
    1717
    18     public function __construct($surveyID=null)
    19     {
    20                 if($surveyID == null)
    21                         $surveyUID = md5( uniqid(rand(), true) );
    22                 else
    23                         $surveyUID = $surveyID;
    24                                        
    25                 $this->surveyAnswerRDFWriter = new SurveyAnswerRDFWriter($surveyUID);
     18    public function __construct($surveyID,$userID)
     19    {                                   
     20                $this->surveyAnswerRDFWriter = new SurveyAnswerRDFWriter($surveyUID,$userID);
    2621                $this->surveyAnswerRDFReader = new SurveyAnswerRDFReader($surveyUID);
    2722    }
    2823       
    29        
     24        public function setSurveyAnswerInfo($surveyInfo)
     25        {
     26
     27        }       
    3028}
    3129?>
  • Dev/trunk/classes/SurveyAnswerRDFReader.php

    r31 r40  
    33class SurveyAnswerRDFReader extends SurveyRDFReader
    44{       
     5        protected $tempModel;
     6       
    57    public function __construct($surveyUID)
    68    {
    79        parent::__construct($surveyUID);
     10               
     11                / Create empty MemModel
     12                $factory = new ModelFactory();
     13                $this->tempModel = $factory->getDefaultModel();
    814        }
    915       
    1016        public function loadSurvey()
    1117        {
    12                 parent::loadSurvey();
     18                parent::loadSurvey();           
     19               
     20        }
     21       
     22        public function getAnswerByQuestion($questionID)
     23        {
     24                $this->tempModel->loadModel($this->model);
     25               
    1326                $answerPath = 'surveys/answers_'.$this->surveyUID;
    1427                $answers = array();
     
    2437                foreach($answers as $answer)
    2538                {
    26                         $this->model->load($answerPath.'/'.$answer);
     39                        $this->tempModel->load($answerPath.'/'.$answer);
    2740                }
    28         }
     41               
     42                $this->tempModel->visualize();
    2943       
    30         public function getAnswer($questionID)
    31         {
    32         $querystring = '
     44                $querystring = '
    3345                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
    3446                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
     
    4153                        }';
    4254                       
    43                 $result = $this->model->sparqlQuery($querystring);
     55                $result = $this->tempModel->sparqlQuery($querystring);
     56               
     57                $this->tempModel->close();             
     58
     59                $this->tempModel->visualize();
     60                               
     61                return $result;
     62        }
     63       
     64        public function getAnswerByRespondent($respondentID)
     65        {
     66                $this->tempModel->loadModel($this->model);
     67               
     68                $answerPath = 'surveys/answers_'.$this->surveyUID;
     69               
     70                $this->tempModel->load($answerPath . '/$answer_' . $respondentID);
     71               
     72                $this->tempModel->visualize();
     73       
     74                $querystring = '
     75                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
     76                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
     77                        SELECT  ?answered
     78                        WHERE   
     79                        {
     80                                _question       predicates:resource_type        resources:question ;
     81                                                        predicates:answered             ?answered       
     82                        }';
     83                       
     84                $result = $this->tempModel->sparqlQuery($querystring);
     85               
     86                $this->tempModel->close();             
     87
     88                $this->tempModel->visualize();
     89                               
     90                return $result;
     91        }
     92       
     93        public function getAnswerByRespondentAndQuestion($respondentID,$questionID)
     94        {
     95                $this->tempModel->loadModel($this->model);
     96               
     97                $answerPath = 'surveys/answers_'.$this->surveyUID;
     98               
     99                $this->tempModel->load($answerPath . '/$answer_' . $respondentID);
     100               
     101                $this->tempModel->visualize();
     102       
     103                $querystring = '
     104                        PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
     105                        PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
     106                        SELECT  ?answered
     107                        WHERE   
     108                        {
     109                                _question       predicates:resource_type        resources:question ;
     110                                                        predicates:uid                          "'.$questionID.'"       ;
     111                                                        predicates:answered             ?answered       
     112                        }';
     113                       
     114                $result = $this->tempModel->sparqlQuery($querystring);
     115               
     116                $this->tempModel->close();             
     117
     118                $this->tempModel->visualize();
    44119                               
    45120                return $result;
  • Dev/trunk/classes/SurveyAnswerRDFWriter.php

    r31 r40  
    2020        }
    2121       
    22         public function setUserData($name)
     22        public function setRespondentData($name)
    2323        {                               
    2424                $resourceUser = new Resource(USER);
     
    2626                $LiteralUserName = new Literal($name);
    2727                $predicateName = new Resource(NAME);
    28                 $this->model->add(new Statement($resourceUser,$predicateUniqueID,$literalSurveyID));           
     28                $this->model->add(new Statement($resourceUser,$predicateUniqueID,$LiteralUserName));           
    2929               
    3030                $literalUserID = new Literal($this->userUID);
  • Dev/trunk/classes/SurveyDatabaseInterface.php

    r31 r40  
    11<?php
    2 // Survey class as intermediate for storing data from the site to the RDF database
     2// Survey database interface class as intermediate for storing data from the site to the RDF database
    33require 'rdfConstants.php';
    44
     
    1515 
    1616
    17     public function __construct($surveyID=null)
     17    public function __construct($surveyID)
    1818    {
    1919                if($surveyID == null)
     
    104104                        while (false !== ($file = readdir($handle))) {
    105105                                if(strstr($file, 'survey_'))
    106                                         $surveyIDs[] = substr($file,0,strlen($file)-4);
     106                                        $surveyIDs[] = substr($file,7,strlen($file)-11);
    107107                        }
    108108                }
     
    116116                return $surveys;
    117117        }
     118       
    118119}
    119120?>
  • Dev/trunk/classes/SurveyRDFReader.php

    r31 r40  
    8888                        {       
    8989                                _question       predicates:resource_type        resources:question ;
    90                                                         predicates:description  ?questionDescription           
     90                                                        predicates:description          ?questionDescription           
    9191                        }';
    9292                       
     
    156156                $factory = new ModelFactory();
    157157                $tempmodel= $factory->getDefaultModel();
    158                 $tempmodel->load('surveys/'.$surveyID.'.rdf');
     158                $tempmodel->load('surveys/survey_'.$surveyID.'.rdf');
    159159               
    160160                $querystring = '
  • Dev/trunk/classes/SurveyRDFWriter.php

    r31 r40  
    4242                $surveyDescription = new Literal($sDescription);
    4343                $this->model->add(new Statement($this->resourceSurvey,$predicateDescription,$surveyDescription));               
     44        }
     45       
     46        public function setUserData($userID)
     47        {                               
     48                $resourceUser = new Resource(USER . '/' . $userID);
     49                               
     50                $predicateCreator = new Resource(CREATOR);
     51                $this->model->add(new Statement($this->resourceSurvey,$predicateCreator,$resourceUser));
     52        }
     53       
     54        public function setApplicationData($applicationID)
     55        {
     56                $resourceApplication = new Resource(APPLICATION . '/' . $userID);
     57                               
     58                $predicatePartOf = new Resource(PART_OF);
     59                $this->model->add(new Statement($this->resourceSurvey,$predicatePartOf,$resourceApplication));
    4460        }
    4561       
  • Dev/trunk/rdfConstants.php

    r31 r40  
    1212define('ANSWER',SURVEYTOOL_RESOURCES_NAMESPACE . 'answer');
    1313define('USER',SURVEYTOOL_RESOURCES_NAMESPACE . 'user');
     14define('APPLICATION',SURVEYTOOL_RESOURCES_NAMESPACE . 'application');
    1415
    1516// Predicates used for RDF triples
     
    1920define('TITLE',SURVEYTOOL_PREDICATES_NAMESPACE . 'title');
    2021define('DESCRIPTION',SURVEYTOOL_PREDICATES_NAMESPACE . 'description');
     22define('PART_OF',SURVEYTOOL_PREDICATES_NAMESPACE . 'part_of');
     23define('STYLE',SURVEYTOOL_PREDICATES_NAMESPACE . 'style');
    2124define('RTYPE',SURVEYTOOL_PREDICATES_NAMESPACE . 'resource_type');
    2225define('QTYPE',SURVEYTOOL_PREDICATES_NAMESPACE . 'question_type');
    2326define('HAS_QUESTION',SURVEYTOOL_PREDICATES_NAMESPACE . 'has_question');
    2427define('HAS_ANSWER',SURVEYTOOL_PREDICATES_NAMESPACE . 'has_answer');
    25 define('NUMBER_OF_ANSWERS',SURVEYTOOL_PREDICATES_NAMESPACE . 'number_of_answers');
    26 define('SCALE',SURVEYTOOL_PREDICATES_NAMESPACE . 'scale');
    2728define('ANSWERED',SURVEYTOOL_PREDICATES_NAMESPACE . 'answered');
    2829define('RESPONDENT',SURVEYTOOL_PREDICATES_NAMESPACE . 'respondent');
Note: See TracChangeset for help on using the changeset viewer.