Moved database columns as constants in wrapper classes
[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         const STATUS_TRAINING        = 'TRAINING';
29
30         /**
31          * Protected constructor
32          *
33          * @return      void
34          */
35         protected function __construct () {
36                 // Call parent constructor
37                 parent::__construct(__CLASS__);
38         }
39
40         /**
41          * Creates an instance of this government class by given user instance
42          *
43          * @param       $userInstance           The user instance
44          * @return      $governmentInstance     Instance of the prepared government instance
45          */
46         public final static function createSimplifiedGovernment (ManageableAccount $userInstance) {
47                 // Get a new instance
48                 $governmentInstance = new SimplifiedGovernment();
49
50                 // Set the user instance
51                 $governmentInstance->setUserInstance($userInstance);
52
53                 // Return the prepared instance
54                 return $governmentInstance;
55         }
56
57         /**
58          * Checks wether the government has already payed a training course for te
59          * current user
60          *
61          * @return      $alreadyPayed   Wether the government has already payed
62          * @todo        Needs do check training limit
63          */
64         public function ifGovernmentAlreadyPayedTraining () {
65                 // Default is not payed
66                 $alreadyPayed = false;
67
68                 // Cache startup training limit
69                 $trainingLimit = $this->getConfigInstance()->getConfigEntry('government_training_limit');
70
71                 // Now get a search criteria and set the user's name as criteria
72                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
73                 $searchInstance->addCriteria(UserGovernmentDatabaseWrapper::DB_COLUMN_GOV_USERID  , $this->getUserInstance()->getUserId());
74                 $searchInstance->addCriteria(UserGovernmentDatabaseWrapper::DB_COLUMN_GOV_ACTIVITY, self::STATUS_TRAINING);
75                 $searchInstance->setLimit(1);
76
77                 // Get a wrapper instance
78                 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_gov_wrapper_class');
79
80                 // Get result back
81                 $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
82
83                 // Was the query fine?
84                 if ($resultInstance->next()) {
85                         // Get entry
86                         $currEntry = $resultInstance->current();
87
88                         // Entry was found so the government can no more pay a training
89                         $alreadyPayed = true;
90                 } // END - if
91
92                 // Return the result
93                 return $alreadyPayed;
94         }
95
96         /**
97          * Checks wether the government has payed maximum of startup helps to the
98          * current user
99          *
100          * @return      $maximumPayed   Wether the government has already payed
101          * @todo        Needs do check help limit
102          */
103         public function ifGovernmentPayedMaxmimumStartupHelp () {
104                 // Default is not payed
105                 $maximumPayed = false;
106
107                 // Cache startup help limit
108                 $helpLimit = $this->getConfigInstance()->getConfigEntry('government_startup_help_limit');
109
110                 // Now get a search criteria and set the user's name as criteria
111                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
112                 $searchInstance->addCriteria(UserGovernmentDatabaseWrapper::DB_COLUMN_GOV_USERID  , $this->getUserInstance()->getUserId());
113                 $searchInstance->addCriteria(UserGovernmentDatabaseWrapper::DB_COLUMN_GOV_ACTIVITY, self::STATUS_STARTER_HELP);
114                 $searchInstance->setLimit($helpLimit);
115
116                 // Get a wrapper instance
117                 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_gov_wrapper_class');
118
119                 // Get result back
120                 $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
121
122                 // Was the query fine?
123                 if ($resultInstance->next()) {
124                         // Get entry
125                         $currEntry = $resultInstance->current();
126
127                         // Entry found, so lets have a look if this government wants to again...
128                         $maximumPayed = true;
129                 } // END - if
130
131                 // Return the result
132                 return $maximumPayed;
133         }
134 }
135
136 // [EOF]
137 ?>