Changeset 149 for Dev/trunk/classes/ApplicationConnector.php
- Timestamp:
- 11/07/11 16:55:36 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/classes/ApplicationConnector.php
r144 r149 11 11 * @author jkraaijeveld 12 12 */ 13 class ApplicationConnector implements IConnector 14 13 class ApplicationConnector implements IConnector{ 14 15 15 protected $model; 16 16 protected $fileName = 'data/applications/applications.rdf'; … … 19 19 * Constructor for ApplicationConnector. 20 20 */ 21 public function __construct() { 21 public function __construct() 22 { 22 23 //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/'); 26 26 } 27 27 28 28 /** 29 29 * function load() … … 33 33 //Get the Memory Model from the ModelFactory 34 34 $this->model = ModelFactory::getDefaultModel(); 35 35 36 36 //Ensure the required file exists before loading 37 if 37 if(file_exists($this->fileName)) 38 38 $this->model->load($this->fileName); 39 39 } 40 40 41 41 /** 42 42 * function save() … … 44 44 */ 45 45 public function save() { 46 $this->model->saveAs($this->fileName, 'rdf');46 $this->model->saveAs($this->fileName,'rdf'); 47 47 } 48 48 49 49 /** 50 50 * function get($arguments) … … 58 58 $keys = array_keys($arguments); 59 59 //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"; 64 61 //Set the arguments if they are supplied 65 if 66 $uid = "\"" . $arguments["uid"] ."\"";67 if 68 $title = '\'' . $arguments["title"] .'\'';69 if 70 $description = "\"" . $arguments["description"] ."\"";71 if 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"]."\""; 73 70 74 71 //Create the querystring … … 93 90 $results = $this->model->sparqlQuery($querystring); 94 91 $applications = array(); 95 if (!empty($results)) { 92 if(!empty($results)) 93 { 96 94 //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); 99 98 } 100 99 } 101 100 return $applications; 102 101 } 103 102 104 103 /** 105 104 * function set() … … 108 107 * @param type $rToolObject: The ResearchToolObject to be saved. 109 108 */ 110 public function set($rToolObject) { 109 public function set($rToolObject) 110 { 111 111 $this->load(); 112 $resourceApplication = new Resource(APPLICATION . '/' .$rToolObject->uid);112 $resourceApplication = new Resource(APPLICATION.'/'.$rToolObject->uid); 113 113 //Remove the old value stored with the given id 114 114 $this->model->subtract($this->model->find($resourceApplication, null, null)); … … 117 117 $resourceApplicationType = new Resource(APPLICATION); 118 118 $predicateRType = new Resource(RTYPE); 119 $this->model->add(new Statement($resourceApplication, $predicateRType,$resourceApplicationType));120 119 $this->model->add(new Statement($resourceApplication,$predicateRType,$resourceApplicationType)); 120 121 121 $literalApplicationID = new Literal($rToolObject->uid); 122 122 $predicateUniqueID = new Resource(UID); 123 $this->model->add(new Statement($resourceApplication, $predicateUniqueID,$literalApplicationID));123 $this->model->add(new Statement($resourceApplication,$predicateUniqueID,$literalApplicationID)); 124 124 125 125 $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)); 128 128 129 129 $applicationDescription = new Literal($rToolObject->description); 130 130 $predicateDescription = new Resource(DESCRIPTION); 131 $this->model->add(new Statement($resourceApplication, $predicateDescription,$applicationDescription));131 $this->model->add(new Statement($resourceApplication,$predicateDescription,$applicationDescription)); 132 132 133 133 $applicationStyle = new Literal($rToolObject->style); 134 134 $predicateStyle = new Resource(STYLE); 135 $this->model->add(new Statement($resourceApplication, $predicateStyle,$applicationStyle));136 137 135 $this->model->add(new Statement($resourceApplication,$predicateStyle,$applicationStyle)); 136 137 $this->save(); 138 138 } 139 140 139 } 141 140
Note: See TracChangeset
for help on using the changeset viewer.