source: Dev/trunk/classes/DatabaseInterface.php @ 139

Last change on this file since 139 was 139, checked in by jkraaijeveld, 14 years ago

Now has Survey support

File size: 2.5 KB
Line 
1<?php
2
3/*
4 * To change this template, choose Tools | Templates
5 * and open the template in the editor.
6 */
7
8/**
9 * Description of DatabaseInterface
10 * Initializes all the connectors, serves as only entrance and exit point
11 * for the frontend
12 * @author jkraaijeveld
13 */
14class DatabaseInterface {
15   
16    /**
17     * Constructor for the DatabaseInterface class
18     */
19    private $applicationConnector;
20    private $questionConnector;
21    private $userConnector;
22    private $surveyConnector;
23   
24    /**
25     * Constructor for DatabaseInterface.
26     * Initializes all the connectors.
27     */
28    public function __construct() {
29        $this->applicationConnector = new ApplicationConnector();
30        $this->questionConnector = new QuestionConnector();
31        $this->userConnector = new UserConnector();
32        $this->surveyConnector = new SurveyConnector();
33    }
34   
35    /**
36     * Get the data corresponding to the given type and arguments
37     * @param type $type
38     * @param type $arguments
39     * @return type
40     */
41    public function get($type, $arguments)
42    {
43        switch(strtolower($type))
44        {
45            case "application":
46                return $this->applicationConnector->get($arguments);
47                break;
48            case "question":
49                return $this->questionConnector->get($arguments);
50                break;
51            case "user":
52                return $this->userConnector->get($arguments);
53                break;
54            case "survey":
55                return $this->surveyConnector->get($arguments);
56        }
57    }
58       
59    /**
60     * Saves the given object based on its class.
61     * @param type $rToolObject
62     */
63    public function set($rToolObject)
64    {
65        switch(get_class($rToolObject))
66        {
67            case "Application":
68                $this->applicationConnector->set($rToolObject);
69                break;
70            case "Question":
71                $this->questionConnector->set($rToolObject);
72                break;
73            case "User":
74                $this->userConnector->set($rToolObject);
75                break;
76            case "Survey":
77                $this->surveyConnector->set($rToolObject);
78        }
79    }
80   
81    /**
82     * Saves all the objects in the given array, assuming they are
83     * valid ResearchToolObjects.
84     * @param type $rToolObjects
85     */
86    public function batchSet($rToolObjects)
87    {
88        foreach ($rToolObjects as $rToolObject)
89        {
90            $this->set($rToolObject);
91        }
92    }
93
94       
95}
96
97?>
Note: See TracBrowser for help on using the repository browser.