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

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

Deleted previous database classes
Submitted (partial) new database connection

File size: 2.2 KB
RevLine 
[131]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   
23    /**
24     * Constructor for DatabaseInterface.
25     * Initializes all the connectors.
26     */
27    public function __construct() {
28        $this->applicationConnector = new ApplicationConnector();
29        $this->questionConnector = new QuestionConnector();
30        $this->userConnector = new UserConnector();
31    }
32   
33    /**
34     * Get the data corresponding to the given type and arguments
35     * @param type $type
36     * @param type $arguments
37     * @return type
38     */
39    public function get($type, $arguments)
40    {
41        switch(strtolower($type))
42        {
43            case "application":
44                return $this->applicationConnector->get($arguments);
45                break;
46            case "question":
47                return $this->questionConnector->get($arguments);
48                break;
49            case "user":
50                return $this->userConnector->get($arguments);
51                break;
52        }
53    }
54       
55    /**
56     * Saves the given object based on its class.
57     * @param type $rToolObject
58     */
59    public function set($rToolObject)
60    {
61        switch(get_class($rToolObject))
62        {
63            case "Application":
64                $this->applicationConnector->set($rToolObject);
65                break;
66            case "Question":
67                $this->questionConnector->set($rToolObject);
68                break;
69            case "User":
70                $this->userConnector->set($rToolObject);
71                break;
72        }
73    }
74   
75    /**
76     * Saves all the objects in the given array, assuming they are
77     * valid ResearchToolObjects.
78     * @param type $rToolObjects
79     */
80    public function batchSet($rToolObjects)
81    {
82        foreach ($rToolObjects as $rToolObject)
83        {
84            $this->set($rToolObject);
85        }
86    }
87
88       
89}
90
91?>
Note: See TracBrowser for help on using the repository browser.