]> git.mxchange.org Git - hub.git/blobdiff - inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php
Code sync from ship-simu code (all class config entries must end with _class!)
[hub.git] / inc / classes / main / database / wrapper / class_UserDatabaseWrapper.php
index c8eb465c2b3e313b29cb753dae071d0b832708f3..5fc62e2a836a0a2fd32fb9ea2d8bcf6d676d0711 100644 (file)
@@ -7,7 +7,7 @@
  * @version            0.0.0
  * @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
@@ -29,10 +29,11 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper {
        private $cacheInstance = null;
 
        // Constants for exceptions
-       const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0xe00;
+       const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x070;
 
        // Constants for database columns
        const DB_COLUMN_USERNAME = "username";
+       const DB_COLUMN_EMAIL    = "email";
 
        // Constants for database table names
        const DB_TABLE_USER = "user";
@@ -50,7 +51,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper {
                $this->setObjectDescription("Database wrapper for user objects");
 
                // Create unique ID number
-               $this->createUniqueID();
+               $this->generateUniqueId();
        }
 
        /**
@@ -103,8 +104,17 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper {
                        // Now it's time to ask the database layer for this select statement
                        $result = $this->getDatabaseInstance()->doSelectByTableCriteria(self::DB_TABLE_USER, $criteriaInstance);
 
-                       // Cache the result
-                       $this->cacheInstance->offsetSet($cacheKey, $result);
+                       // Cache the result if not null
+                       if (!is_null($result)) {
+                               // A valid result has returned from the database layer
+                               $this->cacheInstance->offsetSet($cacheKey, $result);
+                       } else {
+                               // This invalid result must be wrapped
+                               $result = array(
+                                       'status'                => "invalid",
+                                       'exception'             => $this->getDatabaseInstance()->getLastException()
+                               );
+                       }
                }
 
                // Create an instance of a DatabaseResult class with the given result
@@ -113,6 +123,24 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper {
                // And return the instance
                return $resultInstance;
        }
+
+       /**
+        * 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');
+               $dataSetInstance->setTableName(self::DB_TABLE_USER);
+
+               // Add registration elements to the dataset
+               $registrationInstance->addElementsToDataSet($dataSetInstance);
+
+               // "Insert" this request instance completely into the database
+               $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
+       }
 }
 
 // [EOF]