[131] | 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 | */ |
---|
[171] | 13 | class ApplicationConnector extends Connector{ |
---|
[149] | 14 | |
---|
[131] | 15 | /** |
---|
| 16 | * Constructor for ApplicationConnector. |
---|
| 17 | */ |
---|
[149] | 18 | public function __construct() |
---|
| 19 | { |
---|
[171] | 20 | $this->fileName = 'data/applications/applications.rdf'; |
---|
[131] | 21 | //Ensure the required folder for this connector exists |
---|
[149] | 22 | if (!is_dir('data/applications/')) |
---|
| 23 | mkdir('data/applications/'); |
---|
[131] | 24 | } |
---|
[149] | 25 | |
---|
[131] | 26 | /** |
---|
| 27 | * function get($arguments) |
---|
| 28 | * @param type $arguments : An array containing zero or more of the following keys: |
---|
[158] | 29 | * 'uid', 'title', 'description', 'style' |
---|
[131] | 30 | */ |
---|
| 31 | public function get($arguments) { |
---|
| 32 | $this->load(); |
---|
| 33 | |
---|
| 34 | //Create the querystring |
---|
| 35 | $querystring = ' |
---|
| 36 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> |
---|
| 37 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> |
---|
| 38 | SELECT ?uid, ?title, ?description, ?style |
---|
| 39 | WHERE |
---|
| 40 | { |
---|
| 41 | _application predicates:resource_type resources:application ; |
---|
| 42 | predicates:uid ?uid ; |
---|
| 43 | predicates:title ?title ; |
---|
| 44 | predicates:description ?description ; |
---|
[158] | 45 | predicates:style ?style ; ' |
---|
[171] | 46 | . $this->createArguments($arguments) . ' |
---|
[131] | 47 | }'; |
---|
| 48 | |
---|
| 49 | //Query the model |
---|
| 50 | $results = $this->model->sparqlQuery($querystring); |
---|
| 51 | $applications = array(); |
---|
[149] | 52 | if(!empty($results)) |
---|
| 53 | { |
---|
[131] | 54 | //Run over all results and create appropriate Application objets |
---|
[149] | 55 | foreach($results as $result) |
---|
| 56 | { |
---|
| 57 | $applications[] = new Application($result['?uid']->label, $result['?title']->label, $result['?description']->label, $result['?style']->label); |
---|
[131] | 58 | } |
---|
| 59 | } |
---|
| 60 | return $applications; |
---|
| 61 | } |
---|
[149] | 62 | |
---|
[131] | 63 | /** |
---|
| 64 | * function set() |
---|
| 65 | * Finds the required databaseentry matching the given object and removes |
---|
| 66 | * it from the rdf file. Then adds the new RDF entry matching the object. |
---|
| 67 | * @param type $rToolObject: The ResearchToolObject to be saved. |
---|
| 68 | */ |
---|
[149] | 69 | public function set($rToolObject) |
---|
| 70 | { |
---|
[131] | 71 | $this->load(); |
---|
[149] | 72 | $resourceApplication = new Resource(APPLICATION.'/'.$rToolObject->uid); |
---|
[131] | 73 | //Remove the old value stored with the given id |
---|
| 74 | $this->model->subtract($this->model->find($resourceApplication, null, null)); |
---|
| 75 | |
---|
| 76 | //Add the new statements to the model |
---|
| 77 | $resourceApplicationType = new Resource(APPLICATION); |
---|
| 78 | $predicateRType = new Resource(RTYPE); |
---|
[149] | 79 | $this->model->add(new Statement($resourceApplication,$predicateRType,$resourceApplicationType)); |
---|
| 80 | |
---|
[131] | 81 | $literalApplicationID = new Literal($rToolObject->uid); |
---|
| 82 | $predicateUniqueID = new Resource(UID); |
---|
[149] | 83 | $this->model->add(new Statement($resourceApplication,$predicateUniqueID,$literalApplicationID)); |
---|
[131] | 84 | |
---|
| 85 | $applicationTitle = new Literal($rToolObject->title); |
---|
[149] | 86 | $predicateTitle = new Resource(TITLE); |
---|
| 87 | $this->model->add(new Statement($resourceApplication,$predicateTitle,$applicationTitle)); |
---|
[131] | 88 | |
---|
| 89 | $applicationDescription = new Literal($rToolObject->description); |
---|
| 90 | $predicateDescription = new Resource(DESCRIPTION); |
---|
[149] | 91 | $this->model->add(new Statement($resourceApplication,$predicateDescription,$applicationDescription)); |
---|
[131] | 92 | |
---|
| 93 | $applicationStyle = new Literal($rToolObject->style); |
---|
| 94 | $predicateStyle = new Resource(STYLE); |
---|
[149] | 95 | $this->model->add(new Statement($resourceApplication,$predicateStyle,$applicationStyle)); |
---|
| 96 | |
---|
[158] | 97 | $this->save(); |
---|
[131] | 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | ?> |
---|