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