Ignore:
Timestamp:
11/07/11 16:55:36 (13 years ago)
Author:
jkraaijeveld
Message:

Added missing classes for the database connection

File:
1 edited

Legend:

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

    r144 r149  
    1111 * @author jkraaijeveld
    1212 */
    13 class ApplicationConnector implements IConnector {
    14 
     13class ApplicationConnector implements IConnector{
     14   
    1515    protected $model;
    1616    protected $fileName = 'data/applications/applications.rdf';
     
    1919     * Constructor for ApplicationConnector.
    2020     */
    21     public function __construct() {
     21    public function __construct()
     22    {
    2223        //Ensure the required folder for this connector exists
    23         if (!is_dir('data/applications/')) {
    24             mkdir('data/applications/', null, true);
    25         }
     24        if (!is_dir('data/applications/'))
     25            mkdir('data/applications/');       
    2626    }
    27 
     27   
    2828    /**
    2929     * function load()
     
    3333        //Get the Memory Model from the ModelFactory
    3434        $this->model = ModelFactory::getDefaultModel();
    35 
     35       
    3636        //Ensure the required file exists before loading
    37         if (file_exists($this->fileName))
     37        if(file_exists($this->fileName))
    3838            $this->model->load($this->fileName);
    3939    }
    40 
     40   
    4141    /**
    4242     * function save()
     
    4444     */
    4545    public function save() {
    46         $this->model->saveAs($this->fileName, 'rdf');
     46        $this->model->saveAs($this->fileName,'rdf');
    4747    }
    48 
     48   
    4949    /**
    5050     * function get($arguments)
     
    5858        $keys = array_keys($arguments);
    5959        //Set default values for arguments
    60         $uid = "?uid";
    61         $title = "?title";
    62         $description = "?description";
    63         $style = "?style";
     60        $uid = "?uid"; $title = "?title"; $description = "?description"; $style = "?style";
    6461        //Set the arguments if they are supplied
    65         if (in_array("uid", $keys))
    66             $uid = "\"" . $arguments["uid"] . "\"";
    67         if (in_array("title", $keys))
    68             $title = '\'' . $arguments["title"] . '\'';
    69         if (in_array("description", $keys))
    70             $description = "\"" . $arguments["description"] . "\"";
    71         if (in_array("style", $keys))
    72             $style = "\"" . $arguments["style"] . "\"";
     62        if(in_array("uid", $keys))
     63            $uid = "\"".$arguments["uid"]."\"";
     64        if(in_array("title", $keys))
     65            $title = '\''.$arguments["title"].'\'';
     66        if(in_array("description", $keys))
     67            $description = "\"".$arguments["description"]."\"";
     68        if(in_array("style", $keys))
     69            $style = "\"".$arguments["style"]."\"";   
    7370
    7471        //Create the querystring
     
    9390        $results = $this->model->sparqlQuery($querystring);
    9491        $applications = array();
    95         if (!empty($results)) {
     92        if(!empty($results))
     93        {
    9694            //Run over all results and create appropriate Application objets
    97             foreach ($results as $result) {
    98                 $applications[] = new Application($result['?uid']->label, $result['?title']->label, $result['?description']->label, $result['?style']->label);
     95            foreach($results as $result)
     96            {
     97                    $applications[] = new Application($result['?uid']->label, $result['?title']->label, $result['?description']->label, $result['?style']->label);
    9998            }
    10099        }
    101100        return $applications;
    102101    }
    103 
     102   
    104103    /**
    105104     * function set()
     
    108107     * @param type $rToolObject: The ResearchToolObject to be saved.
    109108     */
    110     public function set($rToolObject) {
     109    public function set($rToolObject)
     110    {
    111111        $this->load();
    112         $resourceApplication = new Resource(APPLICATION . '/' . $rToolObject->uid);
     112        $resourceApplication = new Resource(APPLICATION.'/'.$rToolObject->uid);
    113113        //Remove the old value stored with the given id
    114114        $this->model->subtract($this->model->find($resourceApplication, null, null));
     
    117117        $resourceApplicationType = new Resource(APPLICATION);
    118118        $predicateRType = new Resource(RTYPE);
    119         $this->model->add(new Statement($resourceApplication, $predicateRType, $resourceApplicationType));
    120 
     119        $this->model->add(new Statement($resourceApplication,$predicateRType,$resourceApplicationType));
     120               
    121121        $literalApplicationID = new Literal($rToolObject->uid);
    122122        $predicateUniqueID = new Resource(UID);
    123         $this->model->add(new Statement($resourceApplication, $predicateUniqueID, $literalApplicationID));
     123        $this->model->add(new Statement($resourceApplication,$predicateUniqueID,$literalApplicationID));
    124124
    125125        $applicationTitle = new Literal($rToolObject->title);
    126         $predicateTitle = new Resource(TITLE);
    127         $this->model->add(new Statement($resourceApplication, $predicateTitle, $applicationTitle));
     126        $predicateTitle = new Resource(TITLE); 
     127        $this->model->add(new Statement($resourceApplication,$predicateTitle,$applicationTitle));
    128128
    129129        $applicationDescription = new Literal($rToolObject->description);
    130130        $predicateDescription = new Resource(DESCRIPTION);
    131         $this->model->add(new Statement($resourceApplication, $predicateDescription, $applicationDescription));
     131        $this->model->add(new Statement($resourceApplication,$predicateDescription,$applicationDescription));
    132132
    133133        $applicationStyle = new Literal($rToolObject->style);
    134134        $predicateStyle = new Resource(STYLE);
    135         $this->model->add(new Statement($resourceApplication, $predicateStyle, $applicationStyle));
    136 
    137         $this->save();
     135        $this->model->add(new Statement($resourceApplication,$predicateStyle,$applicationStyle));
     136               
     137        $this->save();
    138138    }
    139 
    140139}
    141140
Note: See TracChangeset for help on using the changeset viewer.