source: Dev/branches/jos-branch/classes/DatabaseInterface.php @ 141

Last change on this file since 141 was 141, checked in by jkraaijeveld, 14 years ago

Started work on Answer and AnswerConnector?.

note to self: (Session -> AnswerSet? (SurveyId?, Respondent, Answer*)

File size: 3.1 KB
Line 
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 */
14class 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   
26    /**
27     * Constructor for DatabaseInterface.
28     * Initializes all the connectors.
29     */
30    public function __construct() {
31        $this->applicationConnector = new ApplicationConnector();
32        $this->questionConnector = new QuestionConnector();
33        $this->userConnector = new UserConnector();
34        $this->surveyConnector = new SurveyConnector();
35        $this->respondentConnector = new RespondentConnector();
36        $this->answerConnector = new AnswerConnector();
37    }
38   
39    /**
40     * Get the data corresponding to the given type and arguments
41     * @param type $type
42     * @param type $arguments
43     * @return type
44     */
45    public function get($type, $arguments)
46    {
47        switch(strtolower($type))
48        {
49            case "application":
50                return $this->applicationConnector->get($arguments);
51                break;
52            case "question":
53                return $this->questionConnector->get($arguments);
54                break;
55            case "user":
56                return $this->userConnector->get($arguments);
57                break;
58            case "survey":
59                return $this->surveyConnector->get($arguments);
60                break;
61            case "respondent":
62                return $this->respondentConnector->get($arguments);
63                break;
64            case "answer":
65                return $this->answerConnector->get($arguments);
66                break;
67               
68        }
69    }
70       
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;
88            case "Survey":
89                $this->surveyConnector->set($rToolObject);
90            case "Respondent":
91                $this->respondentConnector->set($rToolObject);
92            case "Answer":
93                $this->answerConnector->set($rToolObject);
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
110       
111}
112
113?>
Note: See TracBrowser for help on using the repository browser.