X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=inc%2Fclasses%2Fmain%2Fuser%2Fclass_BaseUser.php;h=0a3432de390c06c6729bc4ff4760a5f6009b6071;hb=968aa514d2df8ed98dab8ff251ee83c95f1ac182;hp=e7e4541e70623d0dcaf99a6150777ece46fa41b7;hpb=6019ae86707cb6decaddc63f191e3ef6eb5e4d44;p=shipsimu.git diff --git a/inc/classes/main/user/class_BaseUser.php b/inc/classes/main/user/class_BaseUser.php index e7e4541..0a3432d 100644 --- a/inc/classes/main/user/class_BaseUser.php +++ b/inc/classes/main/user/class_BaseUser.php @@ -22,10 +22,10 @@ * along with this program. If not, see . */ class BaseUser extends BaseFrameworkSystem { - /** - * Instance of the database result - */ - private $resultInstance = null; + // Exception constances + const EXCEPTION_USERNAME_NOT_FOUND = 0x150; + const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x151; + const EXCEPTION_USER_PASS_MISMATCH = 0x152; /** * Username of current user @@ -52,38 +52,6 @@ class BaseUser extends BaseFrameworkSystem { $this->removeSystemArray(); } - /** - * "Getter" for databse entry - * - * @return $entry An array with database entries - * @throws NullPointerException If the database result is not found - * @throws InvalidDatabaseResultException If the database result is invalid - */ - private function getDatabaseEntry () { - // Is there an instance? - if (is_null($this->getResultInstance())) { - // Throw new exception - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } // END - if - - // Rewind it - $this->getResultInstance()->rewind(); - - // Do we have an entry? - if (!$this->getResultInstance()->valid()) { - throw new InvalidDatabaseResultException(array($this, $this->resultInstance), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT); - } // END - if - - // Get next entry - $this->getResultInstance()->next(); - - // Fetch it - $entry = $this->getResultInstance()->current(); - - // And return it - return $entry; - } - /** * Setter for username * @@ -122,15 +90,6 @@ class BaseUser extends BaseFrameworkSystem { return $this->email; } - /** - * Getter for database result instance - * - * @return $resultInstance An instance of a database result class - */ - protected final function getResultInstance () { - return $this->resultInstance; - } - /** * Determines wether the username exists or not * @@ -153,7 +112,7 @@ class BaseUser extends BaseFrameworkSystem { $criteriaInstance->setLimit(1); // Get a search result - $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance); + $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance)); } else { // Rewind it $this->getResultInstance()->rewind(); @@ -191,7 +150,7 @@ class BaseUser extends BaseFrameworkSystem { $criteriaInstance->setLimit(1); // Get a search resultInstance - $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance); + $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance)); } else { // Rewind it $this->getResultInstance()->rewind(); @@ -201,6 +160,15 @@ class BaseUser extends BaseFrameworkSystem { if ($this->getResultInstance()->next()) { // Entry found $exists = true; + + // Is the username set? + if ($this->getUserName() == "") { + // Get current entry + $currEntry = $this->getResultInstance()->current(); + + // Set the username + $this->setUserName($currEntry['username']); + } // END - if } // END - if // Return the status @@ -229,7 +197,7 @@ class BaseUser extends BaseFrameworkSystem { $criteriaInstance->setLimit(1); // Get a search resultInstance - $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance); + $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance)); // Search for it if ($this->getResultInstance()->next()) { @@ -261,36 +229,12 @@ class BaseUser extends BaseFrameworkSystem { if (isset($entry['pass_hash'])) { // Get it $passHash = $entry['pass_hash']; - } + } // END - if // And return the hash return $passHash; } - /** - * Getter for field name - * - * @param $fieldName Field name which we shall get - * @return $fieldValue Field value from the user - * @todo Do we need to secure this here against missing results? - */ - public final function getField ($fieldName) { - // Default field value - $fieldValue = null; - - // Get current array - $fieldArray = $this->getResultInstance()->current(); - - // Does the field exist? - if (isset($fieldArray[$fieldName])) { - // Get it - $fieldValue = $fieldArray[$fieldName]; - } // END - if - - // Return it - return $fieldValue; - } - /** * Getter for primary key value * @@ -309,6 +253,41 @@ class BaseUser extends BaseFrameworkSystem { // Return the value return $primaryValue; } + + /** + * Updates a given field with new value + * + * @param $fieldName Field to update + * @param $fieldValue New value to store + * @return void + * @throws DatabaseUpdateSupportException If this class does not support database updates + */ + public function updateDatabaseField ($fieldName, $fieldValue) { + // Is updating database fields allowed by interface? + if (!$this instanceof Updateable) { + // Update not supported! + throw new DatabaseUpdateSupportException($this, self::EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED); + } // END - if + + // Get a critieria instance + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + + // Add search criteria + $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName()); + $searchInstance->setLimit(1); + + // Now get another criteria + $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class'); + + // And add our both entries + $updateInstance->addCriteria($fieldName, $fieldValue); + + // Add the search criteria for searching for the right entry + $updateInstance->setSearchInstance($searchInstance); + + // Remember the update in database result + $this->getResultInstance()->add2UpdateQueue($updateInstance); + } } // [EOF]