Ignore:
Timestamp:
10/24/11 13:47:23 (14 years ago)
Author:
jkraaijeveld
Message:

Added support for questions and users

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/jos-branch/classes/DatabaseInterface.php

    r128 r130  
    1717     * Constructor for the DatabaseInterface class
    1818     */
    19     protected $applicationConnector;
     19    private $applicationConnector;
     20    private $questionConnector;
     21    private $userConnector;
    2022   
     23    /**
     24     * Constructor for DatabaseInterface.
     25     * Initializes all the connectors.
     26     */
    2127    public function __construct() {
    2228        $this->applicationConnector = new ApplicationConnector();
     29        $this->questionConnector = new QuestionConnector();
     30        $this->userConnector = new UserConnector();
    2331    }
    2432   
     33    /**
     34     * Get the data corresponding to the given type and arguments
     35     * @param type $type
     36     * @param type $arguments
     37     * @return type
     38     */
    2539    public function get($type, $arguments)
    2640    {
    27         switch($type)
     41        switch(strtolower($type))
    2842        {
    2943            case "application":
    3044                return $this->applicationConnector->get($arguments);
    31            
     45                break;
     46            case "question":
     47                return $this->questionConnector->get($arguments);
     48                break;
     49            case "user":
     50                return $this->userConnector->get($arguments);
     51                break;
    3252        }
    3353    }
    3454       
    35         public function set($rToolObject)
    36         {
    37                 switch(get_class($rToolObject))
    38                 {
    39                         case "Application":
    40                                 $this->applicationConnector->set($rToolObject);
    41                 }
    42         }
    43        
     55    /**
     56     * Saves the given object based on its class.
     57     * @param type $rToolObject
     58     */
     59    public function set($rToolObject)
     60    {
     61        switch(get_class($rToolObject))
     62        {
     63            case "Application":
     64                $this->applicationConnector->set($rToolObject);
     65                break;
     66            case "Question":
     67                $this->questionConnector->set($rToolObject);
     68                break;
     69            case "User":
     70                $this->userConnector->set($rToolObject);
     71                break;
     72        }
     73    }
     74   
     75    /**
     76     * Saves all the objects in the given array, assuming they are
     77     * valid ResearchToolObjects.
     78     * @param type $rToolObjects
     79     */
     80    public function batchSet($rToolObjects)
     81    {
     82        foreach ($rToolObjects as $rToolObject)
     83        {
     84            $this->set($rToolObject);
     85        }
     86    }
     87
    4488       
    4589}
Note: See TracChangeset for help on using the changeset viewer.