3 namespace Org\Mxchange\CoreFramework\Database\Frontend\User;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Database\Frontend\BaseDatabaseWrapper;
7 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
8 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
9 use Org\Mxchange\CoreFramework\Registration\User\UserRegister;
10 use Org\Mxchange\CoreFramework\Registry\Registerable;
11 use Org\Mxchange\CoreFramework\Result\Update\UpdateableResult;
12 use Org\Mxchange\CoreFramework\Wrapper\Account\ManageableAccountWrapper;
15 * A database wrapper for the User class
17 * @author Roland Haeder <webmaster@shipsimu.org>
19 <<<<<<< HEAD:framework/main/classes/database/frontend/class_UserDatabaseWrapper.php
20 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
22 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
23 >>>>>>> Some updates::inc/main/classes/database/frontend/class_UserDatabaseWrapper.php
24 * @license GNU GPL 3.0 or any newer version
25 * @link http://www.shipsimu.org
27 * This program is free software: you can redistribute it and/or modify
28 * it under the terms of the GNU General Public License as published by
29 * the Free Software Foundation, either version 3 of the License, or
30 * (at your option) any later version.
32 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with this program. If not, see <http://www.gnu.org/licenses/>.
40 class UserDatabaseWrapper extends BaseDatabaseWrapper implements ManageableAccountWrapper, Registerable {
41 // Constants for exceptions
42 const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x180;
44 // Constants for database columns
45 const DB_COLUMN_USERID = 'userid';
46 const DB_COLUMN_USERNAME = 'username';
47 const DB_COLUMN_EMAIL = 'email';
48 const DB_COLUMN_CONFIRM_HASH = 'confirm_hash';
49 const DB_COLUMN_USER_STATUS = 'user_status';
51 // Constants for database table names
52 const DB_TABLE_USER = 'user';
55 * Protected constructor
59 protected function __construct () {
60 // Call parent constructor
61 parent::__construct(__CLASS__);
65 * Creates an instance of this database wrapper by a provided user class
67 * @return $wrapperInstance An instance of the created wrapper class
69 public static final function createUserDatabaseWrapper () {
71 $wrapperInstance = new UserDatabaseWrapper();
73 // Set (primary!) table name
74 $wrapperInstance->setTableName(self::DB_TABLE_USER);
76 // Return the instance
77 return $wrapperInstance;
81 * Handles inserting the registration data from a registration instance into the database
83 * @param $registrationInstance An instance of a registration class
86 public function insertRegistrationObject (UserRegister $registrationInstance) {
87 // Generate a data set for the request
88 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER));
90 // Set the primary key
91 $dataSetInstance->setUniqueKey(self::DB_COLUMN_USERNAME);
93 // Add registration elements to the dataset
94 $registrationInstance->addElementsToDataSet($dataSetInstance);
96 // "Insert" this request instance completely into the database
97 $this->queryInsertDataSet($dataSetInstance);
101 * Updates an user database entry with given result
103 * @param $resultInstance An instance of a Updateable database result
105 * @throws NullPointerException If $updateInstance or $searchInstance is null
107 public function doUpdateByResult (UpdateableResult $resultInstance) {
108 // Get the search instance from result
109 $searchInstance = $resultInstance->getSearchInstance();
112 if (is_null($searchInstance)) {
113 // Get the update instance
114 $updateInstance = $resultInstance->getUpdateInstance();
117 if (is_null($updateInstance)) {
118 // Throw an exception here
119 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
122 // Get search instance from update instance
123 $searchInstance = $updateInstance->getSearchInstance();
126 if (is_null($searchInstance)) {
127 // Throw an exception here
128 throw new NullPointerException($updateInstance, self::EXCEPTION_IS_NULL_POINTER);
132 // Generate a data set object
133 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER));
135 // Add seach criteria
136 $dataSetInstance->setSearchInstance($searchInstance);
138 // Set the primary key
139 $dataSetInstance->setUniqueKey(self::DB_COLUMN_USERNAME);
141 // Add all update criteria to the database set
142 $resultInstance->addElementsToDataSet($dataSetInstance);
144 // "Update" this request with the database
145 $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);