* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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
$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
*
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
*
$criteriaInstance->setLimit(1);
// Get a search result
- $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+ $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance));
} else {
// Rewind it
$this->getResultInstance()->rewind();
$criteriaInstance->setLimit(1);
// Get a search resultInstance
- $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+ $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance));
} else {
// Rewind it
$this->getResultInstance()->rewind();
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
$criteriaInstance->setLimit(1);
// Get a search resultInstance
- $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+ $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance));
// Search for it
if ($this->getResultInstance()->next()) {
*
* @return $passHash User's password hash from database result
*/
- public function getPasswordHash () {
+ public final function getPasswordHash () {
// Default is missing password hash
$passHash = null;
if (isset($entry['pass_hash'])) {
// Get it
$passHash = $entry['pass_hash'];
- }
+ } // END - if
// And return the hash
return $passHash;
}
/**
- * Getter for field name
+ * Getter for primary key value
*
- * @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?
+ * @return $primaryValue Value of the primary key based on database type
*/
- public function getField ($fieldName) {
- // Default field value
- $fieldValue = null;
+ public final function getPrimaryKey () {
+ // Get a user database wrapper
+ $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
- // Get current array
- $fieldArray = $this->getResultInstance()->current();
+ // Get the primary key back from the wrapper
+ $primaryKey = $wrapperInstance->getPrimaryKeyValue();
- // Does the field exist?
- if (isset($fieldArray[$fieldName])) {
- // Get it
- $fieldValue = $fieldArray[$fieldName];
- } // END - if
+ // Get that field
+ $primaryValue = $this->getField($primaryKey);
- // Return it
- return $fieldValue;
+ // Return the value
+ return $primaryValue;
}
}