]> git.mxchange.org Git - shipsimu.git/commitdiff
Moved database columns as constants in wrapper classes
authorRoland Häder <roland@mxchange.org>
Sat, 22 Aug 2009 03:40:24 +0000 (03:40 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 22 Aug 2009 03:40:24 +0000 (03:40 +0000)
application/ship-simu/config.php
application/ship-simu/main/government/class_SimplifiedGovernment.php
application/ship-simu/main/user/class_ShipSimuBaseUser.php
application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php
application/ship-simu/main/wrapper/class_UserGovernmentDatabaseWrapper.php

index 80a53d40b894c76caced3acd72f75f299d70961a..3514596ec478676a722ee4551db31b348b8971cf 100644 (file)
@@ -433,6 +433,9 @@ $cfg->setConfigEntry('ship_simu_login_refill_payment_discovery', 'LocalPaymentDi
 // CFG: GOVERNMENT-STARTUP-HELP-LIMIT
 $cfg->setConfigEntry('government_startup_help_limit', 3);
 
+// CFG: GOVERNMENT-TRAINING-LIMIT
+$cfg->setConfigEntry('government_training_limit', 2);
+
 // CFG: WEB-BLOCK-HELPER
 $cfg->setConfigEntry('web_block_helper', 'WebBlockHelper');
 
index 3413f9dc340c9653d96ee170a6ec2e4a0b77c057..d4b593b20b205b5f71ccaca3bf5a5ce18835a8e2 100644 (file)
@@ -24,7 +24,8 @@
  */
 class SimplifiedGovernment extends BaseFrameworkSystem implements Registerable {
        // Constants
-       const STATUS_STARTER_HELP = "STARTER_HELP";
+       const STATUS_STARTER_HELP    = 'STARTER_HELP';
+       const STATUS_TRAINING        = 'TRAINING';
 
        /**
         * Protected constructor
@@ -58,25 +59,32 @@ class SimplifiedGovernment extends BaseFrameworkSystem implements Registerable {
         * current user
         *
         * @return      $alreadyPayed   Wether the government has already payed
+        * @todo        Needs do check training limit
         */
        public function ifGovernmentAlreadyPayedTraining () {
                // Default is not payed
                $alreadyPayed = false;
 
+               // Cache startup training limit
+               $trainingLimit = $this->getConfigInstance()->getConfigEntry('government_training_limit');
+
                // Now get a search criteria and set the user's name as criteria
-               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-               $criteriaInstance->addCriteria("gov_uid", $this->getUserInstance()->getUserId());
-               $criteriaInstance->addCriteria("gov_activity_status", self::STATUS_STARTER_HELP);
-               $criteriaInstance->setLimit(1);
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+               $searchInstance->addCriteria(UserGovernmentDatabaseWrapper::DB_COLUMN_GOV_USERID  , $this->getUserInstance()->getUserId());
+               $searchInstance->addCriteria(UserGovernmentDatabaseWrapper::DB_COLUMN_GOV_ACTIVITY, self::STATUS_TRAINING);
+               $searchInstance->setLimit(1);
 
                // Get a wrapper instance
                $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_gov_wrapper_class');
 
                // Get result back
-               $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+               $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
 
                // Was the query fine?
-               if ($resultInstance->getAffectedRows() === 1) {
+               if ($resultInstance->next()) {
+                       // Get entry
+                       $currEntry = $resultInstance->current();
+
                        // Entry was found so the government can no more pay a training
                        $alreadyPayed = true;
                } // END - if
@@ -90,6 +98,7 @@ class SimplifiedGovernment extends BaseFrameworkSystem implements Registerable {
         * current user
         *
         * @return      $maximumPayed   Wether the government has already payed
+        * @todo        Needs do check help limit
         */
        public function ifGovernmentPayedMaxmimumStartupHelp () {
                // Default is not payed
@@ -99,19 +108,22 @@ class SimplifiedGovernment extends BaseFrameworkSystem implements Registerable {
                $helpLimit = $this->getConfigInstance()->getConfigEntry('government_startup_help_limit');
 
                // Now get a search criteria and set the user's name as criteria
-               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-               $criteriaInstance->addCriteria("gov_uid", $this->getUserInstance()->getUserId());
-               $criteriaInstance->addCriteria("gov_activity_status", self::STATUS_STARTER_HELP);
-               $criteriaInstance->setLimit($helpLimit);
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+               $searchInstance->addCriteria(UserGovernmentDatabaseWrapper::DB_COLUMN_GOV_USERID  , $this->getUserInstance()->getUserId());
+               $searchInstance->addCriteria(UserGovernmentDatabaseWrapper::DB_COLUMN_GOV_ACTIVITY, self::STATUS_STARTER_HELP);
+               $searchInstance->setLimit($helpLimit);
 
                // Get a wrapper instance
                $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_gov_wrapper_class');
 
                // Get result back
-               $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+               $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
 
                // Was the query fine?
-               if ($resultInstance->getAffectedRows() === $helpLimit) {
+               if ($resultInstance->next()) {
+                       // Get entry
+                       $currEntry = $resultInstance->current();
+
                        // Entry found, so lets have a look if this government wants to again...
                        $maximumPayed = true;
                } // END - if
index ffc4c6edc7eefd59f8082ccbe98f158f4a4590ed..5f61809a5451519e7ec93b6f3b23f6389db4b6f4 100644 (file)
@@ -43,15 +43,15 @@ class ShipSimuBaseUser extends BaseUser implements Registerable, Updateable {
                $maxFound = $this->getConfigInstance()->getConfigEntry('max_allowed_companies_found');
 
                // Now get a search criteria and set the user's name as criteria
-               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-               $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
-               $criteriaInstance->setLimit($maxFound);
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+               $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
+               $searchInstance->setLimit($maxFound);
 
                // Get a company wrapper
                $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class');
 
                // Do the count-select by criteria
-               $totalRows = $wrapperInstance->doSelectCountByCriteria($criteriaInstance);
+               $totalRows = $wrapperInstance->doSelectCountByCriteria($searchInstance);
 
                // Does the user have reached maximum?
                $reached = ($totalRows >= $maxFound);
index 7cf15803d125530936fb87815dbd3ee7e3df69ca..72e7844d67cc427e3ddeeae1933917bc2051f2fb 100644 (file)
@@ -28,8 +28,11 @@ class CompanyDatabaseWrapper extends BaseDatabaseWrapper {
        private $companyInstance = null;
 
        // Constants for database tables
-       const DB_TABLE_COMPANY_DATA = "company";
-       const DB_TABLE_COMPANY_USER = "company_user";
+       const DB_TABLE_COMPANY_DATA = 'company';
+       const DB_TABLE_COMPANY_USER = 'company_user';
+
+       // Constants for database columns
+       const DB_COLUMN_PARTICIPANT_ID = 'participant_id';
 
        /**
         * Protected constructor
@@ -75,17 +78,17 @@ class CompanyDatabaseWrapper extends BaseDatabaseWrapper {
                $participates = false;
 
                // Get a search criteria class
-               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
                // Add the user primary key as a search criteria
-               $criteriaInstance->addCriteria("participant_id", $userInstance->getPrimaryKey());
-               $criteriaInstance->setLimit(1);
+               $searchInstance->addCriteria(self::DB_COLUMN_PARTICIPANT_ID, $userInstance->getPrimaryKey());
+               $searchInstance->setLimit(1);
 
                // Set company->user table
                $this->setTableName(self::DB_TABLE_COMPANY_USER);
 
                // Get the result back
-               $resultInstance = $this->doSelectByCriteria($criteriaInstance);
+               $resultInstance = $this->doSelectByCriteria($searchInstance);
 
                // Is there a result?
                if ($resultInstance->next()) {
index bdf0a0c1218871bc74b23f76d2e8ea8af2c5fc79..2bf10350ec2d93c55af073215b66e4a1d36b36ff 100644 (file)
  */
 class UserGovernmentDatabaseWrapper extends BaseDatabaseWrapper {
        // Constants for database tables
-       const DB_TABLE_USER_GOVERNMENT = "gov_user";
+       const DB_TABLE_USER_GOVERNMENT = 'gov_user';
+
+       // Database columns
+       const DB_COLUMN_GOV_USERID   = 'gov_uid';
+       const DB_COLUMN_GOV_ACTIVITY = 'gov_activity_status';
 
        /**
         * Protected constructor