コード例 #1
0
 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";
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 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";
 }
コード例 #4
0
 public function getTemplateParameters()
 {
     $camp = TrainingcampsDataService::getCampById($this->_websoccer, $this->_db, $this->_websoccer->getRequestParameter("id"));
     if (!$camp) {
         throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND));
     }
     $defaultDate = $this->_websoccer->getNowAsTimestamp() + 24 * 3600;
     return array("camp" => $camp, "defaultDate" => $defaultDate);
 }
コード例 #5
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;
 }
 private function checkTrainingCamps()
 {
     $fromTable = $this->_websoccer->getConfig('db_prefix') . '_trainingslager_belegung AS B';
     $fromTable .= ' INNER JOIN ' . $this->_websoccer->getConfig('db_prefix') . '_trainingslager AS C ON C.id = B.lager_id';
     $columns['B.id'] = 'id';
     $columns['B.datum_start'] = 'date_start';
     $columns['B.datum_ende'] = 'date_end';
     $columns['B.verein_id'] = 'team_id';
     $columns['C.name'] = 'name';
     $columns['C.land'] = 'country';
     $columns['C.preis_spieler_tag'] = 'costs';
     $columns['C.p_staerke'] = 'effect_strength';
     $columns['C.p_technik'] = 'effect_strength_technique';
     $columns['C.p_kondition'] = 'effect_strength_stamina';
     $columns['C.p_frische'] = 'effect_strength_freshness';
     $columns['C.p_zufriedenheit'] = 'effect_strength_satisfaction';
     $whereCondition = 'B.datum_ende < %d';
     $result = $this->_db->querySelect($columns, $fromTable, $whereCondition, $this->_websoccer->getNowAsTimestamp());
     while ($booking = $result->fetch_array()) {
         TrainingcampsDataService::executeCamp($this->_websoccer, $this->_db, $booking['team_id'], $booking);
     }
     $result->free();
 }