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