コード例 #1
0
 /**
  * (non-PHPdoc)
  * @see IModel::getTemplateParameters()
  */
 public function getTemplateParameters()
 {
     $teamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db);
     // last training executions
     $lastExecution = TrainingDataService::getLatestTrainingExecutionTime($this->_websoccer, $this->_db, $teamId);
     $unitsCount = TrainingDataService::countRemainingTrainingUnits($this->_websoccer, $this->_db, $teamId);
     $paginator = null;
     $trainers = null;
     // has valid training unit?
     $training_unit = TrainingDataService::getValidTrainingUnit($this->_websoccer, $this->_db, $teamId);
     if (!isset($training_unit["id"])) {
         // get trainers
         $count = TrainingDataService::countTrainers($this->_websoccer, $this->_db);
         $eps = $this->_websoccer->getConfig("entries_per_page");
         $paginator = new Paginator($count, $eps, $this->_websoccer);
         if ($count > 0) {
             $trainers = TrainingDataService::getTrainers($this->_websoccer, $this->_db, $paginator->getFirstIndex(), $eps);
         }
     } else {
         $training_unit["trainer"] = TrainingDataService::getTrainerById($this->_websoccer, $this->_db, $training_unit["trainer_id"]);
     }
     // collect effects of executed training unit
     $trainingEffects = array();
     $contextParameters = $this->_websoccer->getContextParameters();
     if (isset($contextParameters["trainingEffects"])) {
         $trainingEffects = $contextParameters["trainingEffects"];
     }
     return array("unitsCount" => $unitsCount, "lastExecution" => $lastExecution, "training_unit" => $training_unit, "trainers" => $trainers, "paginator" => $paginator, "trainingEffects" => $trainingEffects);
 }
コード例 #2
0
 public function getTemplateParameters()
 {
     $trainerId = $this->_websoccer->getRequestParameter("id");
     $trainer = TrainingDataService::getTrainerById($this->_websoccer, $this->_db, $trainerId);
     if (!isset($trainer["id"])) {
         throw new Exception(MSG_KEY_ERROR_PAGENOTFOUND);
     }
     return array("trainer" => $trainer);
 }
コード例 #3
0
 /**
  * (non-PHPdoc)
  * @see IActionController::executeAction()
  */
 public function executeAction($parameters)
 {
     $user = $this->_websoccer->getUser();
     $teamId = $user->getClubId($this->_websoccer, $this->_db);
     if ($teamId < 1) {
         return null;
     }
     // get unit info
     $unit = TrainingDataService::getTrainingUnitById($this->_websoccer, $this->_db, $teamId, $parameters["id"]);
     if (!isset($unit["id"])) {
         throw new Exception("invalid ID");
     }
     if ($unit["date_executed"]) {
         throw new Exception($this->_i18n->getMessage("training_execute_err_already_executed"));
     }
     // check if minimum time break between two units is matched
     $previousExecution = TrainingDataService::getLatestTrainingExecutionTime($this->_websoccer, $this->_db, $teamId);
     $earliestValidExecution = $previousExecution + 3600 * $this->_websoccer->getConfig("training_min_hours_between_execution");
     $now = $this->_websoccer->getNowAsTimestamp();
     if ($now < $earliestValidExecution) {
         throw new Exception($this->_i18n->getMessage("training_execute_err_too_early", $this->_websoccer->getFormattedDatetime($earliestValidExecution)));
     }
     // check if team is in training camp.
     $campBookings = TrainingcampsDataService::getCampBookingsByTeam($this->_websoccer, $this->_db, $teamId);
     foreach ($campBookings as $booking) {
         if ($booking["date_start"] <= $now && $booking["date_end"] >= $now) {
             throw new Exception($this->_i18n->getMessage("training_execute_err_team_in_training_camp"));
         }
     }
     // check if there is currently a match simulating
     $liveMatch = MatchesDataService::getLiveMatchByTeam($this->_websoccer, $this->_db, $teamId);
     if (isset($liveMatch["match_id"])) {
         throw new Exception($this->_i18n->getMessage("training_execute_err_match_simulating"));
     }
     // trainer info
     $trainer = TrainingDataService::getTrainerById($this->_websoccer, $this->_db, $unit["trainer_id"]);
     $columns["focus"] = $parameters["focus"];
     $unit["focus"] = $parameters["focus"];
     $columns["intensity"] = $parameters["intensity"];
     $unit["intensity"] = $parameters["intensity"];
     // train players
     $this->trainPlayers($teamId, $trainer, $unit);
     // update execution time of unit
     $columns["date_executed"] = $now;
     $fromTable = $this->_websoccer->getConfig("db_prefix") . "_training_unit";
     $whereCondition = "id = %d";
     $this->_db->queryUpdate($columns, $fromTable, $whereCondition, $unit["id"]);
     // success message
     $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("training_execute_success"), ""));
     return null;
 }
コード例 #4
0
 /**
  * (non-PHPdoc)
  * @see IActionController::executeAction()
  */
 public function executeAction($parameters)
 {
     $user = $this->_websoccer->getUser();
     $teamId = $user->getClubId($this->_websoccer, $this->_db);
     if ($teamId < 1) {
         throw new Exception($this->_i18n->getMessage("feature_requires_team"));
     }
     if (TrainingDataService::countRemainingTrainingUnits($this->_websoccer, $this->_db, $teamId)) {
         throw new Exception($this->_i18n->getMessage("training_choose_trainer_err_existing_units"));
     }
     // trainer info
     $trainer = TrainingDataService::getTrainerById($this->_websoccer, $this->_db, $parameters["id"]);
     if (!isset($trainer["id"])) {
         throw new Exception("invalid ID");
     }
     // can team afford it?
     $numberOfUnits = (int) $parameters["units"];
     $totalCosts = $numberOfUnits * $trainer["salary"];
     $teamInfo = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId);
     if ($teamInfo["team_budget"] <= $totalCosts) {
         throw new Exception($this->_i18n->getMessage("training_choose_trainer_err_too_expensive"));
     }
     // try to debit premium fee
     if ($trainer['premiumfee']) {
         PremiumDataService::debitAmount($this->_websoccer, $this->_db, $user->id, $trainer['premiumfee'], "choose-trainer");
     }
     // debit money
     BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $teamId, $totalCosts, "training_trainer_salary_subject", $trainer["name"]);
     // create new units
     $columns["team_id"] = $teamId;
     $columns["trainer_id"] = $trainer["id"];
     $fromTable = $this->_websoccer->getConfig("db_prefix") . "_training_unit";
     for ($unitNo = 1; $unitNo <= $numberOfUnits; $unitNo++) {
         $this->_db->queryInsert($columns, $fromTable);
     }
     // success message
     $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("saved_message_title"), ""));
     // redirect to training overview
     return "training";
 }