class_ShipSimuBaseUser.php

Go to the documentation of this file.
00001 <?php
00024 class ShipSimuBaseUser extends BaseUser implements Registerable, Updateable {
00031         protected function __construct ($className) {
00032                 // Call parent constructor
00033                 parent::__construct($className);
00034         }
00035 
00041         public function ifUserCreatedMaximumAllowedCompanies () {
00042                 // Get max allowed companies to found
00043                 $maxFound = $this->getConfigInstance()->readConfig('max_allowed_companies_found');
00044 
00045                 // Now get a search criteria and set the user's name as criteria
00046                 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
00047                 $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
00048                 $criteriaInstance->setLimit($maxFound);
00049 
00050                 // Get a company wrapper
00051                 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class');
00052 
00053                 // Do the count-select by criteria
00054                 $totalRows = $wrapperInstance->doSelectCountByCriteria($criteriaInstance);
00055 
00056                 // Does the user have reached maximum?
00057                 $reached = ($totalRows >= $maxFound);
00058 
00059                 // Return the result
00060                 return $reached;
00061         }
00062 
00069         public function ifUserHasRequiredPoints ($action) {
00070                 // Default is that everyone is poor... ;-)
00071                 $hasRequired = false;
00072 
00073                 // Get a points instance from registry
00074                 $pointsInstance = Registry::getRegistry()->getInstance('points');
00075 
00076                 // Is there an instance?
00077                 if (is_null($pointsInstance)) {
00078                         // Then create one
00079                         $pointsInstance = ObjectFactory::createObjectByConfiguredName('user_ppints_class', array($this));
00080 
00081                         // And store it in registry
00082                         Registry::getRegistry()->addInstance('points', $pointsInstance);
00083                 } // END - if
00084 
00085                 // Just forward this request to the user points class
00086                 $hasRequired = $pointsInstance->ifUserHasRequiredPoints($action);
00087 
00088                 // Return the result
00089                 return $hasRequired;
00090         }
00091 
00097         public function ifGovernmentPaysTraining () {
00098                 // By default they want to help.
00099                 $ifGovHelps = true;
00100 
00101                 // First get a government instance from registry
00102                 $governmentInstance = Registry::getRegistry()->getInstance('government');
00103 
00104                 // Is it there?
00105                 if (is_null($governmentInstance)) {
00106                         // Then create a new one
00107                         $governmentInstance = ObjectFactory::createObjectByConfiguredName('government_class', array($this));
00108 
00109                         // Store it in registry
00110                         Registry::getRegistry()->addInstance('government', $governmentInstance);
00111                 } // END - if
00112 
00113                 // Then ask the government if they want to pay a "startup help" to the user
00114                 if ($governmentInstance->ifGovernmentAlreadyPayedTraining()) {
00115                         // Training already given!
00116                         $ifGovHelps = false;
00117                 } // END - if
00118 
00119                 // Return result here
00120                 return $ifGovHelps;
00121         }
00122 
00128         public function ifGovernmentPaysStartupHelp () {
00129                 // By default they want to help.
00130                 $ifGovHelps = true;
00131 
00132                 // First get a government instance from registry
00133                 $governmentInstance = Registry::getRegistry()->getInstance('government');
00134 
00135                 // Is it there?
00136                 if (is_null($governmentInstance)) {
00137                         // Then create a new one
00138                         $governmentInstance = ObjectFactory::createObjectByConfiguredName('government_class', array($this));
00139 
00140                         // Store it in registry
00141                         Registry::getRegistry()->addInstance('government', $governmentInstance);
00142                 } // END - if
00143 
00144                 // Then ask the government if they want to pay a "startup help" to the user
00145                 if ($governmentInstance->ifGovernmentPayedMaxmimumStartupHelp()) {
00146                         // They can't pay anymore to the user (excited amount)
00147                         $ifGovHelps = false;
00148                 } // END - if
00149 
00150                 // Return result here
00151                 return $ifGovHelps;
00152         }
00153 
00160         public function ifUserAllowedTakeCreditsFromMoneyBank () {
00161                 // Per default the money bank cannot pay
00162                 $bankLends = false;
00163 
00164                 // Get a money bank instance from registry
00165                 $bankInstance = Registry::getRegistry()->getInstance('money_bank');
00166 
00167                 // Is it there?
00168                 if (is_null($bankInstance)) {
00169                         // Then create a new one
00170                         $bankInstance = ObjectFactory::createObjectByConfiguredName('bank_class', array($this));
00171 
00172                         // Store it in registry
00173                         Registry::getRegistry()->addInstance('money_bank', $bankInstance);
00174                 } // END - if
00175 
00176                 // Does the money bank lend more money?
00177                 /* UNFINISED:
00178                 if ($bankInstance->ifBankLendsMoreMoney()) {
00179                         // Okay, that they will do
00180                         $bankLends = true;
00181                 } // END - if
00182                 */
00183 
00184                 // Return result
00185                 return $bankLends;
00186         }
00187 
00196         public function ifUserHasMaximumCreditsWithMoneyBank () {
00197                 // For default he can still get money
00198                 $hasMaxCredits = false;
00199 
00200                 // Get a money bank instance from registry
00201                 $bankInstance = Registry::getRegistry()->getInstance('money_bank');
00202 
00203                 // Is it there?
00204                 if (is_null($bankInstance)) {
00205                         // Then create a new one
00206                         $bankInstance = ObjectFactory::createObjectByConfiguredName('bank_class', array($this));
00207 
00208                         // Store it in registry
00209                         Registry::getRegistry()->addInstance('money_bank', $bankInstance);
00210                 } // END - if
00211 
00212                 // Now check if the user has maximum credits
00220                 // Return the result
00221                 return $hasMaxCredits;
00222         }
00223 }
00224 
00225 // [EOF]
00226 ?>

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