/** * (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); }
/** * (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; }