source: Dev/branches/jos-branch/classes_old/RespondentConnector.php @ 210

Last change on this file since 210 was 210, checked in by jkraaijeveld, 13 years ago

Moved all classes into classes_old

File size: 3.2 KB
Line 
1<?php
2// Survey database interface class as intermediate for storing data from the site to the RDF database
3require_once 'rdfConstants.php';
4// Include RAP Library to write RDF files
5include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
6
7/**
8 * Description of RespondentConnector
9 *
10 * @author jkraaijeveld
11 */
12class RespondentConnector extends Connector{
13   
14    /**
15     * Constructor for RespondentConnector.
16     */
17    public function __construct()
18    {
19                $this->fileName = 'data/users/respondents.rdf';
20        if (!is_dir('data/users/'))
21            mkdir('data/users/');       
22    }
23   
24    /**
25     * function get()
26     * Gets the array of Respondent objects belonging to arguments supplied.
27     * @param type $arguments : An array containing zero or more of the following keys:
28     *                          'uid', 'name', 'password'
29     */
30    public function get($arguments) {
31        $this->load();
32       
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                    _respondent predicates:resource_type        resources:respondent ;
41                                        predicates:uid ?uid ;
42                                        predicates:name ?name ;
43                                        predicates:password ?password ;
44                                        ' . $this->createArguments($arguments) .  '
45            }';
46        //Query the model
47        $results = $this->model->sparqlQuery($querystring);
48                $respondents = array();
49        if(!empty($results))
50        {
51            //Run over all results and create appropriate Respondent objets
52            foreach($results as $result)
53            {
54                    $respondents[] = new Respondent($result['?uid']->label, $result['?name']->label, $result['?password']->label);
55            }
56        }
57        return $respondents;
58    }
59   
60    /**
61         * function set()
62     * @param type $rToolObject : The ResearchToolObject to be saved.
63     */
64    public function set($rToolObject)
65    {
66        $this->load();
67        $resourceRespondent = new Resource(RESPONDENT . '/' . $rToolObject->uid);
68        //Remove the old value stored with the given id
69        $this->model->subtract($this->model->find($resourceRespondent, null, null));
70
71                //Set the new values
72        $resourceRespondentType = new Resource(RESPONDENT);
73        $predicateRType = new Resource(RTYPE);
74        $this->model->add(new Statement($resourceRespondent,$predicateRType,$resourceRespondentType));
75
76        $literalRespondentID = new Literal($rToolObject->uid);
77        $predicateUniqueID = new Resource(UID);
78        $this->model->add(new Statement($resourceRespondent,$predicateUniqueID,$literalRespondentID));
79       
80        $literalRespondentName = new Literal($rToolObject->name);
81        $predicateName = new Resource(NAME);
82        $this->model->add(new Statement($resourceRespondent,$predicateName,$literalRespondentName));                   
83
84        $literalPassword = new Literal($rToolObject->password);
85        $predicatePassword = new Resource(PASSWORD);
86        $this->model->add(new Statement($resourceRespondent,$predicatePassword,$literalPassword));
87        $this->save();
88    }
89}
90
91?>
Note: See TracBrowser for help on using the repository browser.