X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=application%2Fshipsimu%2Fmain%2Fgovernment%2Fclass_SimplifiedGovernment.php;fp=application%2Fshipsimu%2Fmain%2Fgovernment%2Fclass_SimplifiedGovernment.php;h=8999153e811c7e8e73441c2504f2c3a330c0801f;hp=0000000000000000000000000000000000000000;hb=02a6b02f96d2193d2161e70477bf8f18a199389f;hpb=4f70843ae8428f051d70ccff5bb43fc4c03dda8d diff --git a/application/shipsimu/main/government/class_SimplifiedGovernment.php b/application/shipsimu/main/government/class_SimplifiedGovernment.php new file mode 100644 index 0000000..8999153 --- /dev/null +++ b/application/shipsimu/main/government/class_SimplifiedGovernment.php @@ -0,0 +1,137 @@ + + * @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.shipsimu.org + * @todo Find an interface for governments + * + * 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 SimplifiedGovernment extends BaseFrameworkSystem implements Registerable { + // Constants + const STATUS_STARTER_HELP = 'STARTER_HELP'; + const STATUS_TRAINING = 'TRAINING'; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this government class by given user instance + * + * @param $userInstance The user instance + * @return $governmentInstance Instance of the prepared government instance + */ + public static final function createSimplifiedGovernment (ManageableAccount $userInstance) { + // Get a new instance + $governmentInstance = new SimplifiedGovernment(); + + // Set the user instance + $governmentInstance->setUserInstance($userInstance); + + // Return the prepared instance + return $governmentInstance; + } + + /** + * Checks wether the government has already payed a training course for te + * current user + * + * @return $alreadyPayed Wether the government has already payed + * @todo Needs do check training limit + */ + public function ifGovernmentAlreadyPayedTraining () { + // Default is not payed + $alreadyPayed = false; + + // Cache startup training limit + $trainingLimit = $this->getConfigInstance()->getConfigEntry('government_training_limit'); + + // Now get a search criteria and set the user's name as criteria + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + $searchInstance->addCriteria(UserGovernmentDatabaseWrapper::DB_COLUMN_GOV_USERID , $this->getUserInstance()->getUserId()); + $searchInstance->addCriteria(UserGovernmentDatabaseWrapper::DB_COLUMN_GOV_ACTIVITY, self::STATUS_TRAINING); + $searchInstance->setLimit(1); + + // Get a wrapper instance + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_gov_wrapper_class'); + + // Get result back + $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance); + + // Was the query fine? + if ($resultInstance->next()) { + // Get entry + $currEntry = $resultInstance->current(); + + // Entry was found so the government can no more pay a training + $alreadyPayed = true; + } // END - if + + // Return the result + return $alreadyPayed; + } + + /** + * Checks wether the government has payed maximum of startup helps to the + * current user + * + * @return $maximumPayed Wether the government has already payed + * @todo Needs do check help limit + */ + public function ifGovernmentPayedMaxmimumStartupHelp () { + // Default is not payed + $maximumPayed = false; + + // Cache startup help limit + $helpLimit = $this->getConfigInstance()->getConfigEntry('government_startup_help_limit'); + + // Now get a search criteria and set the user's name as criteria + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + $searchInstance->addCriteria(UserGovernmentDatabaseWrapper::DB_COLUMN_GOV_USERID , $this->getUserInstance()->getUserId()); + $searchInstance->addCriteria(UserGovernmentDatabaseWrapper::DB_COLUMN_GOV_ACTIVITY, self::STATUS_STARTER_HELP); + $searchInstance->setLimit($helpLimit); + + // Get a wrapper instance + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_gov_wrapper_class'); + + // Get result back + $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance); + + // Was the query fine? + if ($resultInstance->next()) { + // Get entry + $currEntry = $resultInstance->current(); + + // Entry found, so lets have a look if this government wants to again... + $maximumPayed = true; + } // END - if + + // Return the result + return $maximumPayed; + } +} + +// [EOF] +?>