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

    r158 r171  
    1010 * @author jkraaijeveld
    1111 */
    12 class UserConnector implements IConnector{
    13    
    14     protected $model;
    15     protected $fileName = 'data/users/users.rdf';
     12class UserConnector extends Connector{
    1613   
    1714    /**
    18      * Constructor for RespondentConnector.
     15     * Constructor for UserConnector.
    1916     */
    2017    public function __construct()
    2118    {
     19                $this->fileName = 'data/users/users.rdf';
    2220        //Ensure the required folder for this connector exists
    2321        if (!is_dir('data/users/'))
    2422            mkdir('data/users/');       
    25     }
    26    
    27     /**
    28      * function load()
    29      * Loads the file into the standard MemModel.
    30      */
    31     public function load() {
    32         //Get the Memory Model from the ModelFactory
    33         $this->model = ModelFactory::getDefaultModel();
    34         //Ensure the required file exists before loading
    35         if(file_exists($this->fileName))
    36             $this->model->load($this->fileName);
    37     }
    38    
    39     /**
    40      * function save()
    41      * Saves the MemModel into the given file.
    42      */
    43     public function save() {
    44         $this->model->saveAs($this->fileName,'rdf');
    4523    }
    4624   
     
    5331    public function get($arguments) {
    5432        $this->load();
    55         //Determine which arguments are supplied
    56         $keys = array_keys($arguments);
    57         //Set default values for arguments
    58         $uid = ""; $name = ""; $password = "";
    59         //Set the arguments if they are supplied
    60         if(in_array("uid", $keys))
    61             $uid = "predicates:uid \"".$arguments["uid"]."\"";
    62         if(in_array("name", $keys))
    63             $name = 'predicates:name \''.$arguments["name"].'\'';
    64         if(in_array("password", $keys))
    65             $password = "predicates:password \"".$arguments["password"]."\"";
    66        
    6733        //Create the querystring
    6834        $querystring = '
     
    7642                                        predicates:name ?name ;
    7743                                        predicates:password ?password ;
    78                                         ' . $uid . $name . $password . '
     44                                        ' . $this->createArguments($arguments) . '
    7945            }';
    8046        //Query the model
    81         $results = $this->model->sparqlQuery($querystring);
     47                $results = $this->model->sparqlQuery($querystring);
    8248        $users = array();
    8349        if(!empty($results))
Note: See TracChangeset for help on using the changeset viewer.