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

    r158 r171  
    1111 * @author jkraaijeveld
    1212 */
    13 class ApplicationConnector implements IConnector{
     13class ApplicationConnector extends Connector{
    1414   
    15     protected $model;
    16     protected $fileName = 'data/applications/applications.rdf';
    17 
    1815    /**
    1916     * Constructor for ApplicationConnector.
     
    2118    public function __construct()
    2219    {
     20                $this->fileName = 'data/applications/applications.rdf';
    2321        //Ensure the required folder for this connector exists
    2422        if (!is_dir('data/applications/'))
    2523            mkdir('data/applications/');       
    26     }
    27    
    28     /**
    29      * function load()
    30      * Loads the file into the standard MemModel.
    31      */
    32     public function load() {
    33         //Get the Memory Model from the ModelFactory
    34         $this->model = ModelFactory::getDefaultModel();
    35        
    36         //Ensure the required file exists before loading
    37         if(file_exists($this->fileName))
    38             $this->model->load($this->fileName);
    39     }
    40    
    41     /**
    42      * function save()
    43      * Saves the MemModel into the given file.
    44      */
    45     public function save() {
    46         $this->model->saveAs($this->fileName,'rdf');
    4724    }
    4825   
     
    5431    public function get($arguments) {
    5532        $this->load();
    56         //Determine which arguments are supplied
    57         $keys = array_keys($arguments);
    58         //Set default values for arguments
    59         $uid = ""; $title = ""; $description = ""; $style = "";
    60         //Set the arguments if they are supplied
    61         if(in_array("uid", $keys))
    62             $uid = "predicates:uid \"".$arguments["uid"]."\"";
    63         if(in_array("title", $keys))
    64             $title = 'predicates:title \''.$arguments["title"].'\'';
    65         if(in_array("description", $keys))
    66             $description = "predicates:description \"".$arguments["description"]."\"";
    67         if(in_array("style", $keys))
    68             $style = "predicates:style \"".$arguments["style"]."\"";   
    6933
    7034        //Create the querystring
     
    8044                                        predicates:description ?description ;
    8145                                        predicates:style ?style ; '
    82                     . $uid . $title . $description . $style . '
     46                    . $this->createArguments($arguments) . '
    8347            }';
    8448
Note: See TracChangeset for help on using the changeset viewer.