3 * A government class with simplified ways...
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
10 * @todo Find an interface for governments
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class SimplifiedGovernment extends BaseFrameworkSystem implements Registerable {
27 const STATUS_STARTER_HELP = "STARTER_HELP";
30 * Protected constructor
34 protected function __construct () {
35 // Call parent constructor
36 parent::__construct(__CLASS__);
40 * Creates an instance of this government class by given user instance
42 * @param $userInstance The user instance
43 * @return $governmentInstance Instance of the prepared government instance
45 public final static function createSimplifiedGovernment (ManageableAccount $userInstance) {
47 $governmentInstance = new SimplifiedGovernment();
49 // Set the user instance
50 $governmentInstance->setUserInstance($userInstance);
52 // Return the prepared instance
53 return $governmentInstance;
57 * Checks wether the government has already payed a training course for te
60 * @return $alreadyPayed Wether the government has already payed
62 public function ifGovernmentAlreadyPayedTraining () {
63 // Default is not payed
64 $alreadyPayed = false;
66 // Now get a search criteria and set the user's name as criteria
67 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
68 $criteriaInstance->addCriteria("gov_uid", $this->getUserInstance()->getUserId());
69 $criteriaInstance->addCriteria("gov_activity_status", self::STATUS_STARTER_HELP);
70 $criteriaInstance->setLimit(1);
72 // Get a wrapper instance
73 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_gov_wrapper_class');
76 $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
78 // Was the query fine?
79 if ($resultInstance->getAffectedRows() === 1) {
80 // Entry was found so the government can no more pay a training
89 * Checks wether the government has payed maximum of startup helps to the
92 * @return $maximumPayed Wether the government has already payed
94 public function ifGovernmentPayedMaxmimumStartupHelp () {
95 // Default is not payed
96 $maximumPayed = false;
98 // Cache startup help limit
99 $helpLimit = $this->getConfigInstance()->getConfigEntry('government_startup_help_limit');
101 // Now get a search criteria and set the user's name as criteria
102 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
103 $criteriaInstance->addCriteria("gov_uid", $this->getUserInstance()->getUserId());
104 $criteriaInstance->addCriteria("gov_activity_status", self::STATUS_STARTER_HELP);
105 $criteriaInstance->setLimit($helpLimit);
107 // Get a wrapper instance
108 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_gov_wrapper_class');
111 $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
113 // Was the query fine?
114 if ($resultInstance->getAffectedRows() === $helpLimit) {
115 // Entry found, so lets have a look if this government wants to again...
116 $maximumPayed = true;
120 return $maximumPayed;