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")); } $existingBookings = TrainingcampsDataService::getCampBookingsByTeam($this->_websoccer, $this->_db, $teamId); if (!count($existingBookings)) { throw new Exception($this->_i18n->getMessage("trainingcamp_cancel_illegalid")); } $deleted = FALSE; foreach ($existingBookings as $booking) { if ($booking["id"] == $parameters["bookingid"]) { $this->_db->queryDelete($this->_websoccer->getConfig("db_prefix") . "_trainingslager_belegung", "id = %d", $booking["id"]); $deleted = TRUE; } } if (!$deleted) { throw new Exception($this->_i18n->getMessage("trainingcamp_cancel_illegalid")); } // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("trainingcamp_cancel_success"), "")); return "trainingcamp"; }
public function getTemplateParameters() { $user = $this->_websoccer->getUser(); $teamId = $user->getClubId($this->_websoccer, $this->_db); if ($teamId < 1) { throw new Exception($this->_i18n->getMessage("feature_requires_team")); } $camps = array(); $bookedCamp = array(); $bookedCamps = TrainingcampsDataService::getCampBookingsByTeam($this->_websoccer, $this->_db, $teamId); $listCamps = TRUE; if (count($bookedCamps)) { $bookedCamp = $bookedCamps[0]; if ($bookedCamp["date_end"] < $this->_websoccer->getNowAsTimestamp()) { TrainingcampsDataService::executeCamp($this->_websoccer, $this->_db, $teamId, $bookedCamp); $bookedCamp = array(); } else { $listCamps = FALSE; } } // provide camps to book if ($listCamps) { $camps = TrainingcampsDataService::getCamps($this->_websoccer, $this->_db); } return array("bookedCamp" => $bookedCamp, "camps" => $camps); }
public function executeAction($parameters) { $now = $this->_websoccer->getNowAsTimestamp(); $user = $this->_websoccer->getUser(); $teamId = $user->getClubId($this->_websoccer, $this->_db); if ($teamId < 1) { throw new Exception($this->_i18n->getMessage("feature_requires_team")); } $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId); // check if duration is in range $min = $this->_websoccer->getConfig("trainingcamp_min_days"); $max = $this->_websoccer->getConfig("trainingcamp_max_days"); if ($parameters["days"] < $min || $parameters["days"] > $max) { throw new Exception(sprintf($this->_i18n->getMessage("trainingcamp_booking_err_invaliddays"), $min, $max)); } // check if date is in future $startDateObj = DateTime::createFromFormat($this->_websoccer->getConfig("date_format") . " H:i", $parameters["start_date"] . " 00:00"); $startDateTimestamp = $startDateObj->getTimestamp(); $endDateTimestamp = $startDateTimestamp + 3600 * 24 * $parameters["days"]; if ($startDateTimestamp <= $now) { throw new Exception($this->_i18n->getMessage("trainingcamp_booking_err_dateinpast")); } // check if too far in future $maxDate = $now + $this->_websoccer->getConfig("trainingcamp_booking_max_days_in_future") * 3600 * 24; if ($startDateTimestamp > $maxDate) { throw new Exception($this->_i18n->getMessage("trainingcamp_booking_err_datetoofar", $this->_websoccer->getConfig("trainingcamp_booking_max_days_in_future"))); } // get camp details $camp = TrainingcampsDataService::getCampById($this->_websoccer, $this->_db, $parameters["id"]); if (!$camp) { throw new Exception("Illegal ID"); } // check if user still has an open training camp $existingBookings = TrainingcampsDataService::getCampBookingsByTeam($this->_websoccer, $this->_db, $teamId); if (count($existingBookings)) { throw new Exception($this->_i18n->getMessage("trainingcamp_booking_err_existingbookings")); } // check if team can afford it. $playersOfTeam = PlayersDataService::getPlayersOfTeamById($this->_websoccer, $this->_db, $teamId); $totalCosts = $camp["costs"] * $parameters["days"] * count($playersOfTeam); if ($totalCosts >= $team["team_budget"]) { throw new Exception($this->_i18n->getMessage("trainingcamp_booking_err_tooexpensive")); } // check if there are matches within the time frame $matches = MatchesDataService::getMatchesByTeamAndTimeframe($this->_websoccer, $this->_db, $teamId, $startDateTimestamp, $endDateTimestamp); if (count($matches)) { throw new Exception($this->_i18n->getMessage("trainingcamp_booking_err_matcheswithintimeframe")); } // debit amount BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $teamId, $totalCosts, "trainingcamp_booking_costs_subject", $camp["name"]); // create camp booking $columns["verein_id"] = $teamId; $columns["lager_id"] = $camp["id"]; $columns["datum_start"] = $startDateTimestamp; $columns["datum_ende"] = $endDateTimestamp; $this->_db->queryInsert($columns, $this->_websoccer->getConfig("db_prefix") . "_trainingslager_belegung"); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("trainingcamp_booking_success"), "")); return "trainingcamp"; }
/** * (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; }