Copyright updated, menu class added for 'home'
[shipsimu.git] / application / ship-simu / main / government / class_SimplifiedGovernment.php
1 <?php
2 /**
3  * A government class with simplified ways...
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  * @todo                Find an interface for governments
11  *
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.
16  *
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.
21  *
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/>.
24  */
25 class SimplifiedGovernment extends BaseFrameworkSystem implements Registerable {
26         // Constants
27         const STATUS_STARTER_HELP = "STARTER_HELP";
28
29         /**
30          * Protected constructor
31          *
32          * @return      void
33          */
34         protected function __construct () {
35                 // Call parent constructor
36                 parent::__construct(__CLASS__);
37
38                 // Clean up a little
39                 $this->removeSystemArray();
40                 $this->removeNumberFormaters();
41         }
42
43         /**
44          * Creates an instance of this government class by given user instance
45          *
46          * @param       $userInstance           The user instance
47          * @return      $governmentInstance     Instance of the prepared government instance
48          */
49         public final static function createSimplifiedGovernment (ManageableAccount $userInstance) {
50                 // Get a new instance
51                 $governmentInstance = new SimplifiedGovernment();
52
53                 // Set the user instance
54                 $governmentInstance->setUserInstance($userInstance);
55
56                 // Return the prepared instance
57                 return $governmentInstance;
58         }
59
60         /**
61          * Checks wether the government has already payed a training course for te
62          * current user
63          *
64          * @return      $alreadyPayed   Wether the government has already payed
65          */
66         public function ifGovernmentAlreadyPayedTraining () {
67                 // Default is not payed
68                 $alreadyPayed = false;
69
70                 // Now get a search criteria and set the user's name as criteria
71                 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
72                 $criteriaInstance->addCriteria("gov_uid", $this->getUserInstance()->getUserId());
73                 $criteriaInstance->addCriteria("gov_activity_status", self::STATUS_STARTER_HELP);
74                 $criteriaInstance->setLimit(1);
75
76                 // Get a wrapper instance
77                 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_gov_wrapper_class');
78
79                 // Get result back
80                 $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
81
82                 // Was the query fine?
83                 if ($resultInstance->getAffectedRows() === 1) {
84                         // Entry was found so the government can no more pay a training
85                         $alreadyPayed = true;
86                 } // END - if
87
88                 // Return the result
89                 return $alreadyPayed;
90         }
91
92         /**
93          * Checks wether the government has payed maximum of startup helps to the
94          * current user
95          *
96          * @return      $maximumPayed   Wether the government has already payed
97          */
98         public function ifGovernmentPayedMaxmimumStartupHelp () {
99                 // Default is not payed
100                 $maximumPayed = false;
101
102                 // Cache startup help limit
103                 $helpLimit = $this->getConfigInstance()->readConfig('government_startup_help_limit');
104
105                 // Now get a search criteria and set the user's name as criteria
106                 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
107                 $criteriaInstance->addCriteria("gov_uid", $this->getUserInstance()->getUserId());
108                 $criteriaInstance->addCriteria("gov_activity_status", self::STATUS_STARTER_HELP);
109                 $criteriaInstance->setLimit($helpLimit);
110
111                 // Get a wrapper instance
112                 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_gov_wrapper_class');
113
114                 // Get result back
115                 $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
116
117                 // Was the query fine?
118                 if ($resultInstance->getAffectedRows() === $helpLimit) {
119                         // Entry found, so lets have a look if this government wants to again...
120                         $maximumPayed = true;
121                 } // END - if
122
123                 // Return the result
124                 return $maximumPayed;
125         }
126 }
127
128 // [EOF]
129 ?>