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