Ignore:
Timestamp:
12/02/11 15:26:01 (13 years ago)
Author:
jkraaijeveld
Message:

Iteration of refactoring in the Connector code.

  • Abstracted load() and save() to a new superclass Connector. Every connector extends Connector.
  • Query arguments are now correctly created by Connector's createArguments() function, removing redundant if/if/if statements in every get() function.
  • Every sidefunction which previously used a seperate query to get data now uses the RAP findRegex method, should increase performance.
  • Question arguments have been changed slightly: 'uid' is now 'code' and 'answers' is now 'definedanswers' to avoid confusion.
File:
1 edited

Legend:

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

    r158 r171  
    1010 * @author jkraaijeveld
    1111 */
    12 class RespondentConnector implements IConnector{
    13    
    14     protected $fileName = 'data/users/respondents.rdf';
     12class RespondentConnector extends Connector{
    1513   
    1614    /**
     
    1917    public function __construct()
    2018    {
     19                $this->fileName = 'data/users/respondents.rdf';
    2120        if (!is_dir('data/users/'))
    2221            mkdir('data/users/');       
    23     }
    24    
    25     /**
    26      * function load()
    27      * Loads the file into the standard MemModel.
    28      */
    29     public function load() {
    30         //Get the Memory Model from the ModelFactory
    31         $this->model = ModelFactory::getDefaultModel();
    32         //Ensure the required file exists before loading
    33         if(file_exists($this->fileName))
    34             $this->model->load($this->fileName);
    35     }
    36    
    37     /**
    38      * function save()
    39      * Saves the MemModel into the given file.
    40      */
    41     public function save() {
    42         $this->model->saveAs($this->fileName,'rdf');
    4322    }
    4423   
     
    5130    public function get($arguments) {
    5231        $this->load();
    53         //Determine which arguments are supplied
    54         $keys = array_keys($arguments);
    55         //Set default values for arguments
    56         $uid = ""; $name = ""; $password = "";
    57         //Set the arguments if they are supplied
    58         if(in_array("uid", $keys))
    59             $uid = "predicates:uid \"".$arguments["uid"]."\"";
    60         if(in_array("name", $keys))
    61             $name = 'predicates:name \''.$arguments["name"].'\'';
    62         if(in_array("password", $keys))
    63             $password = "predicates:password \"".$arguments["password"]."\"";
    6432       
    6533        //Create the querystring
     
    7442                                        predicates:name ?name ;
    7543                                        predicates:password ?password ;
    76                                         ' . $uid . $name . $password . '
     44                                        ' . $this->createArguments($arguments) . '
    7745            }';
    7846        //Query the model
Note: See TracChangeset for help on using the changeset viewer.