[123] | 1 | <?php |
---|
| 2 | |
---|
| 3 | // Survey database interface class as intermediate for storing data from the site to the RDF database |
---|
| 4 | require_once 'rdfConstants.php'; |
---|
| 5 | // Include RAP Library to write RDF files |
---|
| 6 | include(RDFAPI_INCLUDE_DIR . "RDFAPI.php"); |
---|
| 7 | |
---|
| 8 | /** |
---|
| 9 | * Description of ApplicationConnector |
---|
| 10 | * |
---|
| 11 | * @author jkraaijeveld |
---|
| 12 | */ |
---|
| 13 | class ApplicationConnector implements IConnector{ |
---|
| 14 | |
---|
| 15 | protected $model; |
---|
| 16 | protected $fileName = 'data/applications/applications.rdf'; |
---|
| 17 | |
---|
| 18 | /** |
---|
| 19 | * Constructor for ApplicationConnector. |
---|
| 20 | */ |
---|
| 21 | public function __construct() |
---|
| 22 | { |
---|
| 23 | //Ensure the required folder for this connector exists |
---|
| 24 | if (!is_dir('data/applications/')) |
---|
| 25 | 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'); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | * function get($arguments) |
---|
| 51 | * Gets the array of Application objects belonging to arguments supplied. |
---|
| 52 | * @param type $arguments : An array containing zero or more of the following keys: |
---|
| 53 | * 'id', 'title', 'description', 'style' |
---|
| 54 | */ |
---|
| 55 | public function get($arguments) { |
---|
| 56 | $this->load(); |
---|
| 57 | //Determine which arguments are supplied |
---|
| 58 | $keys = array_keys($arguments); |
---|
| 59 | //Set default values for arguments |
---|
| 60 | $id = "?uid"; $title = "?title"; $description = "?description"; $style = "?style"; |
---|
| 61 | //Set the arguments if they are supplied |
---|
| 62 | if(in_array("id", $keys)) |
---|
| 63 | $id = "\"".$arguments["id"]."\""; |
---|
| 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"]."\""; |
---|
| 70 | |
---|
| 71 | //Create the querystring |
---|
| 72 | $querystring = ' |
---|
| 73 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> |
---|
| 74 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> |
---|
| 75 | SELECT ?uid, ?title, ?description, ?style |
---|
| 76 | WHERE |
---|
| 77 | { |
---|
| 78 | _application predicates:resource_type resources:application ; |
---|
| 79 | predicates:uid '. $id . '; |
---|
| 80 | predicates:title '. $title . '; |
---|
| 81 | predicates:description '. $description . '; |
---|
| 82 | predicates:style '. $style .' |
---|
| 83 | }'; |
---|
| 84 | //Query the model |
---|
| 85 | echo $querystring; |
---|
| 86 | $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; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /** |
---|
| 100 | * function set() |
---|
| 101 | * Finds the required databaseentry matching the given objects and removes |
---|
| 102 | * it from the rdf file. |
---|
| 103 | * @param type $rToolObject |
---|
| 104 | */ |
---|
| 105 | public function set($rToolObject) |
---|
| 106 | { |
---|
| 107 | //TODO |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | ?> |
---|