class_Member.php

Go to the documentation of this file.
00001 <?php
00024 class Member extends BaseUser implements ManageableMember, Registerable, Updateable {
00030         protected function __construct () {
00031                 // Call parent constructor
00032                 parent::__construct(__CLASS__);
00033         }
00034 
00040         public function __destruct () {
00041                 // Flush any updated entries to the database
00042                 $this->flushPendingUpdates();
00043 
00044                 // Call parent destructor
00045                 parent::__destruct();
00046         }
00047 
00057         public final static function createMemberByUsername ($userName) {
00058                 // Get a new instance
00059                 $userInstance = new Member();
00060 
00061                 // Set the username
00062                 $userInstance->setUserName($userName);
00063 
00064                 // Check if username exists
00065                 if ($userInstance->ifUsernameExists() === false) {
00066                         // Throw an exception here
00067                         throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
00068                 } // END - if
00069 
00070                 // Return the instance
00071                 return $userInstance;
00072         }
00073 
00081         public final static function createMemberByEmail ($email) {
00082                 // Get a new instance
00083                 $userInstance = new Member();
00084 
00085                 // Set the username
00086                 $userInstance->setEmail($email);
00087 
00088                 // Return the instance
00089                 return $userInstance;
00090         }
00091 
00099         public final static function createMemberByRequest (Requestable $requestInstance) {
00100                 // Determine if by email or username
00101                 if (!is_null($requestInstance->getRequestElement('username'))) {
00102                         // Username supplied
00103                         $userInstance = self::createMemberByUserName($requestInstance->getRequestElement('username'));
00104                 } elseif (!is_null($requestInstance->getRequestElement('email'))) {
00105                         // Email supplied
00106                         $userInstance = self::createMemberByEmail($requestInstance->getRequestElement('email'));
00107                 } else {
00108                         // Unsupported mode
00109                         $userInstance = new Member();
00110                         $userInstance->partialStub("We need to add more ways of creating user classes here.");
00111                         $userInstance->debugBackTrace();
00112                         exit();
00113                 }
00114 
00115                 // Return the prepared instance
00116                 return $userInstance;
00117         }
00118 
00127         public function updateLastActivity (Requestable $requestInstance) {
00128                 // Set last action
00129                 $lastAction = $requestInstance->getRequestElement('action');
00130 
00131                 // If there is no action use the default on
00132                 if (is_null($lastAction)) {
00133                         $lastAction = $this->getConfigInstance()->readConfig('login_default_action');
00134                 } // END - if
00135 
00136                 // Get a critieria instance
00137                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
00138 
00139                 // Add search criteria
00140                 $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
00141                 $searchInstance->setLimit(1);
00142 
00143                 // Now get another criteria
00144                 $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
00145 
00146                 // And add our both entries
00147                 $updateInstance->addCriteria("last_activity", date("Y-m-d H:i:s", time()));
00148                 $updateInstance->addCriteria("last_action", $lastAction);
00149 
00150                 // Add the search criteria for searching for the right entry
00151                 $updateInstance->setSearchInstance($searchInstance);
00152 
00153                 // Remember the update in database result
00154                 $this->getResultInstance()->add2UpdateQueue($updateInstance);
00155         }
00156 
00162         public function flushPendingUpdates () {
00163                 // Do we have data to update?
00164                 if ($this->getResultInstance()->ifDataNeedsFlush()) {
00165                         // Get a database wrapper
00166                         $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
00167 
00168                         // Yes, then send the whole result to the database layer
00169                         $wrapperInstance->doUpdateByResult($this->getResultInstance());
00170                 } // END - if
00171         }
00172 }
00173 
00174 // [EOF]
00175 ?>

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