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
*
// 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;
// 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;
// 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;
// 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]