source: Dev/branches/jos-branch/classes/DatabaseInterface.php @ 203

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

Finished DatabaseInterface? v0.1? I hate version numbering.

File size: 3.6 KB
RevLine 
[123]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     */
[130]19    private $applicationConnector;
20    private $questionConnector;
21    private $userConnector;
[138]22    private $surveyConnector;
[140]23    private $respondentConnector;
[143]24        private $answerConnector;
25        private $answerSetConnector;
26        private $sessionConnector;
[123]27   
[130]28    /**
29     * Constructor for DatabaseInterface.
30     * Initializes all the connectors.
31     */
[123]32    public function __construct() {
33        $this->applicationConnector = new ApplicationConnector();
[130]34        $this->questionConnector = new QuestionConnector();
35        $this->userConnector = new UserConnector();
[138]36        $this->surveyConnector = new SurveyConnector();
[140]37        $this->respondentConnector = new RespondentConnector();
[143]38                $this->answerConnector = new AnswerConnector();
39                $this->answerSetConnector = new AnswerSetConnector();
40                $this->sessionConnector = new SessionConnector();
[123]41    }
42   
[130]43    /**
44     * Get the data corresponding to the given type and arguments
45     * @param type $type
46     * @param type $arguments
47     * @return type
48     */
[148]49    public function get($type, $arguments = array())
[123]50    {
[130]51        switch(strtolower($type))
[123]52        {
53            case "application":
54                return $this->applicationConnector->get($arguments);
[130]55                break;
56            case "question":
57                return $this->questionConnector->get($arguments);
58                break;
59            case "user":
60                return $this->userConnector->get($arguments);
61                break;
[138]62            case "survey":
63                return $this->surveyConnector->get($arguments);
[141]64                break;
[140]65            case "respondent":
66                return $this->respondentConnector->get($arguments);
[141]67                break;
68            case "answer":
69                return $this->answerConnector->get($arguments);
[143]70                                break;
71                        case "answerset":
72                                return $this->answerSetConnector->get($arguments);
[148]73                                break;
[143]74                        case "session":
75                                return $this->sessionConnector->get($arguments);
[148]76                                break;
[123]77        }
78    }
[128]79       
[130]80    /**
81     * Saves the given object based on its class.
82     * @param type $rToolObject
83     */
84    public function set($rToolObject)
85    {
86        switch(get_class($rToolObject))
87        {
88            case "Application":
89                $this->applicationConnector->set($rToolObject);
90                break;
91            case "Question":
92                $this->questionConnector->set($rToolObject);
93                break;
94            case "User":
95                $this->userConnector->set($rToolObject);
96                break;
[138]97            case "Survey":
[143]98                                $this->surveyConnector->set($rToolObject);
99                                break;
[140]100            case "Respondent":
[143]101                                $this->respondentConnector->set($rToolObject);
102                                break;
[141]103            case "Answer":
[143]104                                $this->answerConnector->set($rToolObject);
105                                break;
106                        case "AnswerSet":
107                                $this->answerSetConnector->set($rToolObject);
108                                break;
109                        case "Session":
110                                $this->sessionConnector->set($rToolObject);
111                                break;
[130]112        }
113    }
114   
115    /**
116     * Saves all the objects in the given array, assuming they are
117     * valid ResearchToolObjects.
118     * @param type $rToolObjects
119     */
120    public function batchSet($rToolObjects)
121    {
122        foreach ($rToolObjects as $rToolObject)
123        {
124            $this->set($rToolObject);
125        }
126    }
127
[128]128       
[123]129}
130
131?>
Note: See TracBrowser for help on using the repository browser.