[131] | 1 | <?php |
---|
| 2 | // Survey database interface class as intermediate for storing data from the site to the RDF database |
---|
| 3 | require_once 'rdfConstants.php'; |
---|
| 4 | // Include RAP Library to write RDF files |
---|
| 5 | include(RDFAPI_INCLUDE_DIR . "RDFAPI.php"); |
---|
| 6 | |
---|
| 7 | /** |
---|
| 8 | * Description of UserConnector |
---|
| 9 | * |
---|
| 10 | * @author jkraaijeveld |
---|
| 11 | */ |
---|
[171] | 12 | class UserConnector extends Connector{ |
---|
[131] | 13 | |
---|
| 14 | /** |
---|
[171] | 15 | * Constructor for UserConnector. |
---|
[131] | 16 | */ |
---|
| 17 | public function __construct() |
---|
| 18 | { |
---|
[171] | 19 | $this->fileName = 'data/users/users.rdf'; |
---|
[131] | 20 | //Ensure the required folder for this connector exists |
---|
| 21 | if (!is_dir('data/users/')) |
---|
| 22 | mkdir('data/users/'); |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | /** |
---|
| 26 | * function get($arguments) |
---|
| 27 | * Gets the array of User objects belonging to arguments supplied. |
---|
| 28 | * @param type $arguments : An array containing zero or more of the following keys: |
---|
[149] | 29 | * 'uid', 'name', 'password' |
---|
[131] | 30 | */ |
---|
| 31 | public function get($arguments) { |
---|
| 32 | $this->load(); |
---|
| 33 | //Create the querystring |
---|
| 34 | $querystring = ' |
---|
| 35 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> |
---|
| 36 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> |
---|
| 37 | SELECT ?uid, ?name, ?password |
---|
| 38 | WHERE |
---|
| 39 | { |
---|
| 40 | _user predicates:resource_type resources:user ; |
---|
| 41 | predicates:uid ?uid ; |
---|
| 42 | predicates:name ?name ; |
---|
| 43 | predicates:password ?password ; |
---|
[171] | 44 | ' . $this->createArguments($arguments) . ' |
---|
[131] | 45 | }'; |
---|
| 46 | //Query the model |
---|
[171] | 47 | $results = $this->model->sparqlQuery($querystring); |
---|
[131] | 48 | $users = array(); |
---|
| 49 | if(!empty($results)) |
---|
| 50 | { |
---|
| 51 | //Run over all results and create appropriate Application objets |
---|
| 52 | foreach($results as $result) |
---|
| 53 | { |
---|
| 54 | $users[] = new User($result['?uid']->label, $result['?name']->label, $result['?password']->label); |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | return $users; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | * Save the given User object in the file. |
---|
| 62 | * @param type $rToolObject |
---|
| 63 | */ |
---|
| 64 | public function set($rToolObject) |
---|
| 65 | { |
---|
| 66 | $this->load(); |
---|
| 67 | $resourceUser = new Resource(USER . '/' . $rToolObject->uid); |
---|
| 68 | //Remove the old value stored with the given id |
---|
| 69 | $this->model->subtract($this->model->find($resourceUser, null, null)); |
---|
| 70 | |
---|
| 71 | $resourceUserType = new Resource(USER); |
---|
| 72 | $predicateRType = new Resource(RTYPE); |
---|
| 73 | $this->model->add(new Statement($resourceUser,$predicateRType,$resourceUserType)); |
---|
| 74 | |
---|
| 75 | $literalUserID = new Literal($rToolObject->uid); |
---|
| 76 | $predicateUniqueID = new Resource(UID); |
---|
| 77 | $this->model->add(new Statement($resourceUser,$predicateUniqueID,$literalUserID)); |
---|
| 78 | |
---|
| 79 | $literalUserName = new Literal($rToolObject->name); |
---|
| 80 | $predicateName = new Resource(NAME); |
---|
| 81 | $this->model->add(new Statement($resourceUser,$predicateName,$literalUserName)); |
---|
| 82 | |
---|
| 83 | $literalPassword = new Literal($rToolObject->password); |
---|
| 84 | $predicatePassword = new Resource(PASSWORD); |
---|
| 85 | $this->model->add(new Statement($resourceUser,$predicatePassword,$literalPassword)); |
---|
| 86 | $this->save(); |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | ?> |
---|