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