3 * A database wrapper for the User class
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class UserDatabaseWrapper extends BaseDatabaseWrapper {
25 // Constants for exceptions
26 const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x180;
28 // Constants for database columns
29 const DB_COLUMN_USERID = "userid";
30 const DB_COLUMN_USERNAME = "username";
31 const DB_COLUMN_EMAIL = "email";
32 const DB_COLUMN_CONFIRM_HASH = "confirm_hash";
33 const DB_COLUMN_USER_STATUS = "user_status";
35 // Constants for database table names
36 const DB_TABLE_USER = "user";
39 * Protected constructor
43 protected function __construct() {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
49 * Creates an instance of this database wrapper by a provided user class
51 * @return $wrapperInstance An instance of the created wrapper class
52 * @throws WrapperUserNameNotFoundException If the supplied username
55 public final static function createUserDatabaseWrapper () {
57 $wrapperInstance = new UserDatabaseWrapper();
59 // Set (primary!) table name
60 $wrapperInstance->setTableName(self::DB_TABLE_USER);
62 // Return the instance
63 return $wrapperInstance;
67 * Getter for index key
69 * @return $indexKey Index key
71 public final function getIndexKey () {
72 return $this->getDatabaseInstance()->getIndexKey();
76 * Handles inserting the registration data from a registration instance into the database
78 * @param $registrationInstance An instance of a registration class
81 public function insertRegistrationObject (UserRegister $registrationInstance) {
82 // Generate a data set for the request
83 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER));
85 // Set the primary key
86 $dataSetInstance->setUniqueKey('username');
88 // Add registration elements to the dataset
89 $registrationInstance->addElementsToDataSet($dataSetInstance);
91 // "Insert" this request instance completely into the database
92 $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
96 * Updates an user database entry with given result
98 * @param $resultInstance An instance of a Updateable database result
101 public function doUpdateByResult (UpdateableResult $resultInstance) {
102 // Generate a data set object
103 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER));
105 // Add all update criteria to the database set
106 $resultInstance->addElementsToDataSet($dataSetInstance);
108 // Add seach criteria
109 $dataSetInstance->setSearchInstance($resultInstance->getSearchInstance());
111 // Set the primary key
112 $dataSetInstance->setUniqueKey('username');
114 // "Update" this request with the database
115 $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);