X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fdatabase%2Fwrapper%2Fclass_UserDatabaseWrapper.php;h=0669cb8caf3c5186e1f403a66b4c042a71f2d67d;hp=18aabb060cbd68f9a2268901a3ddf33e60d0d4f5;hb=a550aa5e5aea2ecddfe0166e96bea62b01c7450e;hpb=5d2d7b2329dd8b6cab49a94aa4d21080577b2f2c diff --git a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php index 18aabb0..0669cb8 100644 --- a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php +++ b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php @@ -1,13 +1,12 @@ * @version 0.0.0 - * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @link http://www.ship-simu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,8 +22,17 @@ * along with this program. If not, see . */ class UserDatabaseWrapper extends BaseDatabaseWrapper { - // Constants - const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0xe00; + // Constants for exceptions + const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x180; + + // Constants for database columns + const DB_COLUMN_USERNAME = "username"; + const DB_COLUMN_EMAIL = "email"; + const DB_COLUMN_CONFIRM_HASH = "confirm_hash"; + const DB_COLUMN_USER_STATUS = "user_status"; + + // Constants for database table names + const DB_TABLE_USER = "user"; /** * Protected constructor @@ -36,35 +44,71 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Database client for user objects"); + $this->setObjectDescription("Database wrapper for user objects"); // Create unique ID number - $this->createUniqueID(); + $this->generateUniqueId(); } /** - * Creates an instance of this database client by a provided user class + * Creates an instance of this database wrapper by a provided user class * - * @param $userInstance An instance of a user class - * @return $clientInstance An instance of the created client class - * @throws WrapperUserNameNotFoundException If the supplied username + * @return $wrapperInstance An instance of the created wrapper class + * @throws WrapperUserNameNotFoundException If the supplied username * does not exist */ - public final static function createUserDatabaseWrapper (ManageableUser $userInstance) { + public final static function createUserDatabaseWrapper () { // Get a new instance - $clientInstance = new UserDatabaseWrapper(); - - // Does the username exists? - if (!$clientInstance->ifUserNameExists($userInstance->getUserName())) { - // Throw an exception here - throw new WrapperUserNameNotFoundException (array($clientInstance, $userInstance), self::EXCEPTION_CLIENT_USERNAME_NOT_FOUND); - } + $wrapperInstance = new UserDatabaseWrapper(); - // The user exists - $clientInstance->partialStub("Add loading of full user details"); + // Set (primary!) table name + $wrapperInstance->setTableName(self::DB_TABLE_USER); // Return the instance - return $clientInstance; + return $wrapperInstance; + } + + /** + * Handles inserting the registration data from a registration instance into the database + * + * @param $registrationInstance An instance of a registration class + * @return void + */ + public function insertRegistrationObject (UserRegister $registrationInstance) { + // Generate a data set for the request + $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER)); + + // Set the primary key + $dataSetInstance->setUniqueKey('username'); + + // Add registration elements to the dataset + $registrationInstance->addElementsToDataSet($dataSetInstance); + + // "Insert" this request instance completely into the database + $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance); + } + + /** + * Updates an user database entry with given result + * + * @param $resultInstance An instance of a Updateable database result + * @return void + */ + public function doUpdateByResult (UpdateableResult $resultInstance) { + // Generate a data set object + $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER)); + + // Add all update criteria to the database set + $resultInstance->addElementsToDataSet($dataSetInstance); + + // Add seach criteria + $dataSetInstance->setSearchInstance($resultInstance->getSearchInstance()); + + // Set the primary key + $dataSetInstance->setUniqueKey('username'); + + // "Update" this request with the database + $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance); } }