Changeset 171


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.
Location:
Dev/trunk/classes
Files:
1 added
9 edited

Legend:

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

    r158 r171  
    1010 * @author jkraaijeveld
    1111 */
    12 class AnswerConnector implements IConnector{
    13     protected $model;
    14         protected $fileName = 'data/answers/answers.rdf';
     12class AnswerConnector extends Connector{
    1513        protected $db;
    1614   
     
    2119        //Ensure the required folder for this connector exists
    2220        if (!is_dir('data/answers/'))
    23             mkdir('data/answers/');
    24     }
    25    
    26     /**
    27      * function load()
    28      * Loads the file into the standard MemModel.
    29      */
    30     public function load() {
    31         //Get the Memory Model from the ModelFactory
    32         $this->model = ModelFactory::getDefaultModel();
    33        
    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');
     21                        mkdir('data/answers/');
     22                $this->fileName = 'data/answers/answers.rdf';
    4523    }
    4624   
     
    5331        {
    5432                $this->load();
    55                 $keys = array_keys($arguments);
    56                 $uid = ""; $question = ""; $value = "";
    57                 if(in_array("uid", $keys))
    58                         $uid = 'predicates:uid \''.$arguments["uid"].'\'';
    59                 if(in_array("question", $keys))
    60                         $question = 'predicates:question_code \''.$arguments["question"].'\'';
    61                 if(in_array("values", $keys))
    62                 {
    63                         foreach ($arguments["values"] as $val)
    64                         {
    65                                 $value = $value . 'predicates:answered \'' . $val . '\' ';
    66                         }
    67                 }
    6833                //Create the querystring
    6934                $querystring = '
     
    7742                                predicates:uid ?uid ;
    7843                                predicates:question_code ?question_code ;
    79                                 ' . $uid . $question . $value . '
     44                                ' . $this->createArguments($arguments) . '
    8045                        }';
    8146
     
    8954                        foreach($results as $result)
    9055                        {
    91                                 $values = $this->getValues($result['?uid']->label);
    92                                 $questionResult = $this->db->get("question", array("uid" => $result['?question_code']->label));
    93                                 $answers[] = new Answer($result['?uid']->label, $questionResult[0], $values);
     56                                $questionResult = $this->db->get("question", array("code" => $result['?question_code']->label));
     57                                $answers[] = new Answer($result['?uid']->label, $questionResult[0], $this->getValues($result['?uid']->label));
    9458                        }
    9559                }
    9660                return $answers;
     61        }
    9762
    98         }
    9963        /**
    10064         * function getValues()
     
    10367        private function getValues($uid)
    10468        {
    105                 $querystring = '
    106                         PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
    107                         PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
    108                         SELECT DISTINCT ?answered
    109                         WHERE
    110                         {
    111                                 _answer predicates:resource_type resources:answer ;
    112                                 predicates:answered ?answered ;
    113                                 predicates:uid \''. $uid . '\'
    114                 }';
    115                 $values = $this->model->sparqlQuery($querystring);
    116                 $returnArray = array();
    117                 if(!empty($values))
     69                $result = $this->model->findRegex("[(".$uid.")]", "[(answered)]", null);
     70                $iterator = $result->getStatementIterator();
     71                $values = array();
     72                while($iterator->hasNext())
    11873                {
    119                         foreach($values as $value)
    120                         {
    121                                 $returnArray[] = $value['?answered']->label;
    122                         }
     74                        $element = $iterator->next();
     75                        $values[] = $element->getLabelObject();
    12376                }
    124                 return $returnArray;
     77                return $values;
    12578        }
    12679
  • Dev/trunk/classes/AnswerSetConnector.php

    r158 r171  
    66 * @author jkraaijeveld
    77 */
    8 class AnswerSetConnector implements IConnector{
    9     protected $model;
    10     protected $fileName = 'data/answers/answersets.rdf';
     8class AnswerSetConnector extends Connector{
    119    protected $db;
    1210
     
    1614        public function __construct()
    1715        {
     16                $this->fileName = 'data/answers/answersets.rdf';
    1817                //Ensure the required folder for this connector exists
    1918                if(!is_dir('data/answers'))
    2019                        mkdir('data/answers');
    21         }
    22 
    23         /**
    24          * function load()
    25          * Loads the file into the standard MemModel
    26          */
    27         public function load()
    28         {
    29             //Get the Memory Model from the ModelFactory
    30         $this->model = ModelFactory::getDefaultModel();
    31        
    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');
    4320        }
    4421
     
    5128        {
    5229                $this->load();
    53                
    54                 $keys = array_keys($arguments);
    55                 $uid = ""; $survey = ""; $respondent = ""; $answers = "";
    56                 if(in_array("uid", $keys))
    57                         $uid = 'predicates:uid \''.$arguments["uid"].'\' ';
    58                 if(in_array("survey", $keys))
    59                         $survey = 'predicates:for_survey \''.$arguments["survey"].'\' ';
    60                 if(in_array("respondent", $keys))
    61                         $respondent = 'predicates:by_respondent \''.$arguments["respondent"].'\' ';
    62                 if(in_array("answers", $keys))
    63                 {
    64                         foreach ($arguments["answers"] as $answer)
    65                         {
    66                                 $answers = $answers . 'predicates:given_answer \'' . $answer . '\' ';
    67                         }
    68                 }
    6930
    7031                //Build the query string
     
    7940                                predicates:for_survey ?for_survey ;
    8041                                predicates:by_respondent ?by_respondent ;
    81                                 ' . $uid . $survey . $respondent . $answers . '
     42                                ' . $this->createArguments($arguments) . '
    8243                        }';
    83 
    8444                //Query the model
    8545                $results = $this->model->sparqlQuery($querystring);
     
    10565        private function getAnswers($uid)
    10666        {
    107                 $querystring = '
    108                         PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE .'>
    109                         PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE .'>
    110                         SELECT DISTINCT ?given_answer
    111                         WHERE
    112                         {
    113                                 _answerset predicates:resource_type resources:answerset ;
    114                                 predicates:given_answer ?given_answer ;
    115                                 predicates:uid \'' . $uid . '\'
    116                         }';
    117                 $answers = $this->model->sparqlQuery($querystring);
    118                 $returnArray = array();
    119                 if(!empty($answers))
     67                $result = $this->model->findRegex("[(".$uid.")]", "[(given_answer)]", null);
     68                $iterator = $result->getStatementIterator();
     69                $answers = array();
     70                while($iterator->hasNext())
    12071                {
    121                         foreach($answers as $answer)
    122                         {
    123                                 $answerR = $this->db->get("answer", array("uid" => $answer["?given_answer"]->label));
    124                                 $returnArray[] = $answerR[0];
    125                         }
     72                        $element = $iterator->next();
     73                        $answersR = $this->db->get("answer", array("uid" => $element->getLabelObject()));
     74                        $answers[] = $answersR[0];
    12675                }
    127                 return $returnArray;
     76                return $answers;
    12877        }
    12978
  • 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
  • Dev/trunk/classes/QuestionConnector.php

    r158 r171  
    1212 * @author jkraaijeveld
    1313 */
    14 class QuestionConnector implements IConnector {
     14class QuestionConnector extends Connector {
    1515   
    16     protected $model;
    17     protected $fileName = 'data/questions/questions.rdf';
    1816   
    1917    /**
     
    2220    public function __construct()
    2321    {
     22                $this->fileName = 'data/questions/questions.rdf';
    2423        //Ensure the required folder for this connector exists
    2524        if (!is_dir('data/questions/'))
     
    2827   
    2928    /**
    30      * function load()
    31      * Loads the file into the standard MemModel.
    32      */
    33     public function load() {
    34         //Get the Memory Model from the ModelFactory
    35         $this->model = ModelFactory::getDefaultModel();
    36        
    37         //Ensure the required file exists before loading
    38         if(file_exists($this->fileName))
    39             $this->model->load($this->fileName);
    40     }
    41    
    42     /**
    43      * function save()
    44      * Saves the MemModel into the given file.
    45      */
    46     public function save() {
    47         $this->model->saveAs($this->fileName,'rdf');
    48     }
    49    
    50     /**
    5129     * Get the questions corresponding to the arguments.
    5230         * @param type $arguments : An array having one ore more of the following elements:
    53          * 'uid', 'title', 'type', 'description', 'category', 'has_answer'.
     31         * 'code', 'title', 'type', 'description', 'category', 'definedanswers'.
    5432     */
    5533    public function get($arguments)
    5634    {
    5735        $this->load();
    58        
    59         $keys = array_keys($arguments);
    60         //Set default values for arguments
    61         $uid = ""; $title = ""; $type = ""; $description = ""; $category = ""; $has_answer = "";
    62         //Set the arguments if they are supplied
    63         if(in_array("uid", $keys))
    64             $uid = 'predicates:question_code \''.$arguments["uid"].'\'';
    65         if(in_array("title", $keys))
    66             $title = 'predicates:title \''.$arguments["title"].'\'';
    67         if(in_array("type", $keys))
    68             $type = 'predicates:type \''.$arguments["type"].'\'';
    69         if(in_array("description", $keys))
    70             $description = "predicates:description \"".$arguments["description"]."\"";
    71         if(in_array("category", $keys))
    72                         $style = "predicates:category \"".$arguments["category"]."\"";
    73                 if(in_array("answers", $keys))
    74                 {
    75                         foreach($arguments["answers"] as $answer)
    76                         {
    77                                 $has_answer = $has_answer . 'predicates:has_answer \'' . $answer . '\' ';
    78                         }
    79                 }
    8036           
    8137        $querystring = '
     
    9147                predicates:description ?description ;
    9248                predicates:question_category ?category ;
    93                                 '. $uid . $title . $type . $description . $category . $has_answer . '
    94             }';
     49                                '. $this->createArguments($arguments) . '
     50        }';
     51
     52               
    9553        //Create the querystring
    9654        $results = $this->model->sparqlQuery($querystring);
     
    11573    private function getAnswers($uid)
    11674    {
    117         $querystring = '
    118             PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
    119             PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
    120             SELECT DISTINCT ?has_answer
    121             WHERE
    122             {
    123                  _question      predicates:resource_type        resources:question ;
    124                 predicates:has_answer ?has_answer ;
    125                 predicates:question_code \'' . $uid . '\'
    126             }';
     75                $result = $this->model->findRegex("[(".$uid.")]", "[(has_answer)]", null);
     76                $iterator = $result->getStatementIterator();
     77                $answers = array();
     78                while($iterator->hasNext())
     79                {
     80                        $element = $iterator->next();
     81                        $answers[] = $element->getLabelObject();
     82                }
     83                return $answers;
    12784
    128         $answers = $this->model->sparqlQuery($querystring);
    129         $returnArray = array();
    130         if(!empty($answers))
    131         {
    132             foreach($answers as $answer)
    133             {
    134                 $returnArray[] = $answer['?has_answer']->label;
    135             }
    136         }
    137         return $returnArray;
    138     }
    139 
     85        }
    14086   
    14187    /**
  • 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
  • Dev/trunk/classes/Session.php

    r170 r171  
    4848                        mkdir($location);
    4949                }
     50                //Create the filename, open the file at the given location
    5051                $fileName = $this->datetime->format("d-m-Y") . "_" . $this->title . ".txt";
    5152
  • Dev/trunk/classes/SessionConnector.php

    r170 r171  
    1010 * @author jkraaijeveld
    1111 */
    12 class SessionConnector implements IConnector
     12class SessionConnector extends Connector 
    1313{
    14         protected $model;
    15         protected $fileName = 'data/sessions/sessions.rdf';
    1614        protected $db;
    1715
     
    2119        public function __construct()
    2220        {
     21                $this->fileName = 'data/sessions/sessions.rdf';
    2322                //Ensure the required folder for this connector exists
    2423                if(!is_dir('data/sessions'))
    2524                        mkdir('data/sessions');
    26         }
    27 
    28         /**
    29          * function load()
    30          * Loads the file into the standard MemModel
    31          */
    32         public function load()
    33         {
    34                 $this->model = ModelFactory::getDefaultModel();
    35                 if(file_exists($this->fileName))
    36                         $this->model->load($this->fileName);
    37         }
    38 
    39         /**
    40          * fucntion save()
    41          * Saves the MemModel into the given file.
    42          */
    43         public function save()
    44         {
    45                 $this->model->saveAs($this->fileName,'rdf');
    4625        }
    4726
     
    5433        {
    5534                $this->load();
    56 
    57                 $keys = array_keys($arguments);
    58                 $uid = ""; $title = ""; $creator = ""; $datetime = ""; $applications = ""; $surveys = ""; $answersets = "";
    59                 if(in_array("uid", $keys))
    60                         $uid = 'predicates:uid \''.$arguments["uid"].'\' ';
    61                 if(in_array("title", $keys))
    62                         $title = 'predicates:title \''.$arguments["title"].'\' ';
    63                 if(in_array("creator", $keys))
    64                         $creator = 'predicates:creator \''.$arguments["creator"].'\' ';
    65                 if(in_array("datetime", $keys))
    66                         $datetime = 'predicates:datetime \''.$arguments["datetime"].'\' ';
    67                 if(in_array("applications", $keys))
    68                 {
    69                         foreach($arguments["applications"] as $application)
    70                         {
    71                                 $applications = $applications . 'predicates:has_application \'' . $application . '\' ';
    72                         }
    73                 }
    74                 if(in_array("surveys", $keys))
    75                 {
    76                         foreach($arguments["surveys"] as $survey)
    77                         {
    78                                 $surveys = $surveys . 'predicates:has_survey \'' . $survey . '\' ';
    79                         }
    80                 }
    81                 if(in_array("answersets", $keys))
    82                 {
    83                         foreach($arguments["answersets"] as $answerset)
    84                         {
    85                                 $answersets = $answersets . 'predicates:has_answerset \'' . $answerset . '\' ';
    86                         }
    87                 }
    8835       
    8936                //Build the query string
     
    9946                                predicates:creator ?creator ;
    10047                                predicates:datetime ?datetime ;
    101                                 ' . $uid . $title . $creator . $datetime . $applications . $surveys . $answersets . '
     48                                ' . $this->createArguments($arguments) . '
    10249                        }';
     50                echo $querystring;
    10351                //Query the model
    10452                $results = $this->model->sparqlQuery($querystring);
  • Dev/trunk/classes/SurveyConnector.php

    r158 r171  
    66 * @author jkraaijeveld
    77 */
    8 class SurveyConnector implements IConnector{
    9     protected $model;
    10     protected $fileName = 'data/surveys/surveys.rdf';
     8class SurveyConnector extends Connector{
    119    protected $db;
    1210
     
    1614    public function __construct()
    1715    {
     16                $this->fileName = 'data/surveys/surveys.rdf';
    1817        //Ensure the required folder for this connector exists
    1918        if (!is_dir('data/surveys/'))
    2019            mkdir('data/surveys/');     
    21     }
    22    
    23     /**
    24      * function load()
    25      * Loads the file into the standard MemModel.
    26      */
    27     public function load() {
    28         //Get the Memory Model from the ModelFactory
    29         $this->model = ModelFactory::getDefaultModel();
    30        
    31         //Ensure the required file exists before loading
    32         if(file_exists($this->fileName))
    33             $this->model->load($this->fileName);
    34     }
    35    
    36     /**
    37      * function save()
    38      * Saves the MemModel into the given file.
    39      */
    40     public function save() {
    41         $this->model->saveAs($this->fileName,'rdf');
    4220    }
    4321   
     
    5331        $this->load();
    5432       
    55         $keys = array_keys($arguments);
    56         //Set default values for arguments
    57         $uid = ""; $title = ""; $description = ""; $creator = ""; $questions = "";
    58         if(in_array("uid", $keys))
    59             $uid = 'predicates:uid \''.$arguments["uid"].'\'';
    60         if(in_array("title", $keys))
    61             $title = 'predicates:title \''.$arguments["title"].'\'';
    62         if(in_array("description", $keys))
    63                         $description = "predicates:description \"".$arguments["description"]."\"";
    64                 if(in_array("creator", $keys))
    65                         $creator = "predicates:creator \"".$arguments["creator"]."\"";
    66         if(in_array("questions", $keys))
    67         {
    68             //Append the questions string to filter for questions properly
    69             foreach ($arguments["questions"] as $questionUid)
    70             {
    71                 $questions = $questions . 'predicates:has_question \'' . $questionUid . '\' ';
    72             }
    73         }
    74        
    7533        //Build the query string
    7634        $querystring = '
     
    8543                                predicates:description ?description ;
    8644                                predicates:creator ?creator ;
    87                                 ' . $uid . $title . $description . $creator . $questions . '
     45                                ' . $this->createArguments($arguments) . '
    8846            }';
    8947       
     
    11270    private function getQuestions($uid)
    11371    {
    114         //Create the querystring. Note that the UID is the only argument in this case.
    115         $querystring = '
    116             PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
    117             PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
    118             SELECT DISTINCT ?has_question
    119             WHERE
    120             {
    121                  _survey        predicates:resource_type        resources:survey ;
    122                 predicates:has_question ?has_question ;
    123                 predicates:uid \'' . $uid . '\'
    124             }';
    125 
    126         $results = $this->model->sparqlQuery($querystring);
    127         $questions = array();
    128         //For every question id, get the corresponding question
    129         if(!empty($results))
    130         {
    131             foreach($results as $questionId)
    132             {
    133                 $resultQ = $this->db->get("question", array("uid" => $questionId['?has_question']->label));
    134                 $questions[] = $resultQ[0];
    135             }
    136         }
    137         return $questions;
     72                $result = $this->model->findRegex("[(".$uid.")]", "[(has_question)]", null);
     73                $iterator = $result->getStatementIterator();
     74                $questions = array();
     75                while($iterator->hasNext())
     76                {
     77                        $element = $iterator->next();
     78                        $result = $this->db->get("question", array("code" => $element->getLabelObject()));
     79                        $questions[] = $result[0];
     80                }
     81                return $questions;
    13882    }
    13983   
  • 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.