*/
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
* 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
* current user
*
* @return $maximumPayed Wether the government has already payed
+ * @todo Needs do check help limit
*/
public function ifGovernmentPayedMaxmimumStartupHelp () {
// Default is not payed
$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
$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);
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
$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()) {