class_BaseUser.php

Go to the documentation of this file.
00001 <?php
00024 class BaseUser extends BaseFrameworkSystem {
00025         // Exception constances
00026         const EXCEPTION_USERNAME_NOT_FOUND   = 0x150;
00027         const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x151;
00028         const EXCEPTION_USER_PASS_MISMATCH   = 0x152;
00029 
00033         private $userName = "";
00034 
00038         private $userId = 0;
00039 
00043         private $email = "";
00044 
00051         protected function __construct ($className) {
00052                 // Call parent constructor
00053                 parent::__construct($className);
00054 
00055                 // Clean up a little
00056                 $this->removeNumberFormaters();
00057                 $this->removeSystemArray();
00058         }
00059 
00066         public final function setUserName ($userName) {
00067                 $this->userName = (string) $userName;
00068         }
00069 
00075         public final function getUserName () {
00076                 return $this->userName;
00077         }
00078 
00086         public final function setUserId ($userId) {
00087                 $this->userId = $userId;
00088         }
00089 
00095         public final function getUserId () {
00096                 return $this->userId;
00097         }
00098 
00105         protected final function setEmail ($email) {
00106                 $this->email = (string) $email;
00107         }
00108 
00114         public final function getEmail () {
00115                 return $this->email;
00116         }
00117 
00123         public function ifUsernameExists () {
00124                 // By default the username does not exist
00125                 $exists = false;
00126 
00127                 // Is a previous result there?
00128                 if (is_null($this->getResultInstance())) {
00129                         // Get a UserDatabaseWrapper instance
00130                         $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
00131 
00132                         // Create a search criteria
00133                         $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
00134 
00135                         // Add the username as a criteria and set limit to one entry
00136                         $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
00137                         $criteriaInstance->setLimit(1);
00138 
00139                         // Get a search result
00140                         $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
00141 
00142                         // Set the index "solver"
00143                         $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId'));
00144 
00145                         // And finally set it
00146                         $this->setResultInstance($resultInstance);
00147                 } // END - if
00148 
00149                 // Rewind it
00150                 $this->getResultInstance()->rewind();
00151 
00152                 // Search for it
00153                 if ($this->getResultInstance()->next()) {
00154                         // Entry found
00155                         $exists = true;
00156                 } // END - if
00157 
00158                 // Return the status
00159                 return $exists;
00160         }
00161 
00167         public function ifEmailAddressExists () {
00168                 // By default the email does not exist
00169                 $exists = false;
00170 
00171                 // Is a previous result there?
00172                 if (is_null($this->getResultInstance())) {
00173                         // Get a UserDatabaseWrapper instance
00174                         $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
00175 
00176                         // Create a search criteria
00177                         $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
00178 
00179                         // Add the username as a criteria and set limit to one entry
00180                         $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_EMAIL, $this->getEmail());
00181                         $criteriaInstance->setLimit(1);
00182 
00183                         // Get a search result
00184                         $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
00185 
00186                         // Set the index "solver"
00187                         $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId'));
00188 
00189                         // And finally set it
00190                         $this->setResultInstance($resultInstance);
00191                 } // END - if
00192 
00193                 // Rewind it
00194                 $this->getResultInstance()->rewind();
00195 
00196                 // Search for it
00197                 if ($this->getResultInstance()->next()) {
00198                         // Entry found
00199                         $exists = true;
00200 
00201                         // Is the username set?
00202                         if ($this->getUserName() == "") {
00203                                 // Get current entry
00204                                 $currEntry = $this->getResultInstance()->current();
00205 
00206                                 // Set the username
00207                                 $this->setUserName($currEntry['username']);
00208                         } // END - if
00209                 } // END - if
00210 
00211                 // Return the status
00212                 return $exists;
00213         }
00214 
00222         public function ifPasswordHashMatches (Requestable $requestInstance) {
00223                 // By default nothing matches... ;)
00224                 $matches = false;
00225 
00226                 // Is a previous result there?
00227                 if (is_null($this->getResultInstance())) {
00228                         // Get a UserDatabaseWrapper instance
00229                         $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
00230 
00231                         // Create a search criteria
00232                         $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
00233 
00234                         // Add the username as a criteria and set limit to one entry
00235                         $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
00236                         $criteriaInstance->setLimit(1);
00237 
00238                         // Get a search result
00239                         $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
00240 
00241                         // Set the index "solver"
00242                         $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId'));
00243 
00244                         // And finally set it
00245                         $this->setResultInstance($resultInstance);
00246                 } // END - if
00247 
00248                 // Rewind it
00249                 $this->getResultInstance()->rewind();
00250 
00251                 // Search for it
00252                 if ($this->getResultInstance()->find('pass_hash')) {
00253                         // So does the hashes match?
00254                         //* DEBUG: */ echo $requestInstance->getRequestElement('pass_hash')."/".$entry['pass_hash'];
00255                         $matches = ($requestInstance->getRequestElement('pass_hash') === $this->getResultInstance()->getFoundValue());
00256                 } // END - if
00257 
00258                 // Return the status
00259                 return $matches;
00260         }
00261 
00267         public final function getPasswordHash () {
00268                 // Default is missing password hash
00269                 $passHash = null;
00270 
00271                 // Get a database entry
00272                 $entry = $this->getDatabaseEntry();
00273 
00274                 // Is the password hash there?
00275                 if (isset($entry['pass_hash'])) {
00276                         // Get it
00277                         $passHash = $entry['pass_hash'];
00278                 } // END - if
00279 
00280                 // And return the hash
00281                 return $passHash;
00282         }
00283 
00289         public final function getPrimaryKey () {
00290                 // Get a user database wrapper
00291                 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
00292 
00293                 // Get the primary key back from the wrapper
00294                 $primaryKey = $wrapperInstance->getPrimaryKeyValue();
00295 
00296                 // Get that field
00297                 $primaryValue = $this->getField($primaryKey);
00298 
00299                 // Return the value
00300                 return $primaryValue;
00301         }
00302 
00311         public function updateDatabaseField ($fieldName, $fieldValue) {
00312                 // Is updating database fields allowed by interface?
00313                 if (!$this instanceof Updateable) {
00314                         // Update not supported!
00315                         throw new DatabaseUpdateSupportException($this, self::EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED);
00316                 } // END - if
00317 
00318                 // Get a critieria instance
00319                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
00320 
00321                 // Add search criteria
00322                 $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
00323                 $searchInstance->setLimit(1);
00324 
00325                 // Now get another criteria
00326                 $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
00327 
00328                 // And add our both entries
00329                 $updateInstance->addCriteria($fieldName, $fieldValue);
00330 
00331                 // Add the search criteria for searching for the right entry
00332                 $updateInstance->setSearchInstance($searchInstance);
00333 
00334                 // Remember the update in database result
00335                 $this->getResultInstance()->add2UpdateQueue($updateInstance);
00336         }
00337 }
00338 
00339 // [EOF]
00340 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6