X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=application%2Fship-simu%2Fmain%2Fuser%2Fclass_ShipSimuBaseUser.php;h=e26db54f429c68f068934b4122ec0cf44c6266d6;hp=5f61809a5451519e7ec93b6f3b23f6389db4b6f4;hb=1c8f2ab06eaae6ed470d076babfddda633ecc55f;hpb=0b254c676d73023adb26274ecdc45d7ac9a151fa diff --git a/application/ship-simu/main/user/class_ShipSimuBaseUser.php b/application/ship-simu/main/user/class_ShipSimuBaseUser.php index 5f61809..e26db54 100644 --- a/application/ship-simu/main/user/class_ShipSimuBaseUser.php +++ b/application/ship-simu/main/user/class_ShipSimuBaseUser.php @@ -33,6 +33,66 @@ class ShipSimuBaseUser extends BaseUser implements Registerable, Updateable { parent::__construct($className); } + /** + * Initializes the bank instance + * + * @return $bankInstance A bank instance wether just created or from registry + */ + protected function initBankInstance () { + // Init instance + $bankInstance = null; + + try { + // Get a money bank instance from registry + $bankInstance = Registry::getRegistry()->getInstance('money_bank'); + } catch (NullPointerException $e) { + // Instance not found in registry + // @TODO We should log this exception later + } + + // Is it there? + if (is_null($bankInstance)) { + // Then create a new one + $bankInstance = ObjectFactory::createObjectByConfiguredName('bank_class', array($this)); + + // Store it in registry + Registry::getRegistry()->addInstance('money_bank', $bankInstance); + } // END - if + + // Return the instance + return $bankInstance; + } + + /** + * Initializes the government instance + * + * @return $governmentInstance A government instance + */ + protected function initGovernmentInstance () { + // Init instance + $governmentInstance = null; + + try { + // First get a government instance from registry + $governmentInstance = Registry::getRegistry()->getInstance('government'); + } catch (NullPointerException $e) { + // Instance not found in registry + // @TODO We should log this exception later + } + + // Is it there? + if (is_null($governmentInstance)) { + // Then create a new one + $governmentInstance = ObjectFactory::createObjectByConfiguredName('government_class', array($this)); + + // Store it in registry + Registry::getRegistry()->addInstance('government', $governmentInstance); + } // END - if + + // Return the prepared instance + return $governmentInstance; + } + /** * Checks wether the user has reached maximum allowed companies to found * @@ -106,31 +166,11 @@ class ShipSimuBaseUser extends BaseUser implements Registerable, Updateable { // By default they want to help. $ifGovHelps = true; - // Init instance - $governmentInstance = null; - - try { - // First get a government instance from registry - $governmentInstance = Registry::getRegistry()->getInstance('government'); - } catch (NullPointerException $e) { - // Instance not found in registry - // @TODO We should log this exception later - } - - // Is it there? - if (is_null($governmentInstance)) { - // Then create a new one - $governmentInstance = ObjectFactory::createObjectByConfiguredName('government_class', array($this)); - - // Store it in registry - Registry::getRegistry()->addInstance('government', $governmentInstance); - } // END - if + // Initialize government instance + $governmentInstance = $this->initGovernmentInstance(); // Then ask the government if they want to pay a "startup help" to the user - if ($governmentInstance->ifGovernmentAlreadyPayedTraining()) { - // Training already given! - $ifGovHelps = false; - } // END - if + $ifGovHelps = ($governmentInstance->ifGovernmentAlreadyPayedTraining()); // Return result here return $ifGovHelps; @@ -145,31 +185,11 @@ class ShipSimuBaseUser extends BaseUser implements Registerable, Updateable { // By default they want to help. $ifGovHelps = true; - // Init instance - $governmentInstance = null; - - try { - // First get a government instance from registry - $governmentInstance = Registry::getRegistry()->getInstance('government'); - } catch (NullPointerException $e) { - // Instance not found in registry - // @TODO We should log this exception later - } - - // Is it there? - if (is_null($governmentInstance)) { - // Then create a new one - $governmentInstance = ObjectFactory::createObjectByConfiguredName('government_class', array($this)); - - // Store it in registry - Registry::getRegistry()->addInstance('government', $governmentInstance); - } // END - if + // Initialize government instance + $governmentInstance = $this->initGovernmentInstance(); // Then ask the government if they want to pay a "startup help" to the user - if ($governmentInstance->ifGovernmentPayedMaxmimumStartupHelp()) { - // They can't pay anymore to the user (excited amount) - $ifGovHelps = false; - } // END - if + $ifGovHelps = ($governmentInstance->ifGovernmentPayedMaxmimumStartupHelp()); // Return result here return $ifGovHelps; @@ -185,33 +205,11 @@ class ShipSimuBaseUser extends BaseUser implements Registerable, Updateable { // Per default the money bank cannot pay $bankLends = false; - // Init instance - $bankInstance = null; - - try { - // Get a money bank instance from registry - $bankInstance = Registry::getRegistry()->getInstance('money_bank'); - } catch (NullPointerException $e) { - // Instance not found in registry - // @TODO We should log this exception later - } - - // Is it there? - if (is_null($bankInstance)) { - // Then create a new one - $bankInstance = ObjectFactory::createObjectByConfiguredName('bank_class', array($this)); - - // Store it in registry - Registry::getRegistry()->addInstance('money_bank', $bankInstance); - } // END - if + // Initialize bank instance + $bankInstance->initBankInstance(); // Does the money bank lend more money? - /* UNFINISED: - if ($bankInstance->ifBankLendsMoreMoney()) { - // Okay, that they will do - $bankLends = true; - } // END - if - */ + $bankLends = ($bankInstance->ifBankLendsMoreMoney()); // Return result return $bankLends; @@ -229,37 +227,34 @@ class ShipSimuBaseUser extends BaseUser implements Registerable, Updateable { // For default he can still get money $hasMaxCredits = false; - // Init instance - $bankInstance = null; - - try { - // Get a money bank instance from registry - $bankInstance = Registry::getRegistry()->getInstance('money_bank'); - } catch (NullPointerException $e) { - // Instance not found in registry - // @TODO We should log this exception later - } - - // Is it there? - if (is_null($bankInstance)) { - // Then create a new one - $bankInstance = ObjectFactory::createObjectByConfiguredName('bank_class', array($this)); - - // Store it in registry - Registry::getRegistry()->addInstance('money_bank', $bankInstance); - } // END - if + // Initialize the bank instance + $bankInstance = $this->initBankInstance(); // Now check if the user has maximum credits - /** UNFINISHED PART! - if ($bankInstance->ifUserHasMaxCredits()) { - // Yes, he does! - $hasMaxCredits = true; - } // END - if - */ + $hasMaxCredits = ($bankInstance->ifUserHasMaxCredits()); // Return the result return $hasMaxCredits; } + + /** + * Checks wether the money bank has opened + * + * @return $hasOpened Wether the money bank has opened + */ + public function ifMoneyBankHasOpened () { + // Default is not opened + $hasOpened = false; + + // Initialize the bank instance + $bankInstance = $this->initBankInstance(); + + // Has this bank opened? + $hasOpened = ($bankInstance->ifMoneyBankHasOpened()); + + // Return result + return $hasOpened; + } } // [EOF]