From 968aa514d2df8ed98dab8ff251ee83c95f1ac182 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 1 Jul 2008 20:08:45 +0000 Subject: [PATCH] More game classes added: - Class for simplified goverment added (all-in-one goverment!) - Special classes for Ship-Simu added with game-specific methods - Template for company page rewritten - Method moved from FrameworkInterface to Updateable - Database wrapper classes added for user points - Generic class UserPoints added --- .gitattributes | 12 ++ application/ship-simu/config.php | 24 +++ application/ship-simu/main/bank/.htaccess | 1 + .../ship-simu/main/bank/class_MoneyBank.php | 64 ++++++ application/ship-simu/main/class_ | 19 +- .../main/companies/class_ShippingCompany.php | 8 +- .../ship-simu/main/goverment/.htaccess | 1 + .../main/goverment/class_SimpleGoverment.php | 64 ++++++ .../main/user/class_ShipSimuBaseUser.php | 189 ++++++++++++++++++ .../ship-simu/main/user/extended/.htaccess | 1 + .../user/extended/class_ShipSimuGuest.php | 117 +++++++++++ .../user/extended/class_ShipSimuMember.php | 171 ++++++++++++++++ .../wrapper/class_CompanyDatabaseWrapper.php | 35 +++- .../de/code/action_login_company.ctp | 6 +- db/user_points/.htaccess | 1 + .../interfaces/class_FrameworkInterface.php | 10 - .../interfaces/database/class_Updateable.php | 9 + .../main/class_BaseFrameworkSystem.php | 84 ++------ .../wrapper/class_NewsDatabaseWrapper.php | 2 +- .../class_UserPointsDatabaseWrapper.php | 62 ++++++ .../main/helper/web/class_BaseWebHelper.php | 11 + inc/classes/main/points/.htaccess | 1 + inc/classes/main/points/class_UserPoints.php | 98 +++++++++ inc/classes/main/user/class_BaseUser.php | 35 ++++ 24 files changed, 941 insertions(+), 84 deletions(-) create mode 100644 application/ship-simu/main/bank/.htaccess create mode 100644 application/ship-simu/main/bank/class_MoneyBank.php create mode 100644 application/ship-simu/main/goverment/.htaccess create mode 100644 application/ship-simu/main/goverment/class_SimpleGoverment.php create mode 100644 application/ship-simu/main/user/class_ShipSimuBaseUser.php create mode 100644 application/ship-simu/main/user/extended/.htaccess create mode 100644 application/ship-simu/main/user/extended/class_ShipSimuGuest.php create mode 100644 application/ship-simu/main/user/extended/class_ShipSimuMember.php create mode 100644 db/user_points/.htaccess create mode 100644 inc/classes/main/database/wrapper/class_UserPointsDatabaseWrapper.php create mode 100644 inc/classes/main/points/.htaccess create mode 100644 inc/classes/main/points/class_UserPoints.php diff --git a/.gitattributes b/.gitattributes index 4efc684..b3e2035 100644 --- a/.gitattributes +++ b/.gitattributes @@ -103,6 +103,8 @@ application/ship-simu/main/actions/ship-simu/class_ShipSimuLoginAction.php -text application/ship-simu/main/actions/ship-simu/class_ShipSimuProfileAction.php -text application/ship-simu/main/actions/web/.htaccess -text application/ship-simu/main/actions/web/class_WebLoginCompanyAction.php -text +application/ship-simu/main/bank/.htaccess -text +application/ship-simu/main/bank/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 @@ -134,6 +136,8 @@ application/ship-simu/main/drives/motor/.htaccess -text application/ship-simu/main/drives/motor/class_Motor.php -text application/ship-simu/main/factories/.htaccess -text application/ship-simu/main/factories/class_ShipSimuWebNewsFactory.php -text +application/ship-simu/main/goverment/.htaccess -text +application/ship-simu/main/goverment/class_SimpleGoverment.php -text application/ship-simu/main/login/.htaccess -text application/ship-simu/main/login/class_ShipSimuGuestLogin.php -text application/ship-simu/main/login/class_ShipSimuUserLogin.php -text @@ -177,8 +181,12 @@ application/ship-simu/main/structures/extended/lower/.htaccess -text application/ship-simu/main/structures/extended/upper/.htaccess -text application/ship-simu/main/structures/extended/upper/class_Bridge.php -text application/ship-simu/main/user/.htaccess -text +application/ship-simu/main/user/class_ShipSimuBaseUser.php -text application/ship-simu/main/user/class_ShipSimuGuest.php -text application/ship-simu/main/user/class_ShipSimuMember.php -text +application/ship-simu/main/user/extended/.htaccess -text +application/ship-simu/main/user/extended/class_ShipSimuGuest.php -text +application/ship-simu/main/user/extended/class_ShipSimuMember.php -text application/ship-simu/main/wrapper/.htaccess -text application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php -text application/ship-simu/starter.php -text @@ -219,6 +227,7 @@ db/.htaccess -text db/company_user/.htaccess -text db/news/.htaccess -text db/user/.htaccess -text +db/user_points/.htaccess -text devel/.htaccess -text devel/class_Debug.php -text docs/COPYING -text @@ -495,6 +504,7 @@ inc/classes/main/database/databases/class_LocalFileDatabase.php -text inc/classes/main/database/wrapper/.htaccess -text inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php -text inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php -text +inc/classes/main/database/wrapper/class_UserPointsDatabaseWrapper.php -text inc/classes/main/debug/.htaccess -text inc/classes/main/debug/class_DebugConsoleOutput.php -text inc/classes/main/debug/class_DebugErrorLogOutput.php -text @@ -589,6 +599,8 @@ inc/classes/main/mailer/debug/class_DebugMailer.php -text inc/classes/main/output/.htaccess -text inc/classes/main/output/class_ConsoleOutput.php -text inc/classes/main/output/class_WebOutput.php -text +inc/classes/main/points/.htaccess -text +inc/classes/main/points/class_UserPoints.php -text inc/classes/main/reader/.htaccess -text inc/classes/main/reader/class_DefaultNewsReader.php -text inc/classes/main/registration/.htaccess -text diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index 242de41..51e2695 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -232,6 +232,9 @@ $cfg->setConfigEntry('company_class', "ShippingCompany"); // CFG: COMPANY-DB-WRAPPER-CLASS $cfg->setConfigEntry('company_db_wrapper_class', "CompanyDatabaseWrapper"); +// CFG: USER-POINTS-DB-WRAPPER-CLASS +$cfg->setConfigEntry('user_points_db_wrapper_class', "UserPointsDatabaseWrapper"); + // CFG EMAIl-TPL-RESEND-LINK $cfg->setConfigEntry('email_tpl_resend_link', "text"); @@ -250,5 +253,26 @@ $cfg->setConfigEntry('user_class', "ShipSimuMember"); // CFG: GUEST-CLASS $cfg->setConfigEntry('guest_class', "ShipSimuGuest"); +// CFG: MAX-ALLOWED-COMPANIES-FOUND +$cfg->setConfigEntry('max_allowed_companies_found', 10); + +// CFG: FOUND-NEW-COMPANY-ACTION-POINTS +$cfg->setConfigEntry('found_new_company_action_points', 1000000); + +// CFG: WRITE-APPLICATION-ACTION-POINTS +$cfg->setConfigEntry('write_applications_action_points', 10000); + +// CFG: USER-POINTS-CLASS +$cfg->setConfigEntry('user_ppints_class', "UserPoints"); + +// CFG: GOVERMENT-CLASS +$cfg->setConfigEntry('goverment_class', "SimpleGoverment"); + +// CFG: BANK-CLASS +$cfg->setConfigEntry('bank_class', "MoneyBank"); + +// CFG: REFILL-PAGE-ACTIVE +$cfg->setConfigEntry('refill_page_active', "Y"); + // [EOF] ?> diff --git a/application/ship-simu/main/bank/.htaccess b/application/ship-simu/main/bank/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/ship-simu/main/bank/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/ship-simu/main/bank/class_MoneyBank.php b/application/ship-simu/main/bank/class_MoneyBank.php new file mode 100644 index 0000000..0436549 --- /dev/null +++ b/application/ship-simu/main/bank/class_MoneyBank.php @@ -0,0 +1,64 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software + * @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 BaseFrameworkSystem implements Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A money bank class"); + + // Create unique ID number + $this->generateUniqueId(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * 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; + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/class_ b/application/ship-simu/main/class_ index 4e1385b..2d6541c 100644 --- a/application/ship-simu/main/class_ +++ b/application/ship-simu/main/class_ @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class extends BaseFrameworkSystem { +class ??? extends BaseFrameworkSystem { /** * Protected constructor * @@ -41,6 +41,23 @@ class extends BaseFrameworkSystem { $this->removeNumberFormaters(); $this->removeSystemArray(); } + + /** + * 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 create??? (ManageableAccount $userInstance) { + // Get a new instance + $moneyInstance = new ???(); + + // Set the user instance + $moneyInstance->setUserInstance($userInstance); + + // Return the prepared instance + return $moneyInstance; + } } // [EOF] diff --git a/application/ship-simu/main/companies/class_ShippingCompany.php b/application/ship-simu/main/companies/class_ShippingCompany.php index 7549af4..971c578 100644 --- a/application/ship-simu/main/companies/class_ShippingCompany.php +++ b/application/ship-simu/main/companies/class_ShippingCompany.php @@ -120,7 +120,7 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner $participates = false; // Get a company database wrapper class - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class'); + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class', array($this)); // Ask the wrapper if this user participates $participates = $wrapperInstance->ifUserParticipatesInCompany($userInstance); @@ -204,9 +204,9 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner return $isEmployee; } - //---------------------------------------------------------------------------- - // From here is very old code which needs to be translated and changed heavily - //---------------------------------------------------------------------------- + //------------------------------------------------------------------------------\ + // Below here is very old code which needs to be translated and changed heavily | + //------------------------------------------------------------------------------/ /** * Intialize all lists diff --git a/application/ship-simu/main/goverment/.htaccess b/application/ship-simu/main/goverment/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/ship-simu/main/goverment/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/ship-simu/main/goverment/class_SimpleGoverment.php b/application/ship-simu/main/goverment/class_SimpleGoverment.php new file mode 100644 index 0000000..68882be --- /dev/null +++ b/application/ship-simu/main/goverment/class_SimpleGoverment.php @@ -0,0 +1,64 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software + * @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 SimpleGoverment extends BaseFrameworkSystem implements Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A class for simplified goverment"); + + // Create unique ID number + $this->generateUniqueId(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this goverment class by given user instance + * + * @param $userInstance The user instance + * @return $govermentInstance Instance of the prepared goverment instance + */ + public final static function createSimpleGoverment (ManageableAccount $userInstance) { + // Get a new instance + $govermentInstance = new SimpleGoverment(); + + // Set the user instance + $govermentInstance->setUserInstance($userInstance); + + // Return the prepared instance + return $govermentInstance; + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/user/class_ShipSimuBaseUser.php b/application/ship-simu/main/user/class_ShipSimuBaseUser.php new file mode 100644 index 0000000..563c968 --- /dev/null +++ b/application/ship-simu/main/user/class_ShipSimuBaseUser.php @@ -0,0 +1,189 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software + * @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 ShipSimuBaseUser extends BaseUser implements Registerable, Updateable { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Checks wether the user has reached maximum allowed companies to found + * + * @return $reached Wether the user has reached maximum allowed companies to found + */ + public function ifUserCreatedMaximumAllowedCompanies () { + // Get max allowed companies to found + $maxFound = $this->getConfigInstance()->readConfig('max_allowed_companies_found'); + + // Get a company wrapper + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class'); + + // Now get a search criteria and set the user's name as criteria + $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName()); + $criteriaInstance->setLimit($maxFound); + + // Do the count-select by criteria + $totalRows = $wrapperInstance->doSelectCountByCriteria($criteriaInstance); + + // Does the user have reached maximum? + $reached = ($totalRows >= $maxFound); + + // Return the result + return $reached; + } + + /** + * Checks wether the user has the required amount of points left for the specified action + * + * @param $action The action or configuration entry plus prefix the user wants to perform + * @return $hasRequired Wether the user has the required points + */ + public function ifUserHasRequiredPoints ($action) { + // Default is that everyone is poor... ;-) + $hasRequired = false; + + // Get a points instance from registry + $pointsInstance = Registry::getRegistry()->getInstance('points'); + + // Is there an instance? + if (is_null($pointsInstance)) { + // Then create one + $pointsInstance = ObjectFactory::createObjectByConfiguredName('user_ppints_class', array($this)); + + // And store it in registry + Registry::getRegistry()->addInstance('points', $pointsInstance); + } // END - if + + // Just forward this request to the user points class + $hasRequired = $pointsInstance->ifUserHasRequiredPoints ($action); + + // Return the result + return $hasRequired; + } + + /** + * Determines if the goverment can still pay a "startup help" to the user + * + * @return $ifGovHelped Wether if the goverment has helped the user with startup + */ + public function ifGovermentPaysStartupHelp () { + // By default they have not payed, which is indeed good. ;-) + $ifGovHelped = false; + + // First get a goverment instance from registry + $govermentInstance = Registry::getRegistry()->getInstance('goverment'); + + // Is it there? + if (is_null($govermentInstance)) { + // Then create a new one + $govermentInstance = ObjectFactory::createObjectByConfiguredName('goverment_class', array($this)); + + // Store it in registry + Registry::getRegistry()->addInstance('goverment', $govermentInstance); + } // END - if + + // Then ask the goverment if they want to pay a "startup help" to the user + if ($govermentInstance->ifGovermentAlreadyPayedsStartupHelp()) { + // They can't pay anymore to the user (excited amount) + $ifGovHelped = true; + } // END - if + + // Return result here + return $ifGovHelped; + } + + /** + * Checks wether the user can take points from the money bank + * + * @return $bankLends Wether the money bank is able to lend money + */ + public function ifUserAllowTakeCreditsFromMoneyBank () { + // Per default the money bank cannot pay + $bankLends = false; + + // Get a money bank instance from registry + $bankInstance = Registry::getRegistry()->getInstance('money_bank'); + + // 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 + + // Does the money bank lend more money? + if ($bankInstance->ifBankLendsMoreMoney()) { + // Okay, that they will do + $bankLends = true; + } // END - if + + // Return result + return $bankLends; + } + + /** + * Checks wether the user has maximum credits with the money bank. This + * should be done seperately from checking if the user is allowed to take + * credits from the bank. + * + * @return $hasMaxCredits Wether the user has maximum credits with the bank + */ + public function ifUserHasMaximumCreditsWithMoneyBank () { + // For default he can still get money + $hasMaxCredits = false; + + // Get a money bank instance from registry + $bankInstance = Registry::getRegistry()->getInstance('money_bank'); + + // 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 + + // Now check if the user has maximum credits + if ($bankInstance->ifUserHasMaxCredits()) { + // Yes, he does! + $hasMaxCredits = true; + } // END - if + + // Return the result + return $hasMaxCredits; + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/user/extended/.htaccess b/application/ship-simu/main/user/extended/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/ship-simu/main/user/extended/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/ship-simu/main/user/extended/class_ShipSimuGuest.php b/application/ship-simu/main/user/extended/class_ShipSimuGuest.php new file mode 100644 index 0000000..839e2d7 --- /dev/null +++ b/application/ship-simu/main/user/extended/class_ShipSimuGuest.php @@ -0,0 +1,117 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software + * @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 ShipSimuGuest extends ShipSimuBaseUser implements ManageableGuest { + // Exceptions + const EXCEPTION_USERNAME_NOT_FOUND = 0x170; + const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x171; + const EXCEPTION_USER_PASS_MISMATCH = 0x172; + + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className = "") { + // Is the class name empty? Then this is not a specialized user class + if (empty($className)) $className = __CLASS__; + + // Call parent constructor + parent::__construct($className); + + // Set part description + $this->setObjectDescription("Special ship-simu class"); + + // Create unique ID number + $this->generateUniqueId(); + } + + /** + * Creates an instance of this user class by a provided username. This + * factory method will check if the username is already taken and if not + * so it will throw an exception. + * + * @param $userName Username we need a class instance for + * @return $userInstance An instance of this user class + * @throws UsernameMissingException If the username does not exist + */ + public final static function createGuestByUsername ($userName) { + // Get a new instance + $userInstance = new ShipSimuGuest(); + + // Set the username + $userInstance->setUserName($userName); + + // Check if the username exists + if (!$userInstance->ifUsernameExists()) { + // Throw an exception here + throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND); + } + + // Return the instance + return $userInstance; + } + + /** + * Creates an instance of this user class by a provided email address. This + * factory method will not check if the email address is there. + * + * @param $email Email address of the user + * @return $userInstance An instance of this user class + */ + public final static function createGuestByEmail ($email) { + // Get a new instance + $userInstance = new ShipSimuGuest(); + + // Set the username + $userInstance->setEmail($email); + + // Return the instance + return $userInstance; + } + + /** + * Updates the last activity timestamp and last performed action in the + * database result. You should call flushPendingUpdates() to flush these updates + * to the database layer. + * + * @param $requestInstance A requestable class instance + * @return void + */ + public function updateLastActivity (Requestable $requestInstance) { + // No activity will be logged for guest accounts + } + + /** + * Flushs all pending updates to the database layer + * + * @return void + */ + public function flushPendingUpdates () { + // No updates will be flushed to database! + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/user/extended/class_ShipSimuMember.php b/application/ship-simu/main/user/extended/class_ShipSimuMember.php new file mode 100644 index 0000000..25e76b7 --- /dev/null +++ b/application/ship-simu/main/user/extended/class_ShipSimuMember.php @@ -0,0 +1,171 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software + * @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 ShipSimuMember extends ShipSimuBaseUser implements ManageableMember { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className = "") { + // Is the class name empty? Then this is not a specialized user class + if (empty($className)) $className = __CLASS__; + + // Call parent constructor + parent::__construct($className); + + // Set part description + $this->setObjectDescription("Special member class for Ship-Simu"); + + // Create unique ID number + $this->generateUniqueId(); + } + + /** + * Creates an instance of this user class by a provided username. This + * factory method will check if the username is already taken and if not + * so it will throw an exception. + * + * @param $userName Username we need a class instance for + * @return $userInstance An instance of this user class + * @throws UsernameMissingException If the username does not exist + */ + public final static function createMemberByUsername ($userName) { + // Get a new instance + $userInstance = new ShipSimuMember(); + + // Set the username + $userInstance->setUserName($userName); + + // Check if the username exists + if (!$userInstance->ifUsernameExists()) { + // Throw an exception here + throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND); + } + + // Return the instance + return $userInstance; + } + + /** + * Creates an instance of this user class by a provided email address. This + * factory method will not check if the email address is there. + * + * @param $email Email address of the user + * @return $userInstance An instance of this user class + */ + public final static function createMemberByEmail ($email) { + // Get a new instance + $userInstance = new ShipSimuMember(); + + // Set the username + $userInstance->setEmail($email); + + // Return the instance + return $userInstance; + } + + /** + * Creates a user by a given request instance + * + * @param $requestInstance An instance of a Requestable class + * @return $userInstance An instance of this user class + */ + public final static function createMemberByRequest (Requestable $requestInstance) { + // Determine if by email or username + if (!is_null($requestInstance->getRequestElement('username'))) { + // Username supplied + $userInstance = self::createMemberByUserName($requestInstance->getRequestElement('username')); + } elseif (!is_null($requestInstance->getRequestElement('email'))) { + // Email supplied + $userInstance = self::createMemberByEmail($requestInstance->getRequestElement('email')); + } else { + // Unsupported mode + $userInstance = new ShipSimuMember(); + $userInstance->partialStub("We need to add more ways of creating user classes here."); + $userInstance->debugBackTrace(); + exit(); + } + + // Return the prepared instance + return $userInstance; + } + + /** + * Updates the last activity timestamp and last performed action in the + * database result. You should call flushPendingUpdates() to flush these updates + * to the database layer. + * + * @param $requestInstance A requestable class instance + * @return void + */ + public function updateLastActivity (Requestable $requestInstance) { + // Set last action + $lastAction = $requestInstance->getRequestElement('action'); + + // If there is no action use the default on + if (is_null($lastAction)) { + $lastAction = $this->getConfigInstance()->readConfig('login_default_action'); + } // END - if + + // Get a critieria instance + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + + // Add search criteria + $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName()); + $searchInstance->setLimit(1); + + // Now get another criteria + $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class'); + + // And add our both entries + $updateInstance->addCriteria('last_activity', date("Y-m-d H:i:s", time())); + $updateInstance->addCriteria('last_action', $lastAction); + + // Add the search criteria for searching for the right entry + $updateInstance->setSearchInstance($searchInstance); + + // Remember the update in database result + $this->getResultInstance()->add2UpdateQueue($updateInstance); + } + + /** + * Flushs all pending updates to the database layer + * + * @return void + */ + public function flushPendingUpdates () { + // Do we have data to update? + if ($this->getResultInstance()->ifDataNeedsFlush()) { + // Get a database wrapper + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class'); + + // Yes, then send the whole result to the database layer + $wrapperInstance->doUpdateByResult($this->getResultInstance()); + } // END - if + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php b/application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php index 80bb037..3f2ade6 100644 --- a/application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php +++ b/application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php @@ -22,6 +22,11 @@ * along with this program. If not, see . */ class CompanyDatabaseWrapper extends BaseDatabaseWrapper { + /** + * Company instance + */ + private $companyInstance = null; + // Constants for database tables const DB_TABLE_COMPANY_DATA = "company"; const DB_TABLE_COMPANY_USER = "company_user"; @@ -45,15 +50,22 @@ class CompanyDatabaseWrapper extends BaseDatabaseWrapper { /** * Creates an instance of this wrapper class * + * @param $companyInstance An instance of a generic company class or null if no specific * @return $wrapperInstance An instance of this wrapper class + * @todo Find an interface which is suitable for all companies */ - public final static function createCompanyDatabaseWrapper () { + public final static function createCompanyDatabaseWrapper (ShippingCompany $companyInstance = null) { // Create a new instance $wrapperInstance = new CompanyDatabaseWrapper(); // Set (primary!) table name $wrapperInstance->setTableName(self::DB_TABLE_COMPANY_DATA); + // Set the company instance if not null + if (!is_null($companyInstance)) { + $wrapperInstance->setCompanyInstance($companyInstance); + } // END - if + // Return the instance return $wrapperInstance; } @@ -93,6 +105,27 @@ class CompanyDatabaseWrapper extends BaseDatabaseWrapper { // Return the result return $participates; } + + /** + * Setter for company instance + * + * @param $companyInstance An instance of a generic company + * @return void + * @todo Find an interface suitable for all types of companies + */ + protected final function setCompanyInstance (ShippingCompany $companyInstance) { + $this->companyInstance = $companyInstance; + } + + /** + * Getter for company instance + * + * @return $companyInstance An instance of a generic company + * @todo Find an interface suitable for all types of companies + */ + public final function getCompanyInstance () { + return $this->companyInstance; + } } // [EOF] diff --git a/application/ship-simu/templates/de/code/action_login_company.ctp b/application/ship-simu/templates/de/code/action_login_company.ctp index 7eacc4b..937cd44 100644 --- a/application/ship-simu/templates/de/code/action_login_company.ctp +++ b/application/ship-simu/templates/de/code/action_login_company.ctp @@ -8,9 +8,9 @@ $linkInstance->prefetchValueInstance('user'); // Maximum of allowed companies reached? if ($linkInstance->getValueInstance()->ifUserCreatedMaximumAllowedCompanies()) { // No more companies allowed to create -} elseif ($linkInstance->getValueInstance()->ifUserPointsEnough('found_new_company')) { +} elseif ($linkInstance->getValueInstance()->ifUserHasRequiredPoints('found_new_company')) { // Enough money to found company -} elseif ($linkInstance->getValueInstance()->ifUserPointsEnough('write_applications')) { +} elseif ($linkInstance->getValueInstance()->ifUserHasRequiredPoints('write_applications')) { // Enough money to write applications to other companies } elseif ($linkInstance->getValueInstance()->ifGovermentPaysStartupHelp()) { // Display link to goverment for startup help @@ -24,7 +24,7 @@ if ($linkInstance->getValueInstance()->ifUserAllowTakeCreditsFromMoneyBank()) { // Money bank is closed! } -if ($linkInstance->getValueInstance()->ifRefillPageActive()) { +if ($linkInstance->ifRefillPageActive()) { // Display link to refill page } else { // Refill page not active diff --git a/db/user_points/.htaccess b/db/user_points/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/db/user_points/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/class_FrameworkInterface.php b/inc/classes/interfaces/class_FrameworkInterface.php index 8d808b4..bffb874 100644 --- a/inc/classes/interfaces/class_FrameworkInterface.php +++ b/inc/classes/interfaces/class_FrameworkInterface.php @@ -31,16 +31,6 @@ interface FrameworkInterface { * @throws NullPointerException If the result instance is null */ function getField ($fieldName); - - /** - * Updates a given field with new value - * - * @param $fieldName Field to update - * @param $fieldValue New value to store - * @return void - * @throws DatabaseUpdateSupportException If this class does not support database updates - */ - function updateDatabaseField ($fieldName, $fieldValue); } // diff --git a/inc/classes/interfaces/database/class_Updateable.php b/inc/classes/interfaces/database/class_Updateable.php index 61e64e3..ba8de80 100644 --- a/inc/classes/interfaces/database/class_Updateable.php +++ b/inc/classes/interfaces/database/class_Updateable.php @@ -22,6 +22,15 @@ * along with this program. If not, see . */ interface Updateable extends FrameworkInterface { + /** + * Updates a given field with new value + * + * @param $fieldName Field to update + * @param $fieldValue New value to store + * @return void + * @throws DatabaseUpdateSupportException If this class does not support database updates + */ + function updateDatabaseField ($fieldName, $fieldValue); } // diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 9633826..e0716d7 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -73,6 +73,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $resultInstance = null; + /** + * Instance for user class + */ + private $userInstance = null; + /** * The real class name */ @@ -238,42 +243,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } elseif (is_array($args)) { // Some arguments are there foreach ($args as $arg) { - // Check the type - if (is_bool($arg)) { - // Boolean! - if ($arg) $argsString .= "true(bool)"; else $argsString .= "false(bool)"; - } elseif (is_int($arg)) { - // Integer - $argsString .= $arg."(int)"; - } elseif (is_float($arg)) { - // Floating point - $argsString .= $arg."(float)"; - } elseif ($arg instanceof BaseFrameworkSystem) { - // Own object instance - $argsString .= $arg->__toString()."(Object)"; - } elseif (is_object($arg)) { - // External object - $argsString .= "unknown object(!)"; - } elseif (is_array($arg)) { - // Array - $argsString .= "Array(array)"; - } elseif (is_string($arg)) { - // String - $argsString .= "\"".$arg."\"(string)"; - } elseif (is_null($arg)) { - // Null - $argsString .= "(null)"; - } elseif (is_resource($arg)) { - // Resource - $argsString .= "(resource)"; - } else { - // Unknown type (please report!) - $argsString .= $arg."(unknown!)"; - } - - // Add comma - $argsString .= ", "; - } + // Add the type + $argsString .= $arg." (".gettype($arg)."), "; + } // END - foreach // Remove last comma if (substr($argsString, -2, 1) === ",") { @@ -1235,38 +1207,22 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } /** - * Updates a given field with new value + * Protected setter for user instance * - * @param $fieldName Field to update - * @param $fieldValue New value to store + * @param $userInstance An instance of a user class * @return void - * @throws DatabaseUpdateSupportException If this class does not support database updates */ - public function updateDatabaseField ($fieldName, $fieldValue) { - // Is updating database fields allowed by interface? - if (!$this instanceof Updateable) { - // Update not supported! - throw new DatabaseUpdateSupportException($this, self::EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED); - } // END - if - - // Get a critieria instance - $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); - - // Add search criteria - $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName()); - $searchInstance->setLimit(1); - - // Now get another criteria - $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class'); - - // And add our both entries - $updateInstance->addCriteria($fieldName, $fieldValue); - - // Add the search criteria for searching for the right entry - $updateInstance->setSearchInstance($searchInstance); + protected final function setUserInstance (ManageableAccount $userInstance) { + $this->userInstance = $userInstance; + } - // Remember the update in database result - $this->getResultInstance()->add2UpdateQueue($updateInstance); + /** + * Getter for user instance + * + * @return $userInstance An instance of a user class + */ + public final function getUserInstance () { + return $this->userInstance; } } diff --git a/inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php b/inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php index 73b7a21..f3753f3 100644 --- a/inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php +++ b/inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php @@ -35,7 +35,7 @@ class NewsDatabaseWrapper extends BaseDatabaseWrapper { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Database wrapper for user objects"); + $this->setObjectDescription("Database wrapper for news objects"); // Create unique ID number $this->generateUniqueId(); diff --git a/inc/classes/main/database/wrapper/class_UserPointsDatabaseWrapper.php b/inc/classes/main/database/wrapper/class_UserPointsDatabaseWrapper.php new file mode 100644 index 0000000..c5490d3 --- /dev/null +++ b/inc/classes/main/database/wrapper/class_UserPointsDatabaseWrapper.php @@ -0,0 +1,62 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software + * @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 UserPointsDatabaseWrapper extends BaseDatabaseWrapper { + // Constants for database table names + const DB_TABLE_USER_POINTS = "user_points"; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct() { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Database wrapper for user points objects"); + + // Create unique ID number + $this->generateUniqueId(); + } + + /** + * Creates an instance of this database wrapper by a provided user class + * + * @return $wrapperInstance An instance of the created wrapper class + */ + public final static function createUserPointsDatabaseWrapper () { + // Get a new instance + $wrapperInstance = new UserPointsDatabaseWrapper(); + + // Set (primary!) table name + $wrapperInstance->setTableName(self::DB_TABLE_USER_POINTS); + + // Return the instance + return $wrapperInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/helper/web/class_BaseWebHelper.php b/inc/classes/main/helper/web/class_BaseWebHelper.php index e3030f7..19b5be3 100644 --- a/inc/classes/main/helper/web/class_BaseWebHelper.php +++ b/inc/classes/main/helper/web/class_BaseWebHelper.php @@ -183,6 +183,17 @@ class BaseWebHelper extends BaseHelper { $isUnconfirmed = ($this->getValueField(UserDatabaseWrapper::DB_COLUMN_USER_STATUS) === $this->getConfigInstance()->readConfig('user_status_guest')); return $isUnconfirmed; } + + /** + * Checks wether the refill page is active which should be not the default + * on non-web applications. + * + * @return $refillActive Wether the refill page is active + */ + public function ifRefillPageActive () { + $refillActive = ($this->getConfigInstance()->readConfig('refill_page_active') === "Y"); + return $refillActive; + } } // [EOF] diff --git a/inc/classes/main/points/.htaccess b/inc/classes/main/points/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/points/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/points/class_UserPoints.php b/inc/classes/main/points/class_UserPoints.php new file mode 100644 index 0000000..7a2aa20 --- /dev/null +++ b/inc/classes/main/points/class_UserPoints.php @@ -0,0 +1,98 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software + * @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 UserPoints extends BaseFrameworkSystem implements Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Class for handling user points"); + + // Create unique ID number + $this->generateUniqueId(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this points class + * + * @param $userInstance An instance of a user class + * @return $pointsInstance An instance of this class + */ + public final static function createUserPoints (ManageableAccount $userInstance) { + // Get a new instance + $pointsInstance = new UserPoints(); + + // Set user instance + $pointsInstance->setUserInstance($userInstance); + + // Return instance + return $pointsInstance; + } + + /** + * Checks wether the user has the required amount of points left for the specified action + * + * @param $action The action or configuration entry plus prefix the user wants to perform + * @return $hasRequired Wether the user has the required points + */ + public function ifUserHasRequiredPoints ($action) { + // Default is that everyone is poor... ;-) + $hasRequired = false; + + // Get the required points entry + $requiredPoints = $this->getConfigInstance()->readConfig($action . '_action_points'); + + // Get a wrapper instance + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_points_db_wrapper_class'); + + // Now get a search criteria and set the user's name as criteria + $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + $criteriaInstance->addCriteria('points_uid', $this->getUserInstance()->getUserName()); + $criteriaInstance->setLimit(1); + + // Get result back + $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance); + + // Do we have an entry? + if ($resultInstance->next()) { + // Load points here - TODO! + $this->partialStub("Load points here for comparison."); + } // END - if + + // Return the result + return $hasRequired; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/user/class_BaseUser.php b/inc/classes/main/user/class_BaseUser.php index ed832a9..0a3432d 100644 --- a/inc/classes/main/user/class_BaseUser.php +++ b/inc/classes/main/user/class_BaseUser.php @@ -253,6 +253,41 @@ class BaseUser extends BaseFrameworkSystem { // Return the value return $primaryValue; } + + /** + * Updates a given field with new value + * + * @param $fieldName Field to update + * @param $fieldValue New value to store + * @return void + * @throws DatabaseUpdateSupportException If this class does not support database updates + */ + public function updateDatabaseField ($fieldName, $fieldValue) { + // Is updating database fields allowed by interface? + if (!$this instanceof Updateable) { + // Update not supported! + throw new DatabaseUpdateSupportException($this, self::EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED); + } // END - if + + // Get a critieria instance + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + + // Add search criteria + $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName()); + $searchInstance->setLimit(1); + + // Now get another criteria + $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class'); + + // And add our both entries + $updateInstance->addCriteria($fieldName, $fieldValue); + + // Add the search criteria for searching for the right entry + $updateInstance->setSearchInstance($searchInstance); + + // Remember the update in database result + $this->getResultInstance()->add2UpdateQueue($updateInstance); + } } // [EOF] -- 2.30.2