]> git.mxchange.org Git - shipsimu.git/blob - application/ship-simu/main/user/class_ShipSimuBaseUser.php
5515d3c0df1cbae5d10039676ed722da6203eff6
[shipsimu.git] / application / ship-simu / main / user / class_ShipSimuBaseUser.php
1 <?php
2 /**
3  * A special member class for Ship-Simu
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
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  *
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.
15  *
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.
20  *
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/>.
23  */
24 class ShipSimuBaseUser extends BaseUser implements Registerable, Updateable {
25         /**
26          * Protected constructor
27          *
28          * @param       $className      Name of the class
29          * @return      void
30          */
31         protected function __construct ($className) {
32                 // Call parent constructor
33                 parent::__construct($className);
34         }
35
36         /**
37          * Checks wether the user has reached maximum allowed companies to found
38          *
39          * @return      $reached        Wether the user has reached maximum allowed companies to found
40          */
41         public function ifUserCreatedMaximumAllowedCompanies () {
42                 // Get max allowed companies to found
43                 $maxFound = $this->getConfigInstance()->getConfigEntry('max_allowed_companies_found');
44
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);
49
50                 // Get a company wrapper
51                 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class');
52
53                 // Do the count-select by criteria
54                 $totalRows = $wrapperInstance->doSelectCountByCriteria($criteriaInstance);
55
56                 // Does the user have reached maximum?
57                 $reached = ($totalRows >= $maxFound);
58
59                 // Return the result
60                 return $reached;
61         }
62
63         /**
64          * Checks wether the user has the required amount of points left for the specified action
65          *
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
68          */
69         public function ifUserHasRequiredPoints ($action) {
70                 // Default is that everyone is poor... ;-)
71                 $hasRequired = false;
72
73                 try {
74                         // Get a points instance from registry
75                         $pointsInstance = Registry::getRegistry()->getInstance('points');
76                 } catch (NullPointerException $e) {
77                         // Instance not found in registry
78                         // @TODO We should log this exception later
79                 }
80
81                 // Is there an instance?
82                 if (is_null($pointsInstance)) {
83                         // Then create one
84                         $pointsInstance = ObjectFactory::createObjectByConfiguredName('user_points_class', array($this));
85
86                         // And store it in registry
87                         Registry::getRegistry()->addInstance('points', $pointsInstance);
88                 } // END - if
89
90                 // Just forward this request to the user points class
91                 $hasRequired = $pointsInstance->ifUserHasRequiredPoints($action);
92
93                 // Return the result
94                 return $hasRequired;
95         }
96
97         /**
98          * Determines if government can still pay a "virtual training course" in general
99          *
100          * @return      $ifGovHelps             Wether if government helps the user with a virtual training course
101          */
102         public function ifGovernmentPaysTraining () {
103                 // By default they want to help.
104                 $ifGovHelps = true;
105
106                 // First get a government instance from registry
107                 $governmentInstance = Registry::getRegistry()->getInstance('government');
108
109                 // Is it there?
110                 if (is_null($governmentInstance)) {
111                         // Then create a new one
112                         $governmentInstance = ObjectFactory::createObjectByConfiguredName('government_class', array($this));
113
114                         // Store it in registry
115                         Registry::getRegistry()->addInstance('government', $governmentInstance);
116                 } // END - if
117
118                 // Then ask the government if they want to pay a "startup help" to the user
119                 if ($governmentInstance->ifGovernmentAlreadyPayedTraining()) {
120                         // Training already given!
121                         $ifGovHelps = false;
122                 } // END - if
123
124                 // Return result here
125                 return $ifGovHelps;
126         }
127
128         /**
129          * Determines if government can still pay a "startup help" to the user
130          *
131          * @return      $ifGovHelps             Wether if government helps the user with some startup money
132          */
133         public function ifGovernmentPaysStartupHelp () {
134                 // By default they want to help.
135                 $ifGovHelps = true;
136
137                 // First get a government instance from registry
138                 $governmentInstance = Registry::getRegistry()->getInstance('government');
139
140                 // Is it there?
141                 if (is_null($governmentInstance)) {
142                         // Then create a new one
143                         $governmentInstance = ObjectFactory::createObjectByConfiguredName('government_class', array($this));
144
145                         // Store it in registry
146                         Registry::getRegistry()->addInstance('government', $governmentInstance);
147                 } // END - if
148
149                 // Then ask the government if they want to pay a "startup help" to the user
150                 if ($governmentInstance->ifGovernmentPayedMaxmimumStartupHelp()) {
151                         // They can't pay anymore to the user (excited amount)
152                         $ifGovHelps = false;
153                 } // END - if
154
155                 // Return result here
156                 return $ifGovHelps;
157         }
158
159         /**
160          * Checks wether the user can take points from the money bank
161          *
162          * @return      $bankLends      Wether the money bank is able to lend money
163          * @todo        Need to implement MoneyBank::ifBankLendsMoreMoney()
164          */
165         public function ifUserAllowedTakeCreditsFromMoneyBank () {
166                 // Per default the money bank cannot pay
167                 $bankLends = false;
168
169                 // Get a money bank instance from registry
170                 $bankInstance = Registry::getRegistry()->getInstance('money_bank');
171
172                 // Is it there?
173                 if (is_null($bankInstance)) {
174                         // Then create a new one
175                         $bankInstance = ObjectFactory::createObjectByConfiguredName('bank_class', array($this));
176
177                         // Store it in registry
178                         Registry::getRegistry()->addInstance('money_bank', $bankInstance);
179                 } // END - if
180
181                 // Does the money bank lend more money?
182                 /* UNFINISED:
183                 if ($bankInstance->ifBankLendsMoreMoney()) {
184                         // Okay, that they will do
185                         $bankLends = true;
186                 } // END - if
187                 */
188
189                 // Return result
190                 return $bankLends;
191         }
192
193         /**
194          * Checks wether the user has maximum credits with the money bank. This
195          * should be done seperately from checking if the user is allowed to take
196          * credits from the bank.
197          *
198          * @return      $hasMaxCredits  Wether the user has maximum credits with the bank
199          * @todo        Need to check the bank if they can lend more money
200          */
201         public function ifUserHasMaximumCreditsWithMoneyBank () {
202                 // For default he can still get money
203                 $hasMaxCredits = false;
204
205                 // Get a money bank instance from registry
206                 $bankInstance = Registry::getRegistry()->getInstance('money_bank');
207
208                 // Is it there?
209                 if (is_null($bankInstance)) {
210                         // Then create a new one
211                         $bankInstance = ObjectFactory::createObjectByConfiguredName('bank_class', array($this));
212
213                         // Store it in registry
214                         Registry::getRegistry()->addInstance('money_bank', $bankInstance);
215                 } // END - if
216
217                 // Now check if the user has maximum credits
218                 /** UNFINISHED PART!
219                 if ($bankInstance->ifUserHasMaxCredits()) {
220                         // Yes, he does!
221                         $hasMaxCredits = true;
222                 } // END - if
223                 */
224
225                 // Return the result
226                 return $hasMaxCredits;
227         }
228 }
229
230 // [EOF]
231 ?>