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