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

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

Made lots of new connectors, stranded on Sessionconnector for now. Need to find a way to retain the order of applicaties and surveys of a pipeline.

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