From 1c8f2ab06eaae6ed470d076babfddda633ecc55f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 29 Aug 2009 19:01:54 +0000 Subject: [PATCH] Opening times added (still a lot partial stubs) --- .gitattributes | 8 +- application/ship-simu/config.php | 6 + .../ship-simu/main/bank/class_BaseBank.php | 60 ++++++ .../main/bank/money/class_MoneyBank.php | 94 +++++++++ application/ship-simu/main/opening/.htaccess | 1 + .../ship-simu/main/opening/bank/.htaccess | 1 + .../bank/class_MoneyBankRealtimeOpening.php | 63 ++++++ .../class_MoneyBank.php => opening/class_} | 18 +- .../main/opening/class_BaseOpening.php | 60 ++++++ .../main/user/class_ShipSimuBaseUser.php | 187 +++++++++--------- .../code/action_ship_simu_login_company.ctp | 29 +-- 11 files changed, 408 insertions(+), 119 deletions(-) create mode 100644 application/ship-simu/main/bank/class_BaseBank.php create mode 100644 application/ship-simu/main/bank/money/class_MoneyBank.php create mode 100644 application/ship-simu/main/opening/.htaccess create mode 100644 application/ship-simu/main/opening/bank/.htaccess create mode 100644 application/ship-simu/main/opening/bank/class_MoneyBankRealtimeOpening.php rename application/ship-simu/main/{bank/class_MoneyBank.php => opening/class_} (69%) create mode 100644 application/ship-simu/main/opening/class_BaseOpening.php diff --git a/.gitattributes b/.gitattributes index 97850f8..08601a2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -80,7 +80,8 @@ application/ship-simu/main/actions/web/class_WebShipSimuLoginRefillAction.php -t application/ship-simu/main/actions/web/class_WebShipSimuLoginStatusProblemAction.php -text application/ship-simu/main/actions/web/class_WebShipSimuLoginWelcomeAction.php -text application/ship-simu/main/bank/.htaccess -text -application/ship-simu/main/bank/class_MoneyBank.php -text +application/ship-simu/main/bank/class_BaseBank.php -text +application/ship-simu/main/bank/money/class_MoneyBank.php -text application/ship-simu/main/class_ -text application/ship-simu/main/class_BasePersonell.php -text application/ship-simu/main/class_BaseSimulator.php -text @@ -159,6 +160,11 @@ application/ship-simu/main/menu/class_ShipSimuRegisterMenu.php -text application/ship-simu/main/menu/class_ShipSimuStatusMenu.php -text application/ship-simu/main/menu/government/.htaccess -text application/ship-simu/main/menu/government/class_ShipSimuGovernmentFailedAreaMenu.php -text +application/ship-simu/main/opening/.htaccess -text +application/ship-simu/main/opening/bank/.htaccess -text +application/ship-simu/main/opening/bank/class_MoneyBankRealtimeOpening.php -text +application/ship-simu/main/opening/class_ -text +application/ship-simu/main/opening/class_BaseOpening.php -text application/ship-simu/main/parts/.htaccess -text application/ship-simu/main/parts/class_BaseShipPart.php -text application/ship-simu/main/parts/maschineroom/.htaccess -text diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index 1c7a25d..d79be7e 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -520,5 +520,11 @@ $cfg->setConfigEntry('login_area_menu_class', 'ShipSimuLoginAreaMenu'); // CFG: GOVERNMENT-FAILED-AREA-MENU-CLASS $cfg->setConfigEntry('government_failed_area_menu_class', 'ShipSimuGovernmentFailedAreaMenu'); +// CFG: MONEYBANK-ACTIVATED +$cfg->setConfigEntry('moneybank_activated', 'Y'); + +// CFG: MONEYBANK-OPENING-CLASS +$cfg->setConfigEntry('moneybank_opening_class', 'MoneyBankRealtimeOpening'); + // [EOF] ?> diff --git a/application/ship-simu/main/bank/class_BaseBank.php b/application/ship-simu/main/bank/class_BaseBank.php new file mode 100644 index 0000000..1eaecfa --- /dev/null +++ b/application/ship-simu/main/bank/class_BaseBank.php @@ -0,0 +1,60 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * @todo Find an instance for all banks and move the abstract functions there + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +abstract class BaseBank extends BaseFrameworkSystem { + /** + * Protected constructor + * + * @param $className The class' real name + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Checks wether the bank lends more money to the current user + * + * @return $lendsMoreMoney Wether this bank lends more money to the user + */ + public abstract function ifBankLendsMoreMoney (); + + /** + * Checks wethert the current user has maximum allowed credits with this bank + * + * @return $hasMaximumCredits Wether the user has maximum allowed credits + */ + public abstract function ifUserHasMaxCredits (); + + /** + * Checks wether this money bank has opened + * + * @return $hasOpened Wether this money bank has opened + */ + public abstract function ifMoneyBankHasOpened (); +} + +// [EOF] +?> diff --git a/application/ship-simu/main/bank/money/class_MoneyBank.php b/application/ship-simu/main/bank/money/class_MoneyBank.php new file mode 100644 index 0000000..1e9a510 --- /dev/null +++ b/application/ship-simu/main/bank/money/class_MoneyBank.php @@ -0,0 +1,94 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class MoneyBank extends BaseBank implements Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this money bank class + * + * @param $userInstance A class instance of a user object + * @return $bankInstance An instance of this class + */ + public final static function createMoneyBank (ManageableAccount $userInstance) { + // Get a new instance + $moneyInstance = new MoneyBank(); + + // Set the user instance + $moneyInstance->setUserInstance($userInstance); + + // Return the prepared instance + return $moneyInstance; + } + + /** + * Checks wether the bank lends more money to the current user + * + * @return $lendsMoreMoney Wether this bank lends more money to the user + */ + public function ifBankLendsMoreMoney () { + $this->partialStub(); + } + + /** + * Checks wethert the current user has maximum allowed credits with this bank + * + * @return $hasMaximumCredits Wether the user has maximum allowed credits + */ + public function ifUserHasMaxCredits () { + $this->partialStub(); + } + + /** + * Checks wether this money bank has opened + * + * @return $hasOpened Wether this money bank has opened + */ + public function ifMoneyBankHasOpened () { + // Has not opened by default + $hasOpened = false; + + // Is the money bank activated in config? + if ($this->getConfigInstance()->getConfigEntry('moneybank_activated')) { + // Okay, does the user ask within the opening times? To find this out we need a OpeningTimes class + $openingInstance = ObjectFactory::createObjectByConfiguredName('moneybank_opening_class', array($this)); + + // Then we simply "ask" the opening time instance if the user asks within the opening time + $hasOpened = $openingInstance->ifWithinOpeningTimes(); + } // END - if + + // Return status + return $hasOpened; + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/opening/.htaccess b/application/ship-simu/main/opening/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/ship-simu/main/opening/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/ship-simu/main/opening/bank/.htaccess b/application/ship-simu/main/opening/bank/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/ship-simu/main/opening/bank/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/ship-simu/main/opening/bank/class_MoneyBankRealtimeOpening.php b/application/ship-simu/main/opening/bank/class_MoneyBankRealtimeOpening.php new file mode 100644 index 0000000..752d5b7 --- /dev/null +++ b/application/ship-simu/main/opening/bank/class_MoneyBankRealtimeOpening.php @@ -0,0 +1,63 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class MoneyBankRealtimeOpening extends BaseOpening { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this opening time class + * + * @param $bankInstance An instance of a money bank + * @return $openeningInstance An instance of this class + */ + public final static function createMoneyBankRealtimeOpening (BaseBank $bankInstance) { + // Get a new instance + $openingInstance = new MoneyBankRealtimeOpening(); + + // Set the bank instance here + $openingInstance->setBankInstance($bankInstance); + + // Return the prepared instance + return $openingInstance; + } + + /** + * Checks wether we are within the opening times + * + * @return $withinOpeningTimes Wether we are within opening times + */ + public function ifWithinOpeningTimes () { + $this->partialStub(); + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/bank/class_MoneyBank.php b/application/ship-simu/main/opening/class_ similarity index 69% rename from application/ship-simu/main/bank/class_MoneyBank.php rename to application/ship-simu/main/opening/class_ index a065f35..b9f1ce7 100644 --- a/application/ship-simu/main/bank/class_MoneyBank.php +++ b/application/ship-simu/main/opening/class_ @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class MoneyBank extends BaseFrameworkSystem implements Registerable { +class ???Opening extends BaseOpening { /** * Protected constructor * @@ -33,20 +33,16 @@ class MoneyBank extends BaseFrameworkSystem implements Registerable { } /** - * Creates an instance of this money bank class + * Creates an instance of this opening time class * - * @param $userInstance A class instance of a user object - * @return $bankInstance An instance of this class + * @return $openeningInstance An instance of this class */ - public final static function createMoneyBank (ManageableAccount $userInstance) { + public final static function create???Opening () { // Get a new instance - $moneyInstance = new MoneyBank(); - - // Set the user instance - $moneyInstance->setUserInstance($userInstance); + $openeningInstance = new ???Opening(); // Return the prepared instance - return $moneyInstance; + return $openeningInstance; } } diff --git a/application/ship-simu/main/opening/class_BaseOpening.php b/application/ship-simu/main/opening/class_BaseOpening.php new file mode 100644 index 0000000..b37a1e9 --- /dev/null +++ b/application/ship-simu/main/opening/class_BaseOpening.php @@ -0,0 +1,60 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +abstract class BaseOpening extends BaseFrameworkSystem { + /** + * A bank instance + */ + private $bankInstance = null; + + /** + * Protected constructor + * + * @param $className The class' real name + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Setter for bank instance + * + * @param $bankInstance An instance of a bank + * @return void + */ + protected final function setBankInstance (BaseBank $bankInstance) { + $this->bankInstance = $bankInstance; + } + + /** + * Checks wether we are within the opening times + * + * @return $withinOpeningTimes Wether we are within opening times + */ + public abstract function ifWithinOpeningTimes (); +} + +// [EOF] +?> 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] diff --git a/application/ship-simu/templates/de/code/action_ship_simu_login_company.ctp b/application/ship-simu/templates/de/code/action_ship_simu_login_company.ctp index 6e824d4..680dc55 100644 --- a/application/ship-simu/templates/de/code/action_ship_simu_login_company.ctp +++ b/application/ship-simu/templates/de/code/action_ship_simu_login_company.ctp @@ -43,20 +43,27 @@ if ($linkInstance->getValueInstance()->ifUserHasRequiredPoints('write_applicatio $linkInstance->addLinkNote('government_depleted', "Leider kann dir der Staat nicht mehr weiterhelfen, dich zu bewerben, da du zu oft Starthilfen erhalten hast oder ein Training absolviert hast. Hier muss aber noch weiter am Spiel gearbeitet werden. :-)"); } -// Add link group for money bank -$linkInstance->addLinkGroup('moneybank', "Leihe dir zu günstigen Zinsen virtuelles Geld aus, wenn du mehr brauchst!"); +// Checks wether the money bank has opened +if ($linkInstance->getValueInstance()->ifMoneyBankHasOpened()) { + // Add link group for money bank + $linkInstance->addLinkGroup('moneybank', "Leihe dir zu günstigen Zinsen virtuelles Geld aus, wenn du mehr brauchst!"); -// Add link to moneybank -if ($linkInstance->getValueInstance()->ifUserAllowedTakeCreditsFromMoneyBank()) { - // Display link to money bank page - $linkInstance->addActionLinkById('moneybank', 'virtual_money_bank'); -} elseif ($linkInstance->getValueInstance()->ifUserHasMaximumCreditsWithMoneyBank()) { - // Maximum credits reached which a money bank can lent - $linkInstance->addLinkNote('moneybank_depleted', "Die Bank kann dir kein Geld mehr leihen, bitte zahle es auch wieder zurück."); - $linkInstance->addActionLinkById('moneybank_payback_credits', 'payback_credits_to_money_bank'); + // Add link to moneybank + if ($linkInstance->getValueInstance()->ifUserAllowedTakeCreditsFromMoneyBank()) { + // Display link to money bank page + $linkInstance->addActionLinkById('moneybank', 'virtual_money_bank'); + } elseif ($linkInstance->getValueInstance()->ifUserHasMaximumCreditsWithMoneyBank()) { + // Maximum credits reached which a money bank can lent + $linkInstance->addLinkNote('moneybank_depleted', "Die Spielebank kann dir kein Geld mehr leihen, bitte zahle es auch wieder zurück."); + $linkInstance->addActionLinkById('moneybank_payback_credits', 'payback_credits_to_money_bank'); + } else { + // Unexpected state of the bank + $linkInstance->addLinkNote('moneybank_error', "Es wurde ein Fehler in der Spielebank erkannt. Bitte melde dies dem Support."); + } } else { // Money bank is closed! - $linkInstance->addLinkNote('moneybank_closed', "Die Bank hat derzeit geschlossen. Bitte später nochmal versuchen."); + $linkInstance->addLinkGroup('moneybank', "Die Spielebank hat geschlossen."); + $linkInstance->addLinkNote('moneybank_closed', "Die Spielebank hat derzeit geschlossen. Bitte später nochmal versuchen."); } // Add link group for refill page -- 2.39.2