[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; |
---|
[207] | 27 | private $sessionInstanceConnector; |
---|
[131] | 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(); |
---|
[139] | 37 | $this->surveyConnector = new SurveyConnector(); |
---|
[149] | 38 | $this->respondentConnector = new RespondentConnector(); |
---|
| 39 | $this->answerConnector = new AnswerConnector(); |
---|
| 40 | $this->answerSetConnector = new AnswerSetConnector(); |
---|
| 41 | $this->sessionConnector = new SessionConnector(); |
---|
[207] | 42 | $this->sessionInstanceConnector = new SessionInstanceConnector(); |
---|
[131] | 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 | */ |
---|
[149] | 51 | public function get($type, $arguments = array()) |
---|
[131] | 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; |
---|
[139] | 64 | case "survey": |
---|
| 65 | return $this->surveyConnector->get($arguments); |
---|
[149] | 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; |
---|
[207] | 79 | case "sessioninstance": |
---|
| 80 | return $this->sessionInstanceConnector->get($arguments); |
---|
| 81 | break; |
---|
[131] | 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": |
---|
[207] | 94 | return $this->applicationConnector->set($rToolObject); |
---|
[131] | 95 | break; |
---|
| 96 | case "Question": |
---|
[207] | 97 | return $this->questionConnector->set($rToolObject); |
---|
[131] | 98 | break; |
---|
| 99 | case "User": |
---|
[207] | 100 | return $this->userConnector->set($rToolObject); |
---|
[131] | 101 | break; |
---|
[139] | 102 | case "Survey": |
---|
[207] | 103 | return $this->surveyConnector->set($rToolObject); |
---|
[149] | 104 | break; |
---|
| 105 | case "Respondent": |
---|
[207] | 106 | return $this->respondentConnector->set($rToolObject); |
---|
[149] | 107 | break; |
---|
| 108 | case "Answer": |
---|
[207] | 109 | return $this->answerConnector->set($rToolObject); |
---|
[149] | 110 | break; |
---|
| 111 | case "AnswerSet": |
---|
[207] | 112 | return $this->answerSetConnector->set($rToolObject); |
---|
[149] | 113 | break; |
---|
| 114 | case "Session": |
---|
[207] | 115 | return $this->sessionConnector->set($rToolObject); |
---|
[149] | 116 | break; |
---|
[207] | 117 | case "SessionInstance": |
---|
| 118 | return $this->sessionInstanceConnector->set($rToolObject); |
---|
| 119 | break; |
---|
[131] | 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 | { |
---|
[207] | 132 | if(!$this->set($rToolObject)) |
---|
| 133 | return false; |
---|
| 134 | } |
---|
| 135 | return true; |
---|
[131] | 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | ?> |
---|