Ignore:
Timestamp:
10/17/11 17:21:45 (14 years ago)
Author:
jkraaijeveld
Message:

Finished ApplicationConnector?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/jos-branch/classes/ApplicationConnector.php

    r123 r128  
    5151     * Gets the array of Application objects belonging to arguments supplied.
    5252     * @param type $arguments : An array containing zero or more of the following keys:
    53      *                          'id', 'title', 'description', 'style'
     53     *                          'uid', 'title', 'description', 'style'
    5454     */
    5555    public function get($arguments) {
     
    5858        $keys = array_keys($arguments);
    5959        //Set default values for arguments
    60         $id = "?uid"; $title = "?title"; $description = "?description"; $style = "?style";
     60        $uid = "?uid"; $title = "?title"; $description = "?description"; $style = "?style";
    6161        //Set the arguments if they are supplied
    62         if(in_array("id", $keys))
    63             $id = "\"".$arguments["id"]."\"";
     62        if(in_array("uid", $keys))
     63            $uid = "\"".$arguments["id"]."\"";
    6464        if(in_array("title", $keys))
    6565            $title = '\''.$arguments["title"].'\'';
     
    7777            {
    7878                    _application        predicates:resource_type        resources:application ;
    79                                         predicates:uid                  '. $id . ';
    80                                         predicates:title                '. $title . ';
    81                                         predicates:description          '. $description . ';
    82                                         predicates:style                '. $style .'
     79                                        predicates:uid ?uid ;
     80                                        predicates:title ?title ;
     81                                        predicates:description ?description ;
     82                                        predicates:style ?style ;
     83                                        predicates:uid ' . $uid . '
     84                                        predicates:title ' . $title . '
     85                                        predicates:description ' . $description . '
     86                                        predicates:style ' . $style . '
    8387            }';
     88
    8489        //Query the model
    85         echo $querystring;
    8690        $results = $this->model->sparqlQuery($querystring);
    87         $applications = array();
    88         echo count($results);
    89         //Run over all results and create appropriate Application objets
    90         foreach($results as $result)
    91         {
    92            
    93             $applications[] = new Application($result['?uid']->label, $result['?title']->label, $result['?description']->label, $result['?style']->label);
    94         }
    95         //Return the list of application objects
    96         return $applications;
     91                if(!empty($results))
     92                        {
     93                        $applications = array();
     94                        //Run over all results and create appropriate Application objets
     95                        foreach($results as $result)
     96                        {
     97                                $applications[] = new Application($result['?uid']->label, $result['?title']->label, $result['?description']->label, $result['?style']->label);
     98                        }
     99                        //Return the list of application objects
     100                        return $applications;
     101                }
     102                else
     103                {
     104                        return array();
     105                }
    97106    }
    98107   
    99108    /**
    100109     * function set()
    101      * Finds the required databaseentry matching the given objects and removes
    102      * it from the rdf file.
    103      * @param type $rToolObject
     110     * Finds the required databaseentry matching the given object and removes
     111     * it from the rdf file. Then adds the new RDF entry matching the object.
     112     * @param type $rToolObject: The ResearchToolObject to be saved.
    104113     */
    105114    public function set($rToolObject)
    106115    {
    107         //TODO
     116        $resourceApplication = new Resource(APPLICATION.'/'.$rToolObject->uid);
     117                //Remove the old value stored with the given id
     118                $this->model->subtract($this->model->find($resourceApplication, null, null));
     119               
     120                //Add the new statements to the model
     121        $resourceApplicationType = new Resource(APPLICATION);
     122        $predicateRType = new Resource(RTYPE);
     123        $this->model->add(new Statement($resourceApplication,$predicateRType,$resourceApplicationType));
     124               
     125        $literalApplicationID = new Literal($rToolObject->uid);
     126        $predicateUniqueID = new Resource(UID);
     127        $this->model->add(new Statement($resourceApplication,$predicateUniqueID,$literalApplicationID));
     128
     129        $applicationTitle = new Literal($rToolObject->title);
     130        $predicateTitle = new Resource(TITLE); 
     131        $this->model->add(new Statement($resourceApplication,$predicateTitle,$applicationTitle));
     132
     133        $applicationDescription = new Literal($rToolObject->description);
     134        $predicateDescription = new Resource(DESCRIPTION);
     135        $this->model->add(new Statement($resourceApplication,$predicateDescription,$applicationDescription));
     136
     137        $applicationStyle = new Literal($rToolObject->style);
     138        $predicateStyle = new Resource(STYLE);
     139        $this->model->add(new Statement($resourceApplication,$predicateStyle,$applicationStyle));
     140               
     141                $this->save();
    108142    }
    109143}
Note: See TracChangeset for help on using the changeset viewer.