class_BaseUser.php
Go to the documentation of this file.00001 <?php
00024 class BaseUser extends BaseFrameworkSystem {
00025
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
00053 parent::__construct($className);
00054
00055
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
00125 $exists = false;
00126
00127
00128 if (is_null($this->getResultInstance())) {
00129
00130 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
00131
00132
00133 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
00134
00135
00136 $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
00137 $criteriaInstance->setLimit(1);
00138
00139
00140 $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
00141
00142
00143 $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId'));
00144
00145
00146 $this->setResultInstance($resultInstance);
00147 }
00148
00149
00150 $this->getResultInstance()->rewind();
00151
00152
00153 if ($this->getResultInstance()->next()) {
00154
00155 $exists = true;
00156 }
00157
00158
00159 return $exists;
00160 }
00161
00167 public function ifEmailAddressExists () {
00168
00169 $exists = false;
00170
00171
00172 if (is_null($this->getResultInstance())) {
00173
00174 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
00175
00176
00177 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
00178
00179
00180 $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_EMAIL, $this->getEmail());
00181 $criteriaInstance->setLimit(1);
00182
00183
00184 $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
00185
00186
00187 $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId'));
00188
00189
00190 $this->setResultInstance($resultInstance);
00191 }
00192
00193
00194 $this->getResultInstance()->rewind();
00195
00196
00197 if ($this->getResultInstance()->next()) {
00198
00199 $exists = true;
00200
00201
00202 if ($this->getUserName() == "") {
00203
00204 $currEntry = $this->getResultInstance()->current();
00205
00206
00207 $this->setUserName($currEntry['username']);
00208 }
00209 }
00210
00211
00212 return $exists;
00213 }
00214
00222 public function ifPasswordHashMatches (Requestable $requestInstance) {
00223
00224 $matches = false;
00225
00226
00227 if (is_null($this->getResultInstance())) {
00228
00229 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
00230
00231
00232 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
00233
00234
00235 $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
00236 $criteriaInstance->setLimit(1);
00237
00238
00239 $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
00240
00241
00242 $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId'));
00243
00244
00245 $this->setResultInstance($resultInstance);
00246 }
00247
00248
00249 $this->getResultInstance()->rewind();
00250
00251
00252 if ($this->getResultInstance()->find('pass_hash')) {
00253
00254
00255 $matches = ($requestInstance->getRequestElement('pass_hash') === $this->getResultInstance()->getFoundValue());
00256 }
00257
00258
00259 return $matches;
00260 }
00261
00267 public final function getPasswordHash () {
00268
00269 $passHash = null;
00270
00271
00272 $entry = $this->getDatabaseEntry();
00273
00274
00275 if (isset($entry['pass_hash'])) {
00276
00277 $passHash = $entry['pass_hash'];
00278 }
00279
00280
00281 return $passHash;
00282 }
00283
00289 public final function getPrimaryKey () {
00290
00291 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
00292
00293
00294 $primaryKey = $wrapperInstance->getPrimaryKeyValue();
00295
00296
00297 $primaryValue = $this->getField($primaryKey);
00298
00299
00300 return $primaryValue;
00301 }
00302
00311 public function updateDatabaseField ($fieldName, $fieldValue) {
00312
00313 if (!$this instanceof Updateable) {
00314
00315 throw new DatabaseUpdateSupportException($this, self::EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED);
00316 }
00317
00318
00319 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
00320
00321
00322 $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
00323 $searchInstance->setLimit(1);
00324
00325
00326 $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
00327
00328
00329 $updateInstance->addCriteria($fieldName, $fieldValue);
00330
00331
00332 $updateInstance->setSearchInstance($searchInstance);
00333
00334
00335 $this->getResultInstance()->add2UpdateQueue($updateInstance);
00336 }
00337 }
00338
00339
00340 ?>