From bbacce2b01c210cb194f67c7abb7be9bc8c5f6ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 22 Aug 2009 03:40:24 +0000 Subject: [PATCH] Moved database columns as constants in wrapper classes --- application/ship-simu/config.php | 3 ++ .../government/class_SimplifiedGovernment.php | 38 ++++++++++++------- .../main/user/class_ShipSimuBaseUser.php | 8 ++-- .../wrapper/class_CompanyDatabaseWrapper.php | 15 +++++--- .../class_UserGovernmentDatabaseWrapper.php | 6 ++- 5 files changed, 46 insertions(+), 24 deletions(-) diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index 80a53d4..3514596 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -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'); diff --git a/application/ship-simu/main/government/class_SimplifiedGovernment.php b/application/ship-simu/main/government/class_SimplifiedGovernment.php index 3413f9d..d4b593b 100644 --- a/application/ship-simu/main/government/class_SimplifiedGovernment.php +++ b/application/ship-simu/main/government/class_SimplifiedGovernment.php @@ -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 diff --git a/application/ship-simu/main/user/class_ShipSimuBaseUser.php b/application/ship-simu/main/user/class_ShipSimuBaseUser.php index ffc4c6e..5f61809 100644 --- a/application/ship-simu/main/user/class_ShipSimuBaseUser.php +++ b/application/ship-simu/main/user/class_ShipSimuBaseUser.php @@ -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); diff --git a/application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php b/application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php index 7cf1580..72e7844 100644 --- a/application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php +++ b/application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php @@ -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()) { diff --git a/application/ship-simu/main/wrapper/class_UserGovernmentDatabaseWrapper.php b/application/ship-simu/main/wrapper/class_UserGovernmentDatabaseWrapper.php index bdf0a0c..2bf1035 100644 --- a/application/ship-simu/main/wrapper/class_UserGovernmentDatabaseWrapper.php +++ b/application/ship-simu/main/wrapper/class_UserGovernmentDatabaseWrapper.php @@ -23,7 +23,11 @@ */ 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 -- 2.39.5