X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fdatabase%2Fwrapper%2Fclass_UserDatabaseWrapper.php;h=d68f2883cff5a6204404d3e6416ae68cdd6c0af1;hp=503fbadb02089e2e2f0007fec6b077d5e406135a;hb=1ee35e6d96c456b8e3499bd683f1647aa28bd501;hpb=c6d73b0e3246efc824cb98338d4be7ee5bc9f308 diff --git a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php index 503fbadb..d68f2883 100644 --- a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php +++ b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php @@ -2,11 +2,11 @@ /** * A database wrapper for the User class * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @link http://www.shipsimu.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 @@ -21,26 +21,26 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class UserDatabaseWrapper extends BaseDatabaseWrapper { +class UserDatabaseWrapper extends BaseDatabaseWrapper implements ManageableAccountWrapper { // Constants for exceptions const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x180; // Constants for database columns - const DB_COLUMN_USERID = "userid"; - const DB_COLUMN_USERNAME = "username"; - const DB_COLUMN_EMAIL = "email"; - const DB_COLUMN_CONFIRM_HASH = "confirm_hash"; - const DB_COLUMN_USER_STATUS = "user_status"; + const DB_COLUMN_USERID = 'userid'; + 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"; + const DB_TABLE_USER = 'user'; /** * Protected constructor * * @return void */ - protected function __construct() { + protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); } @@ -50,7 +50,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper { * * @return $wrapperInstance An instance of the created wrapper class */ - public final static function createUserDatabaseWrapper () { + public static final function createUserDatabaseWrapper () { // Get a new instance $wrapperInstance = new UserDatabaseWrapper(); @@ -61,15 +61,6 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper { return $wrapperInstance; } - /** - * Getter for index key - * - * @return $indexKey Index key - */ - public final function getIndexKey () { - return $this->getDatabaseInstance()->getIndexKey(); - } - /** * Handles inserting the registration data from a registration instance into the database * @@ -81,13 +72,13 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper { $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_USER)); // Set the primary key - $dataSetInstance->setUniqueKey('username'); + $dataSetInstance->setUniqueKey(self::DB_COLUMN_USERNAME); // Add registration elements to the dataset - $registrationInstance->addElementsToDataSet($dataSetInstance); + $registrationInstance->addElementsToDataSet($dataSetInstance, NULL); // "Insert" this request instance completely into the database - $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance); + $this->queryInsertDataSet($dataSetInstance); } /** @@ -95,19 +86,44 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper { * * @param $resultInstance An instance of a Updateable database result * @return void + * @throws NullPointerException If $updateInstance or $searchInstance is null */ public function doUpdateByResult (UpdateableResult $resultInstance) { + // Get the search instance from result + $searchInstance = $resultInstance->getSearchInstance(); + + // Is this null? + if (is_null($searchInstance)) { + // Get the update instance + $updateInstance = $resultInstance->getUpdateInstance(); + + // Is this null? + if (is_null($updateInstance)) { + // Throw an exception here + throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + } // END - if + + // Get search instance from update instance + $searchInstance = $updateInstance->getSearchInstance(); + + // Is it still null? + if (is_null($searchInstance)) { + // Throw an exception here + throw new NullPointerException($updateInstance, self::EXCEPTION_IS_NULL_POINTER); + } // END - if + } // END - if + // 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()); + $dataSetInstance->setSearchInstance($searchInstance); // Set the primary key - $dataSetInstance->setUniqueKey('username'); + $dataSetInstance->setUniqueKey(self::DB_COLUMN_USERNAME); + + // Add all update criteria to the database set + $resultInstance->addElementsToDataSet($dataSetInstance, NULL); // "Update" this request with the database $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);