3 * A special member class for Ship-Simu
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
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class ShipSimuBaseUser extends BaseUser implements Registerable, Updateable {
26 * Protected constructor
28 * @param $className Name of the class
31 protected function __construct ($className) {
32 // Call parent constructor
33 parent::__construct($className);
37 * Checks wether the user has reached maximum allowed companies to found
39 * @return $reached Wether the user has reached maximum allowed companies to found
41 public function ifUserCreatedMaximumAllowedCompanies () {
42 // Get max allowed companies to found
43 $maxFound = $this->getConfigInstance()->getConfigEntry('max_allowed_companies_found');
45 // Now get a search criteria and set the user's name as criteria
46 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
47 $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
48 $criteriaInstance->setLimit($maxFound);
50 // Get a company wrapper
51 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class');
53 // Do the count-select by criteria
54 $totalRows = $wrapperInstance->doSelectCountByCriteria($criteriaInstance);
56 // Does the user have reached maximum?
57 $reached = ($totalRows >= $maxFound);
64 * Checks wether the user has the required amount of points left for the specified action
66 * @param $action The action or configuration entry plus prefix the user wants to perform
67 * @return $hasRequired Wether the user has the required points
69 public function ifUserHasRequiredPoints ($action) {
70 // Default is that everyone is poor... ;-)
74 $pointsInstance = null;
77 // Get a points instance from registry
78 $pointsInstance = Registry::getRegistry()->getInstance('points');
79 } catch (NullPointerException $e) {
80 // Instance not found in registry
81 // @TODO We should log this exception later
84 // Is there an instance?
85 if (is_null($pointsInstance)) {
87 $pointsInstance = ObjectFactory::createObjectByConfiguredName('user_points_class', array($this));
89 // And store it in registry
90 Registry::getRegistry()->addInstance('points', $pointsInstance);
93 // Just forward this request to the user points class
94 $hasRequired = $pointsInstance->ifUserHasRequiredPoints($action);
101 * Determines if government can still pay a "virtual training course" in general
103 * @return $ifGovHelps Wether if government helps the user with a virtual training course
105 public function ifGovernmentPaysTraining () {
106 // By default they want to help.
109 // First get a government instance from registry
110 $governmentInstance = Registry::getRegistry()->getInstance('government');
113 if (is_null($governmentInstance)) {
114 // Then create a new one
115 $governmentInstance = ObjectFactory::createObjectByConfiguredName('government_class', array($this));
117 // Store it in registry
118 Registry::getRegistry()->addInstance('government', $governmentInstance);
121 // Then ask the government if they want to pay a "startup help" to the user
122 if ($governmentInstance->ifGovernmentAlreadyPayedTraining()) {
123 // Training already given!
127 // Return result here
132 * Determines if government can still pay a "startup help" to the user
134 * @return $ifGovHelps Wether if government helps the user with some startup money
136 public function ifGovernmentPaysStartupHelp () {
137 // By default they want to help.
140 // First get a government instance from registry
141 $governmentInstance = Registry::getRegistry()->getInstance('government');
144 if (is_null($governmentInstance)) {
145 // Then create a new one
146 $governmentInstance = ObjectFactory::createObjectByConfiguredName('government_class', array($this));
148 // Store it in registry
149 Registry::getRegistry()->addInstance('government', $governmentInstance);
152 // Then ask the government if they want to pay a "startup help" to the user
153 if ($governmentInstance->ifGovernmentPayedMaxmimumStartupHelp()) {
154 // They can't pay anymore to the user (excited amount)
158 // Return result here
163 * Checks wether the user can take points from the money bank
165 * @return $bankLends Wether the money bank is able to lend money
166 * @todo Need to implement MoneyBank::ifBankLendsMoreMoney()
168 public function ifUserAllowedTakeCreditsFromMoneyBank () {
169 // Per default the money bank cannot pay
172 // Get a money bank instance from registry
173 $bankInstance = Registry::getRegistry()->getInstance('money_bank');
176 if (is_null($bankInstance)) {
177 // Then create a new one
178 $bankInstance = ObjectFactory::createObjectByConfiguredName('bank_class', array($this));
180 // Store it in registry
181 Registry::getRegistry()->addInstance('money_bank', $bankInstance);
184 // Does the money bank lend more money?
186 if ($bankInstance->ifBankLendsMoreMoney()) {
187 // Okay, that they will do
197 * Checks wether the user has maximum credits with the money bank. This
198 * should be done seperately from checking if the user is allowed to take
199 * credits from the bank.
201 * @return $hasMaxCredits Wether the user has maximum credits with the bank
202 * @todo Need to check the bank if they can lend more money
204 public function ifUserHasMaximumCreditsWithMoneyBank () {
205 // For default he can still get money
206 $hasMaxCredits = false;
208 // Get a money bank instance from registry
209 $bankInstance = Registry::getRegistry()->getInstance('money_bank');
212 if (is_null($bankInstance)) {
213 // Then create a new one
214 $bankInstance = ObjectFactory::createObjectByConfiguredName('bank_class', array($this));
216 // Store it in registry
217 Registry::getRegistry()->addInstance('money_bank', $bankInstance);
220 // Now check if the user has maximum credits
222 if ($bankInstance->ifUserHasMaxCredits()) {
224 $hasMaxCredits = true;
229 return $hasMaxCredits;