[131] | 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; |
---|
[139] | 22 | private $surveyConnector; |
---|
[149] | 23 | private $respondentConnector; |
---|
| 24 | private $answerConnector; |
---|
| 25 | private $answerSetConnector; |
---|
| 26 | private $sessionConnector; |
---|
[131] | 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(); |
---|
[139] | 36 | $this->surveyConnector = new SurveyConnector(); |
---|
[149] | 37 | $this->respondentConnector = new RespondentConnector(); |
---|
| 38 | $this->answerConnector = new AnswerConnector(); |
---|
| 39 | $this->answerSetConnector = new AnswerSetConnector(); |
---|
| 40 | $this->sessionConnector = new SessionConnector(); |
---|
[131] | 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 | */ |
---|
[149] | 49 | public function get($type, $arguments = array()) |
---|
[131] | 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; |
---|
[139] | 62 | case "survey": |
---|
| 63 | return $this->surveyConnector->get($arguments); |
---|
[149] | 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 | break; |
---|
| 74 | case "session": |
---|
| 75 | return $this->sessionConnector->get($arguments); |
---|
| 76 | break; |
---|
[131] | 77 | } |
---|
| 78 | } |
---|
| 79 | |
---|
| 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; |
---|
[139] | 97 | case "Survey": |
---|
[149] | 98 | $this->surveyConnector->set($rToolObject); |
---|
| 99 | break; |
---|
| 100 | case "Respondent": |
---|
| 101 | $this->respondentConnector->set($rToolObject); |
---|
| 102 | break; |
---|
| 103 | case "Answer": |
---|
| 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; |
---|
[131] | 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 | ?> |
---|