Changeset 158 for Dev/trunk


Ignore:
Timestamp:
11/18/11 11:07:07 (13 years ago)
Author:
jkraaijeveld
Message:

Refactored queries / cleaned up some code.

Location:
Dev/trunk/classes
Files:
11 edited

Legend:

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

    r157 r158  
    4646   
    4747        /**
    48          * Function get()
    49          * Get the answers corresponding to the arguments
    50          * 'Question' argument is supposed to be the question ID
    51          * 'Values' has to be an array to make sure multiple answers can be selected.
     48         * function get()
     49         * @param type $arguments: An array having one or more of the following elements:
     50         * 'uid', 'question', 'values'.
    5251         */
    5352    public function get($arguments)
     
    9998        }
    10099        /**
    101          * Gets the values that belong to the answer
    102          * specified by the UID
     100         * function getValues()
     101         * @param type $uid : The uid of the Answer for which the values should be gotten.
    103102         */
    104103        private function getValues($uid)
     
    127126
    128127    /**
    129      * Saves the answer Object to the RDF file.
    130      * @param type $rToolObject
     128         * function set()
     129     * @param type $rToolObject : The ResearchToolObject to be saved.
    131130     */
    132131    public function set($rToolObject)
  • Dev/trunk/classes/AnswerSetConnector.php

    r149 r158  
    4444
    4545        /**
    46          * Get the AnswerSets corresponding to the arguments
    47          * Arguments can be one or more of the following:
    48          * uid, survey, respondent, answers
    49          * Where answers is an array of answer ids
     46         * function get()
     47         * @param type $arguments : An array having one ore more of the following elements:
     48         * 'uid', 'survey', 'respondent', 'answers'.
    5049         */
    5150        public function get($arguments)
     
    102101        /**
    103102         * function getAnswers()
    104          * Gets the answers corresponding to the given answerset uid
     103         * @param type $uid : the uid for which the answers should be retrieved.
    105104         */
    106105        private function getAnswers($uid)
     
    130129
    131130        /**
    132          * Save the given AnswerSet in the file.
    133          * @param type $rToolObject
     131         * function set()
     132         * @param type $rToolObject : The ResearchToolObject to be saved.
    134133         */
    135134        public function set($rToolObject)
  • Dev/trunk/classes/Application.php

    r131 r158  
    44 * Description of Application
    55 *
    6  * @author fpvanagthoven
     6 * @author jkraaijeveld
    77 */
    88class Application extends ResearchToolObject{
     
    1212    public $style;
    1313
     14        /**
     15         * Constructor for an Application object
     16         * @param type $uid : The uid of the Application object.
     17         * @param type $title: The title of the Application.
     18         * @param type $description: The description of the Application.
     19         * @param type $style: The style of the Application.
     20         */
    1421    public function __construct($uid = null, $title = null, $description = null, $style = null)
    1522    {
  • Dev/trunk/classes/ApplicationConnector.php

    r149 r158  
    4949    /**
    5050     * function get($arguments)
    51      * Gets the array of Application objects belonging to arguments supplied.
    5251     * @param type $arguments : An array containing zero or more of the following keys:
    53      *                          'uid', 'title', 'description', 'style'
     52     * 'uid', 'title', 'description', 'style'
    5453     */
    5554    public function get($arguments) {
     
    5857        $keys = array_keys($arguments);
    5958        //Set default values for arguments
    60         $uid = "?uid"; $title = "?title"; $description = "?description"; $style = "?style";
     59        $uid = ""; $title = ""; $description = ""; $style = "";
    6160        //Set the arguments if they are supplied
    6261        if(in_array("uid", $keys))
    63             $uid = "\"".$arguments["uid"]."\"";
     62            $uid = "predicates:uid \"".$arguments["uid"]."\"";
    6463        if(in_array("title", $keys))
    65             $title = '\''.$arguments["title"].'\'';
     64            $title = 'predicates:title \''.$arguments["title"].'\'';
    6665        if(in_array("description", $keys))
    67             $description = "\"".$arguments["description"]."\"";
     66            $description = "predicates:description \"".$arguments["description"]."\"";
    6867        if(in_array("style", $keys))
    69             $style = "\"".$arguments["style"]."\"";   
     68            $style = "predicates:style \"".$arguments["style"]."\"";   
    7069
    7170        //Create the querystring
     
    8079                                        predicates:title ?title ;
    8180                                        predicates:description ?description ;
    82                                         predicates:style ?style ;
    83                                         predicates:uid ' . $uid . '
    84                                         predicates:title ' . $title . '
    85                                         predicates:description ' . $description . '
    86                                         predicates:style ' . $style . '
     81                                        predicates:style ?style ; '
     82                    . $uid . $title . $description . $style . '
    8783            }';
    8884
     
    135131        $this->model->add(new Statement($resourceApplication,$predicateStyle,$applicationStyle));
    136132               
    137         $this->save();
     133                $this->save();
    138134    }
    139135}
  • Dev/trunk/classes/QuestionConnector.php

    r149 r158  
    5050    /**
    5151     * Get the questions corresponding to the arguments.
    52      * @param type $arguments
    53      * @return type Array
     52         * @param type $arguments : An array having one ore more of the following elements:
     53         * 'uid', 'title', 'type', 'description', 'category', 'has_answer'.
    5454     */
    5555    public function get($arguments)
     
    5959        $keys = array_keys($arguments);
    6060        //Set default values for arguments
    61         $uid = "?uid"; $title = "?title"; $type = "?type"; $description = "?description"; $category = "?category"; $has_answer = "";
     61        $uid = ""; $title = ""; $type = ""; $description = ""; $category = ""; $has_answer = "";
    6262        //Set the arguments if they are supplied
    6363        if(in_array("uid", $keys))
    64             $uid = '\''.$arguments["uid"].'\'';
     64            $uid = 'predicates:question_code \''.$arguments["uid"].'\'';
    6565        if(in_array("title", $keys))
    66             $title = '\''.$arguments["title"].'\'';
     66            $title = 'predicates:title \''.$arguments["title"].'\'';
    6767        if(in_array("type", $keys))
    68             $type = '\''.$arguments["type"].'\'';
     68            $type = 'predicates:type \''.$arguments["type"].'\'';
    6969        if(in_array("description", $keys))
    70             $description = "\"".$arguments["description"]."\"";
     70            $description = "predicates:description \"".$arguments["description"]."\"";
    7171        if(in_array("category", $keys))
    72                         $style = "\"".$arguments["category"]."\"";
     72                        $style = "predicates:category \"".$arguments["category"]."\"";
    7373                if(in_array("answers", $keys))
    7474                {
     
    9191                predicates:description ?description ;
    9292                predicates:question_category ?category ;
    93 
    94                 predicates:question_code ' . $uid . '
    95                 predicates:title ' . $title . '
    96                 predicates:question_type ' . $type . '
    97                 predicates:description ' . $description . '
    98                                 predicates:question_category ' . $category . '
    99                                 ' . $has_answer . '
     93                                '. $uid . $title . $type . $description . $category . $has_answer . '
    10094            }';
    10195        //Create the querystring
     
    117111    /**
    118112     * Gets the answers belonging to the given uid.
    119      * @param type $uid
    120      * @return type Array
     113     * @param type $uid : The uid of the Question in question (haha, pun).
    121114     */
    122115    private function getAnswers($uid)
     
    148141    /**
    149142     * Save the given ResearchTool object
    150      * @param type $rToolObject
     143     * @param type $rToolObject : The ResearchToolObject to be saved.
    151144     */
    152145    public function set($rToolObject)
  • Dev/trunk/classes/ResearchToolObject.php

    r131 r158  
    55 * @author jkraaijeveld
    66 */
    7 class ResearchToolObject {
     7abstract class ResearchToolObject {
    88    public $uid;
    99}
  • Dev/trunk/classes/Respondent.php

    r149 r158  
    66 * @author jkraaijeveld
    77 */
    8 class Respondent extends ResearchToolObject {
     8class Respondent extends User {
    99   public $name;
    1010   public $password;
     
    1212   /**
    1313    * Constructor for a Respondent object
    14     * @param type $uid
     14    * @param type $uid 
    1515    * @param type $name
    1616    * @param type $password
  • Dev/trunk/classes/RespondentConnector.php

    r149 r158  
    1212class RespondentConnector implements IConnector{
    1313   
    14     protected $model;
    1514    protected $fileName = 'data/users/respondents.rdf';
    1615   
     
    2019    public function __construct()
    2120    {
    22         //Ensure the required folder for this connector exists
    2321        if (!is_dir('data/users/'))
    2422            mkdir('data/users/');       
     
    3230        //Get the Memory Model from the ModelFactory
    3331        $this->model = ModelFactory::getDefaultModel();
    34        
    3532        //Ensure the required file exists before loading
    3633        if(file_exists($this->fileName))
     
    4744   
    4845    /**
    49      * function get($arguments)
     46     * function get()
    5047     * Gets the array of Respondent objects belonging to arguments supplied.
    5148     * @param type $arguments : An array containing zero or more of the following keys:
     
    5754        $keys = array_keys($arguments);
    5855        //Set default values for arguments
    59         $uid = "?uid"; $name = "?name"; $password = "?password";
     56        $uid = ""; $name = ""; $password = "";
    6057        //Set the arguments if they are supplied
    6158        if(in_array("uid", $keys))
    62             $uid = "\"".$arguments["uid"]."\"";
     59            $uid = "predicates:uid \"".$arguments["uid"]."\"";
    6360        if(in_array("name", $keys))
    64             $name = '\''.$arguments["name"].'\'';
     61            $name = 'predicates:name \''.$arguments["name"].'\'';
    6562        if(in_array("password", $keys))
    66             $password = "\"".$arguments["password"]."\"";
     63            $password = "predicates:password \"".$arguments["password"]."\"";
    6764       
    6865        //Create the querystring
     
    7774                                        predicates:name ?name ;
    7875                                        predicates:password ?password ;
    79                                 predicates:uid ' . $uid . '
    80                                         predicates:name ' . $name . '
    81                                         predicates:password ' . $password . '
     76                                        ' . $uid . $name . $password . '
    8277            }';
    8378        //Query the model
     
    9691   
    9792    /**
    98      * Save the given User object in the file.
    99      * @param type $rToolObject
     93         * function set()
     94     * @param type $rToolObject : The ResearchToolObject to be saved.
    10095     */
    10196    public function set($rToolObject)
  • Dev/trunk/classes/SessionConnector.php

    r157 r158  
    4747
    4848        /**
    49          * Get the Sessions corresponding to the arguments
    50          * @ param type $arguments
    51          * Arguments can be one or more of the following:
    52          * uid, title, datetime, applications, surveys, answersets
    53          * Where applications, surveys and answersets are arrays containing ids
     49         * function get()
     50         * @param type $arguments : An array containing one or more of the following elements:
     51         * 'uid', 'title', 'datetime', 'applications', 'surveys', 'answersets'
    5452         */
    5553        public function get($arguments)
     
    119117        }
    120118        /**
    121          * function getPipeline
    122          * Get the application and survey objects of the Session in order
     119         * function getPipeline()
     120         * param type $uid : The Session uid for which the pipeline should be retrieved.
    123121         */
    124122        private function getPipeline($uid)
     
    145143
    146144        /**
    147          * function getAnswerSets
    148          * Get the answersets belonging to the given session
     145         * function getAnswerSets()
     146         * @param type $uid : The Session uid for which the answerSets should be retrieved.
    149147         */
    150148        private function getAnswerSets($uid)
     
    163161
    164162        /**
    165          * Save the given Session object in the file.
    166          * @param type $rToolObjects
     163         * function set()
     164         * @param type $rToolObjects : The ResearchToolObject to be saved.
    167165         */
    168166        public function set($rToolObject)
     
    188186                $sessionTimestamp = new Literal($rToolObject->datetime->getTimestamp());
    189187        //      $sessionTimestamp = new Literal($rToolObject->datetime);    // Edit of above function, allows for creation of session, but still results in errors...
    190                 $predicateTimestamp = new Resource(DATETIME);
     188        $predicateTimestamp = new Resource(DATETIME);
    191189                $this->model->add(new Statement($resourceSession, $predicateTimestamp, $sessionTimestamp));
    192190
  • Dev/trunk/classes/SurveyConnector.php

    r149 r158  
    5555        $keys = array_keys($arguments);
    5656        //Set default values for arguments
    57         $uid = "?uid"; $title = "?title"; $description = "?description"; $creator = "?creator"; $questions = "";
     57        $uid = ""; $title = ""; $description = ""; $creator = ""; $questions = "";
    5858        if(in_array("uid", $keys))
    59             $uid = '\''.$arguments["uid"].'\'';
     59            $uid = 'predicates:uid \''.$arguments["uid"].'\'';
    6060        if(in_array("title", $keys))
    61             $title = '\''.$arguments["title"].'\'';
     61            $title = 'predicates:title \''.$arguments["title"].'\'';
    6262        if(in_array("description", $keys))
    63                         $description = "\"".$arguments["description"]."\"";
     63                        $description = "predicates:description \"".$arguments["description"]."\"";
    6464                if(in_array("creator", $keys))
    65                         $creator = "\"".$arguments["creator"]."\"";
     65                        $creator = "predicates:creator \"".$arguments["creator"]."\"";
    6666        if(in_array("questions", $keys))
    6767        {
     
    8383                predicates:uid ?uid ;
    8484                predicates:title ?title ;
    85                 predicates:description ?description ;
    86                 predicates:uid ' . $uid . '
    87                 predicates:title ' . $title . '
    88                                 predicates:description ' . $description . '
    89                                 predicates:creator ' . $creator . '
    90                 ' . $questions . '
     85                                predicates:description ?description ;
     86                                predicates:creator ?creator ;
     87                                ' . $uid . $title . $description . $creator . $questions . '
    9188            }';
    9289       
     
    111108    /**
    112109     * Gets the questions corresponding to the survey
    113      * @param type $uid
     110     * @param type $uid : The uid for which the questions should be gotten.
    114111     */
    115112    private function getQuestions($uid)
     
    143140    /**
    144141     * Saves the given Survey object.
    145      * @param type $rToolObject
     142     * @param type $rToolObject : The ResearchToolObject to be saved.
    146143     */
    147144    public function set($rToolObject)
  • Dev/trunk/classes/UserConnector.php

    r149 r158  
    3232        //Get the Memory Model from the ModelFactory
    3333        $this->model = ModelFactory::getDefaultModel();
    34        
    3534        //Ensure the required file exists before loading
    3635        if(file_exists($this->fileName))
     
    5756        $keys = array_keys($arguments);
    5857        //Set default values for arguments
    59         $uid = "?uid"; $name = "?name"; $password = "?password";
     58        $uid = ""; $name = ""; $password = "";
    6059        //Set the arguments if they are supplied
    6160        if(in_array("uid", $keys))
    62             $uid = "\"".$arguments["uid"]."\"";
     61            $uid = "predicates:uid \"".$arguments["uid"]."\"";
    6362        if(in_array("name", $keys))
    64             $name = '\''.$arguments["name"].'\'';
     63            $name = 'predicates:name \''.$arguments["name"].'\'';
    6564        if(in_array("password", $keys))
    66             $password = "\"".$arguments["password"]."\"";
     65            $password = "predicates:password \"".$arguments["password"]."\"";
    6766       
    6867        //Create the querystring
     
    7776                                        predicates:name ?name ;
    7877                                        predicates:password ?password ;
    79                                         predicates:uid ' . $uid . '
    80                                         predicates:name ' . $name . '
    81                                         predicates:password ' . $password . '
     78                                        ' . $uid . $name . $password . '
    8279            }';
    8380        //Query the model
Note: See TracChangeset for help on using the changeset viewer.