Typo fixed
[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, this is free software
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()->readConfig('max_allowed_companies_found');
44
45                 // Get a company wrapper
46                 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class');
47
48                 // Now get a search criteria and set the user's name as criteria
49                 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
50                 $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
51                 $criteriaInstance->setLimit($maxFound);
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                 // Get a points instance from registry
74                 $pointsInstance = Registry::getRegistry()->getInstance('points');
75
76                 // Is there an instance?
77                 if (is_null($pointsInstance)) {
78                         // Then create one
79                         $pointsInstance = ObjectFactory::createObjectByConfiguredName('user_ppints_class', array($this));
80
81                         // And store it in registry
82                         Registry::getRegistry()->addInstance('points', $pointsInstance);
83                 } // END - if
84
85                 // Just forward this request to the user points class
86                 $hasRequired = $pointsInstance->ifUserHasRequiredPoints ($action);
87
88                 // Return the result
89                 return $hasRequired;
90         }
91
92         /**
93          * Determines if the goverment can still pay a "startup help" to the user
94          *
95          * @return      $ifGovHelped    Wether if the goverment has helped the user with startup
96          */
97         public function ifGovermentPaysStartupHelp () {
98                 // By default they have not payed, which is indeed good. ;-)
99                 $ifGovHelped = false;
100
101                 // First get a goverment instance from registry
102                 $govermentInstance = Registry::getRegistry()->getInstance('goverment');
103
104                 // Is it there?
105                 if (is_null($govermentInstance)) {
106                         // Then create a new one
107                         $govermentInstance = ObjectFactory::createObjectByConfiguredName('goverment_class', array($this));
108
109                         // Store it in registry
110                         Registry::getRegistry()->addInstance('goverment', $govermentInstance);
111                 } // END - if
112
113                 // Then ask the goverment if they want to pay a "startup help" to the user
114                 if ($govermentInstance->ifGovermentAlreadyPayedStartupHelp()) {
115                         // They can't pay anymore to the user (excited amount)
116                         $ifGovHelped = true;
117                 } // END - if
118
119                 // Return result here
120                 return $ifGovHelped;
121         }
122
123         /**
124          * Checks wether the user can take points from the money bank
125          *
126          * @return      $bankLends      Wether the money bank is able to lend money
127          */
128         public function ifUserAllowTakeCreditsFromMoneyBank () {
129                 // Per default the money bank cannot pay
130                 $bankLends = false;
131
132                 // Get a money bank instance from registry
133                 $bankInstance = Registry::getRegistry()->getInstance('money_bank');
134
135                 // Is it there?
136                 if (is_null($bankInstance)) {
137                         // Then create a new one
138                         $bankInstance = ObjectFactory::createObjectByConfiguredName('bank_class', array($this));
139
140                         // Store it in registry
141                         Registry::getRegistry()->addInstance('money_bank', $bankInstance);
142                 } // END - if
143
144                 // Does the money bank lend more money?
145                 if ($bankInstance->ifBankLendsMoreMoney()) {
146                         // Okay, that they will do
147                         $bankLends = true;
148                 } // END - if
149
150                 // Return result
151                 return $bankLends;
152         }
153
154         /**
155          * Checks wether the user has maximum credits with the money bank. This
156          * should be done seperately from checking if the user is allowed to take
157          * credits from the bank.
158          *
159          * @return      $hasMaxCredits  Wether the user has maximum credits with the bank
160          */
161         public function ifUserHasMaximumCreditsWithMoneyBank () {
162                 // For default he can still get money
163                 $hasMaxCredits = false;
164
165                 // Get a money bank instance from registry
166                 $bankInstance = Registry::getRegistry()->getInstance('money_bank');
167
168                 // Is it there?
169                 if (is_null($bankInstance)) {
170                         // Then create a new one
171                         $bankInstance = ObjectFactory::createObjectByConfiguredName('bank_class', array($this));
172
173                         // Store it in registry
174                         Registry::getRegistry()->addInstance('money_bank', $bankInstance);
175                 } // END - if
176
177                 // Now check if the user has maximum credits
178                 if ($bankInstance->ifUserHasMaxCredits()) {
179                         // Yes, he does!
180                         $hasMaxCredits = true;
181                 } // END - if
182
183                 // Return the result
184                 return $hasMaxCredits;
185         }
186 }
187
188 // [EOF]
189 ?>