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 IModel::getTemplateParameters()
  */
 public function getTemplateParameters()
 {
     $matchId = (int) $this->_websoccer->getRequestParameter('id');
     if ($matchId < 1) {
         throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND));
     }
     $match = MatchesDataService::getMatchById($this->_websoccer, $this->_db, $matchId);
     if (!isset($match['match_id'])) {
         throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND));
     }
     $allowTacticChanges = FALSE;
     $reportmessages = array();
     if ($match['match_minutes'] > 0) {
         $reportmessages = MatchesDataService::getMatchReportMessages($this->_websoccer, $this->_db, $this->_i18n, $matchId);
         $userTeamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db);
         $userNationalTeamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db);
         if (!$match['match_simulated'] && $this->_websoccer->getConfig('sim_allow_livechanges') && ($match['match_home_id'] == $userTeamId || $match['match_guest_id'] == $userTeamId || $match['match_home_id'] == $userNationalTeamId || $match['match_guest_id'] == $userNationalTeamId)) {
             $allowTacticChanges = TRUE;
         }
     }
     // collect strikers
     $homeStrikerMessages = array();
     $guestStrikerMessages = array();
     foreach ($reportmessages as $reportMessage) {
         $type = $reportMessage['type'];
         if ($type == 'Tor' || $type == 'Tor_mit_vorlage' || $type == 'Elfmeter_erfolg' || $type == 'Freistoss_treffer') {
             if ($reportMessage['active_home']) {
                 array_unshift($homeStrikerMessages, $reportMessage);
             } else {
                 array_unshift($guestStrikerMessages, $reportMessage);
             }
         }
     }
     return array('match' => $match, 'reportmessages' => $reportmessages, 'allowTacticChanges' => $allowTacticChanges, 'homeStrikerMessages' => $homeStrikerMessages, 'guestStrikerMessages' => $guestStrikerMessages);
 }
 public function getTemplateParameters()
 {
     $matchId = (int) $this->_websoccer->getRequestParameter("id");
     if ($matchId < 1) {
         throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND));
     }
     $match = MatchesDataService::getMatchById($this->_websoccer, $this->_db, $matchId);
     // get statistics
     $columns["SUM(shoots)"] = "shoots";
     $columns["SUM(ballcontacts)"] = "ballcontacts";
     $columns["SUM(wontackles)"] = "wontackles";
     $columns["SUM(passes_successed)"] = "passes_successed";
     $columns["SUM(passes_failed)"] = "passes_failed";
     $fromTable = $this->_websoccer->getConfig("db_prefix") . "_spiel_berechnung";
     $whereCondition = "spiel_id = %d AND team_id = %d";
     // home team
     $parameters = array($matchId, $match["match_home_id"]);
     $result = $this->_db->querySelect($columns, $fromTable, $whereCondition, $parameters);
     $homeStatistics = $result->fetch_array();
     $result->free();
     // guest team
     $parameters = array($matchId, $match["match_guest_id"]);
     $result = $this->_db->querySelect($columns, $fromTable, $whereCondition, $parameters);
     $guestStatistics = $result->fetch_array();
     $result->free();
     return array("match" => $match, "homeStatistics" => $homeStatistics, "guestStatistics" => $guestStatistics);
 }
 /**
  * (non-PHPdoc)
  * @see IActionController::executeAction()
  */
 public function executeAction($parameters)
 {
     $user = $this->_websoccer->getUser();
     if ($this->_isNationalTeam) {
         $teamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db);
     } else {
         $teamId = $user->getClubId($this->_websoccer, $this->_db);
     }
     // check and get next match
     // next x matches
     $nextMatches = MatchesDataService::getNextMatches($this->_websoccer, $this->_db, $teamId, $this->_websoccer->getConfig('formation_max_next_matches'));
     if (!count($nextMatches)) {
         throw new Exception($this->_i18n->getMessage('formation_err_nonextmatch'));
     }
     // currently selected match
     $matchId = $parameters['id'];
     foreach ($nextMatches as $nextMatch) {
         if ($nextMatch['match_id'] == $matchId) {
             $matchinfo = $nextMatch;
             break;
         }
     }
     if (!isset($matchinfo)) {
         throw new Exception('illegal match id');
     }
     // get team players and check whether provided IDs are valid players (in team and not blocked)
     $players = PlayersDataService::getPlayersOfTeamById($this->_websoccer, $this->_db, $teamId, $this->_isNationalTeam, $matchinfo['match_type'] == 'cup', $matchinfo['match_type'] != 'friendly');
     $this->validatePlayer($parameters['player1'], $players);
     $this->validatePlayer($parameters['player2'], $players);
     $this->validatePlayer($parameters['player3'], $players);
     $this->validatePlayer($parameters['player4'], $players);
     $this->validatePlayer($parameters['player5'], $players);
     $this->validatePlayer($parameters['player6'], $players);
     $this->validatePlayer($parameters['player7'], $players);
     $this->validatePlayer($parameters['player8'], $players);
     $this->validatePlayer($parameters['player9'], $players);
     $this->validatePlayer($parameters['player10'], $players);
     $this->validatePlayer($parameters['player11'], $players);
     $this->validatePlayer($parameters['bench1'], $players, TRUE);
     $this->validatePlayer($parameters['bench2'], $players, TRUE);
     $this->validatePlayer($parameters['bench3'], $players, TRUE);
     $this->validatePlayer($parameters['bench4'], $players, TRUE);
     $this->validatePlayer($parameters['bench5'], $players, TRUE);
     // validate substitutions
     $validSubstitutions = array();
     for ($subNo = 1; $subNo <= 3; $subNo++) {
         $playerIn = $parameters['sub' . $subNo . '_in'];
         $playerOut = $parameters['sub' . $subNo . '_out'];
         $playerMinute = $parameters['sub' . $subNo . '_minute'];
         if ($playerIn != null && $playerIn > 0 && $playerOut != null && $playerOut > 0 && $playerMinute != null && $playerMinute > 0) {
             $this->validateSubstitution($playerIn, $playerOut, $playerMinute, $players);
             $validSubstitutions[] = $subNo;
         }
     }
     // save formation
     $this->saveFormation($teamId, $matchinfo['match_id'], $parameters, $validSubstitutions);
     // create success message
     $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage('saved_message_title'), ''));
     return null;
 }
 /**
  * (non-PHPdoc)
  * @see IModel::getTemplateParameters()
  */
 public function getTemplateParameters()
 {
     $matchId = (int) $this->_websoccer->getRequestParameter("id");
     if ($matchId < 1) {
         throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND));
     }
     $match = MatchesDataService::getMatchById($this->_websoccer, $this->_db, $matchId, FALSE, TRUE);
     $home_players = MatchesDataService::getMatchReportPlayerRecords($this->_websoccer, $this->_db, $matchId, $match["match_home_id"]);
     $guest_players = MatchesDataService::getMatchReportPlayerRecords($this->_websoccer, $this->_db, $matchId, $match["match_guest_id"]);
     // check if any player is member of team of the day
     if ($match["match_simulated"]) {
         $result = $this->_db->querySelect("player_id", $this->_websoccer->getConfig("db_prefix") . "_teamoftheday", "season_id = %d AND matchday = %d", array($match["match_season_id"], $match["match_matchday"]));
         $topPlayerIds = array();
         while ($topmember = $result->fetch_array()) {
             $topPlayerIds[] = $topmember["player_id"];
         }
         $result->free();
         if (count($topPlayerIds)) {
             for ($playerIndex = 0; $playerIndex < count($home_players); $playerIndex++) {
                 if (in_array($home_players[$playerIndex]["id"], $topPlayerIds)) {
                     $home_players[$playerIndex]["is_best_player_of_day"] = TRUE;
                 }
             }
             for ($playerIndex = 0; $playerIndex < count($guest_players); $playerIndex++) {
                 if (in_array($guest_players[$playerIndex]["id"], $topPlayerIds)) {
                     $guest_players[$playerIndex]["is_best_player_of_day"] = TRUE;
                 }
             }
         }
     }
     return array("match" => $match, "home_players" => $home_players, "guest_players" => $guest_players);
 }
 /**
  * (non-PHPdoc)
  * @see IModel::getTemplateParameters()
  */
 public function getTemplateParameters()
 {
     $userId = (int) $this->_websoccer->getRequestParameter('id');
     $matches = MatchesDataService::getLatestMatchesByUser($this->_websoccer, $this->_db, $userId);
     $items = array();
     foreach ($matches as $match) {
         $items[] = array('url' => $this->_websoccer->getInternalUrl('match', 'id=' . $match['id'], TRUE), 'title' => $match['home_team'] . ' - ' . $match['guest_team'] . ' (' . $match['home_goals'] . ':' . $match['guest_goals'] . ')', 'date' => gmdate(DATE_RSS, $match['date']));
     }
     return array('items' => $items);
 }
 public function getTemplateParameters()
 {
     $matches = array();
     $paginator = null;
     $count = MatchesDataService::countTodaysMatches($this->_websoccer, $this->_db);
     if ($count) {
         $eps = $this->_websoccer->getConfig("entries_per_page");
         $paginator = new Paginator($count, $eps, $this->_websoccer);
         $matches = MatchesDataService::getTodaysMatches($this->_websoccer, $this->_db, $paginator->getFirstIndex(), $eps);
     }
     return array("matches" => $matches, "paginator" => $paginator);
 }
 public function getTemplateParameters()
 {
     $cupRoundId = $this->_websoccer->getRequestParameter("roundid");
     $cupGroup = $this->_websoccer->getRequestParameter("group");
     $columns = "C.name AS cup_name, R.name AS round_name";
     $fromTable = $this->_websoccer->getConfig("db_prefix") . "_cup_round AS R";
     $fromTable .= " INNER JOIN " . $this->_websoccer->getConfig("db_prefix") . "_cup AS C ON C.id = R.cup_id";
     $result = $this->_db->querySelect($columns, $fromTable, "R.id = %d", $cupRoundId);
     $round = $result->fetch_array();
     $result->free();
     $matches = MatchesDataService::getMatchesByCupRoundAndGroup($this->_websoccer, $this->_db, $round["cup_name"], $round["round_name"], $cupGroup);
     return array("matches" => $matches, "groupteams" => CupsDataService::getTeamsOfCupGroupInRankingOrder($this->_websoccer, $this->_db, $cupRoundId, $cupGroup));
 }
 /**
  * (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;
 }
 public function getTemplateParameters()
 {
     if ($this->_websoccer->getRequestParameter("nationalteam")) {
         $clubId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db);
     } else {
         $clubId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db);
     }
     $matchinfo = MatchesDataService::getNextMatch($this->_websoccer, $this->_db, $clubId);
     // get previous matches against this team
     if (count($matchinfo)) {
         $matchinfo["previous_matches"] = MatchesDataService::getPreviousMatches($matchinfo, $this->_websoccer, $this->_db);
     }
     return $matchinfo;
 }
 private function _getLatestMatchesByTeam($teamId)
 {
     $whereCondition = "M.berechnet = 1 AND (HOME.id = %d OR GUEST.id = %d)";
     $parameters = array($teamId, $teamId);
     if ($this->_match['match_season_id']) {
         $whereCondition .= ' AND M.saison_id = %d';
         $parameters[] = $this->_match['match_season_id'];
     } elseif (strlen($this->_match['match_cup_name'])) {
         $whereCondition .= ' AND M.pokalname = \'%s\'';
         $parameters[] = $this->_match['match_cup_name'];
     } else {
         $whereCondition .= ' AND M.spieltyp = \'Freundschaft\'';
     }
     $whereCondition .= " ORDER BY M.datum DESC";
     return MatchesDataService::getMatchesByCondition($this->_websoccer, $this->_db, $whereCondition, $parameters, 5);
 }
 public function getTemplateParameters()
 {
     $teamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db);
     if ($teamId < 1) {
         throw new Exception($this->_i18n->getMessage("feature_requires_team"));
     }
     $sponsor = SponsorsDataService::getSponsorinfoByTeamId($this->_websoccer, $this->_db, $teamId);
     $sponsors = array();
     $teamMatchday = 0;
     if (!$sponsor) {
         $teamMatchday = MatchesDataService::getMatchdayNumberOfTeam($this->_websoccer, $this->_db, $teamId);
         if ($teamMatchday >= $this->_websoccer->getConfig("sponsor_earliest_matchday")) {
             $sponsors = SponsorsDataService::getSponsorOffers($this->_websoccer, $this->_db, $teamId);
         }
     }
     return array("sponsor" => $sponsor, "sponsors" => $sponsors, "teamMatchday" => $teamMatchday);
 }
 /**
  * (non-PHPdoc)
  * @see IModel::getTemplateParameters()
  */
 public function getTemplateParameters()
 {
     $cupName = $this->_websoccer->getRequestParameter('cup');
     $cupRound = $this->_websoccer->getRequestParameter('round');
     // get cup round info
     $columns['C.logo'] = 'cup_logo';
     $columns['R.id'] = 'round_id';
     $columns['R.firstround_date'] = 'firstround_date';
     $columns['R.secondround_date'] = 'secondround_date';
     $columns['R.finalround'] = 'is_finalround';
     $columns['R.groupmatches'] = 'is_groupround';
     $columns['PREVWINNERS.name'] = 'prev_round_winners';
     $columns['PREVLOOSERS.name'] = 'prev_round_loosers';
     $fromTable = $this->_websoccer->getConfig('db_prefix') . '_cup_round AS R';
     $fromTable .= ' INNER JOIN ' . $this->_websoccer->getConfig('db_prefix') . '_cup AS C ON C.id = R.cup_id';
     $fromTable .= ' LEFT JOIN ' . $this->_websoccer->getConfig('db_prefix') . '_cup_round AS PREVWINNERS ON PREVWINNERS.id = R.from_winners_round_id';
     $fromTable .= ' LEFT JOIN ' . $this->_websoccer->getConfig('db_prefix') . '_cup_round AS PREVLOOSERS ON PREVLOOSERS.id = R.from_loosers_round_id';
     $result = $this->_db->querySelect($columns, $fromTable, 'C.name = \'%s\' AND R.name = \'%s\'', array($cupName, $cupRound), 1);
     $round = $result->fetch_array();
     $result->free();
     $groups = array();
     $preSelectedGroup = '';
     if ($round['is_groupround']) {
         $userTeamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db);
         $result = $this->_db->querySelect('name,team_id', $this->_websoccer->getConfig('db_prefix') . '_cup_round_group', 'cup_round_id = %d ORDER BY name ASC', array($round['round_id']));
         while ($group = $result->fetch_array()) {
             if (!isset($groups[$group['name']])) {
                 $groups[$group['name']] = $group['name'];
             }
             if ($group['team_id'] == $userTeamId) {
                 $preSelectedGroup = $group['name'];
             }
         }
         $result->free();
         $matches = array();
     } else {
         $matches = MatchesDataService::getMatchesByCupRound($this->_websoccer, $this->_db, $cupName, $cupRound);
     }
     return array('matches' => $matches, 'round' => $round, 'groups' => $groups, 'preSelectedGroup' => $preSelectedGroup);
 }
 public function executeAction($parameters)
 {
     $user = $this->_websoccer->getUser();
     $teamId = $user->getClubId($this->_websoccer, $this->_db);
     if ($teamId < 1) {
         return null;
     }
     $sponsor = SponsorsDataService::getSponsorinfoByTeamId($this->_websoccer, $this->_db, $teamId);
     if ($sponsor) {
         throw new Exception($this->_i18n->getMessage("sponsor_choose_stillcontract"));
     }
     // check min matchday
     $teamMatchday = MatchesDataService::getMatchdayNumberOfTeam($this->_websoccer, $this->_db, $teamId);
     if ($teamMatchday < $this->_websoccer->getConfig("sponsor_earliest_matchday")) {
         throw new Exception($this->_i18n->getMessage("sponsor_choose_tooearly", $this->_websoccer->getConfig("sponsor_earliest_matchday")));
     }
     // check if selected sponsor is in list of available sponsors
     // (sponsor might be selected by other teams in meanwhile)
     $sponsors = SponsorsDataService::getSponsorOffers($this->_websoccer, $this->_db, $teamId);
     $found = FALSE;
     foreach ($sponsors as $availableSponsor) {
         if ($availableSponsor["sponsor_id"] == $parameters["id"]) {
             $found = TRUE;
             break;
         }
     }
     if (!$found) {
         throw new Exception($this->_i18n->getMessage("sponsor_choose_novalidsponsor"));
     }
     // update team
     $columns["sponsor_id"] = $parameters["id"];
     $columns["sponsor_spiele"] = $this->_websoccer->getConfig("sponsor_matches");
     $fromTable = $this->_websoccer->getConfig("db_prefix") . "_verein";
     $whereCondition = "id = %d";
     $this->_db->queryUpdate($columns, $fromTable, $whereCondition, $teamId);
     // success message
     $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("sponsor_choose_success"), ""));
     return null;
 }
 /**
  * (non-PHPdoc)
  * @see IModel::getTemplateParameters()
  */
 public function getTemplateParameters()
 {
     $matches = array();
     $paginator = null;
     $clubId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db);
     $whereCondition = '(home_verein = %d OR gast_verein = %d) AND berechnet != \'1\'';
     $parameters = array($clubId, $clubId);
     $result = $this->_db->querySelect('COUNT(*) AS hits', $this->_websoccer->getConfig('db_prefix') . '_spiel', $whereCondition, $parameters);
     $matchesCnt = $result->fetch_array();
     $result->free();
     if ($matchesCnt) {
         $count = $matchesCnt['hits'];
     } else {
         $count = 0;
     }
     if ($count) {
         $whereCondition .= ' ORDER BY M.datum ASC';
         $eps = $this->_websoccer->getConfig("entries_per_page");
         $paginator = new Paginator($count, $eps, $this->_websoccer);
         $matches = MatchesDataService::getMatchesByCondition($this->_websoccer, $this->_db, $whereCondition, $parameters, $paginator->getFirstIndex() . ',' . $eps);
     }
     return array("matches" => $matches, "paginator" => $paginator);
 }
 /**
  * (non-PHPdoc)
  * @see IModel::getTemplateParameters()
  */
 public function getTemplateParameters()
 {
     // get team players
     if ($this->_nationalteam) {
         $clubId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db);
     } else {
         $clubId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db);
     }
     // next x matches
     $nextMatches = MatchesDataService::getNextMatches($this->_websoccer, $this->_db, $clubId, $this->_websoccer->getConfig('formation_max_next_matches'));
     if (!count($nextMatches)) {
         throw new Exception($this->_i18n->getMessage('next_match_block_no_nextmatch'));
     }
     // currently selected match
     $matchId = $this->_websoccer->getRequestParameter('id');
     if (!$matchId) {
         $matchinfo = $nextMatches[0];
     } else {
         foreach ($nextMatches as $nextMatch) {
             if ($nextMatch['match_id'] == $matchId) {
                 $matchinfo = $nextMatch;
                 break;
             }
         }
     }
     if (!isset($matchinfo)) {
         throw new Exception('illegal match id');
     }
     $players = null;
     if ($clubId > 0) {
         if ($this->_nationalteam) {
             $players = NationalteamsDataService::getNationalPlayersOfTeamByPosition($this->_websoccer, $this->_db, $clubId);
         } else {
             $players = PlayersDataService::getPlayersOfTeamByPosition($this->_websoccer, $this->_db, $clubId, 'DESC', count($matchinfo) && $matchinfo['match_type'] == 'cup', isset($matchinfo['match_type']) && $matchinfo['match_type'] != 'friendly');
         }
     }
     // load template
     if ($this->_websoccer->getRequestParameter('templateid')) {
         $formation = FormationDataService::getFormationByTemplateId($this->_websoccer, $this->_db, $clubId, $this->_websoccer->getRequestParameter('templateid'));
     } else {
         // get previously saved formation and tactic
         $formation = FormationDataService::getFormationByTeamId($this->_websoccer, $this->_db, $clubId, $matchinfo['match_id']);
     }
     for ($benchNo = 1; $benchNo <= 5; $benchNo++) {
         if ($this->_websoccer->getRequestParameter('bench' . $benchNo)) {
             $formation['bench' . $benchNo] = $this->_websoccer->getRequestParameter('bench' . $benchNo);
         } else {
             if (!isset($formation['bench' . $benchNo])) {
                 $formation['bench' . $benchNo] = '';
             }
         }
     }
     for ($subNo = 1; $subNo <= 3; $subNo++) {
         if ($this->_websoccer->getRequestParameter('sub' . $subNo . '_out')) {
             $formation['sub' . $subNo . '_out'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_out');
             $formation['sub' . $subNo . '_in'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_in');
             $formation['sub' . $subNo . '_minute'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_minute');
             $formation['sub' . $subNo . '_condition'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_condition');
             $formation['sub' . $subNo . '_position'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_position');
         } else {
             if (!isset($formation['sub' . $subNo . '_out'])) {
                 $formation['sub' . $subNo . '_out'] = '';
                 $formation['sub' . $subNo . '_in'] = '';
                 $formation['sub' . $subNo . '_minute'] = '';
                 $formation['sub' . $subNo . '_condition'] = '';
                 $formation['sub' . $subNo . '_position'] = '';
             }
         }
     }
     $setup = $this->getFormationSetup($formation);
     // select players from team by criteria
     $criteria = $this->_websoccer->getRequestParameter('preselect');
     if ($criteria !== NULL) {
         if ($criteria == 'strongest') {
             $sortColumn = 'w_staerke';
         } elseif ($criteria == 'freshest') {
             $sortColumn = 'w_frische';
         } else {
             $sortColumn = 'w_zufriedenheit';
         }
         $proposedPlayers = FormationDataService::getFormationProposalForTeamId($this->_websoccer, $this->_db, $clubId, $setup['defense'], $setup['dm'], $setup['midfield'], $setup['om'], $setup['striker'], $setup['outsideforward'], $sortColumn, 'DESC', $this->_nationalteam, isset($matchinfo['match_type']) && $matchinfo['match_type'] == 'cup');
         for ($playerNo = 1; $playerNo <= 11; $playerNo++) {
             $playerIndex = $playerNo - 1;
             if (isset($proposedPlayers[$playerIndex])) {
                 $formation['player' . $playerNo] = $proposedPlayers[$playerIndex]['id'];
                 $formation['player' . $playerNo . '_pos'] = $proposedPlayers[$playerIndex]['position'];
             }
         }
         // clear bench (prevents duplicate players)
         for ($benchNo = 1; $benchNo <= 5; $benchNo++) {
             $formation['bench' . $benchNo] = '';
         }
         for ($subNo = 1; $subNo <= 3; $subNo++) {
             $formation['sub' . $subNo . '_out'] = '';
             $formation['sub' . $subNo . '_in'] = '';
             $formation['sub' . $subNo . '_minute'] = '';
             $formation['sub' . $subNo . '_condition'] = '';
             $formation['sub' . $subNo . '_position'] = '';
         }
     }
     // free kick taker
     if ($this->_websoccer->getRequestParameter('freekickplayer')) {
         $formation['freekickplayer'] = $this->_websoccer->getRequestParameter('freekickplayer');
     } else {
         if (!isset($formation['freekickplayer'])) {
             $formation['freekickplayer'] = '';
         }
     }
     // tactical options
     if ($this->_websoccer->getRequestParameter('offensive')) {
         $formation['offensive'] = $this->_websoccer->getRequestParameter('offensive');
     } else {
         if (!isset($formation['offensive'])) {
             $formation['offensive'] = 40;
         }
     }
     if ($this->_websoccer->getRequestParameter('longpasses')) {
         $formation['longpasses'] = $this->_websoccer->getRequestParameter('longpasses');
     }
     if ($this->_websoccer->getRequestParameter('counterattacks')) {
         $formation['counterattacks'] = $this->_websoccer->getRequestParameter('counterattacks');
     }
     for ($playerNo = 1; $playerNo <= 11; $playerNo++) {
         // set player from request
         if ($this->_websoccer->getRequestParameter('player' . $playerNo)) {
             $formation['player' . $playerNo] = $this->_websoccer->getRequestParameter('player' . $playerNo);
             $formation['player' . $playerNo . '_pos'] = $this->_websoccer->getRequestParameter('player' . $playerNo . '_pos');
             // set to 0 if no previous formation is available
         } else {
             if (!isset($formation['player' . $playerNo])) {
                 $formation['player' . $playerNo] = '';
                 $formation['player' . $playerNo . '_pos'] = '';
             }
         }
     }
     return array('nextMatches' => $nextMatches, 'next_match' => $matchinfo, 'previous_matches' => MatchesDataService::getPreviousMatches($matchinfo, $this->_websoccer, $this->_db), 'players' => $players, 'formation' => $formation, 'setup' => $setup, 'captain_id' => TeamsDataService::getTeamCaptainIdOfTeam($this->_websoccer, $this->_db, $clubId));
 }
 public function getTemplateParameters()
 {
     $matches = MatchesDataService::getMatchesByMatchday($this->_websoccer, $this->_db, $this->_seasonId, $this->_matchday);
     return array("matches" => $matches);
 }
echo "<select name=\"team_id\" id=\"team_id\">";
echo "<option value=\"" . $match["match_home_id"] . "\">" . escapeOutput($match["match_home_name"]) . "</option>";
echo "<option value=\"" . $match["match_guest_id"] . "\">" . escapeOutput($match["match_guest_name"]) . "</option>";
echo "</select>";
echo "</div>";
echo "</div>";
echo FormBuilder::createFormGroup($i18n, "message_id", array("type" => "foreign_key", "jointable" => "spiel_text", "entity" => "matchtext", "labelcolumns" => "aktion,nachricht"), "", "match_manage_reportmsg_");
echo FormBuilder::createFormGroup($i18n, "playernames", array("type" => "text"), "", "match_manage_reportmsg_");
echo FormBuilder::createFormGroup($i18n, "minute", array("type" => "number"), "", "match_manage_reportmsg_");
echo FormBuilder::createFormGroup($i18n, "intermediateresult", array("type" => "text"), "", "match_manage_reportmsg_");
echo "</fieldset>";
echo "<div class=\"form-actions\">";
echo "<button type=\"submit\" class=\"btn btn-primary\">" . $i18n->getMessage("button_save") . "</button>";
echo "</div></form>";
// ******** list items
$reportItems = MatchesDataService::getMatchReportMessages($website, $db, $i18n, $matchId);
// no items
if (!count($reportItems)) {
    echo createInfoMessage("", $i18n->getMessage("match_manage_reportitems_noitems"));
    // list items
} else {
    echo "<table class=\"table table-bordered table-striped table-hover\">";
    echo "<thead>";
    echo "<tr>";
    echo "<th>" . $i18n->getMessage("match_manage_reportmsg_minute") . "</th>";
    echo "<th>" . $i18n->getMessage("entity_matchtext_aktion") . "</th>";
    echo "<th>" . $i18n->getMessage("entity_matchtext_nachricht") . "</th>";
    echo "<th>" . $i18n->getMessage("match_manage_reportmsg_playernames") . "</th>";
    echo "<th>" . $i18n->getMessage("match_manage_reportmsg_intermediateresult") . "</th>";
    echo "</tr>";
    echo "</thead>";
 /**
  * (non-PHPdoc)
  * @see IModel::getTemplateParameters()
  */
 public function getTemplateParameters()
 {
     return array('cups' => MatchesDataService::getCupRoundsByCupname($this->_websoccer, $this->_db));
 }
 /**
  * (non-PHPdoc)
  * @see IModel::getTemplateParameters()
  */
 public function getTemplateParameters()
 {
     $matches = MatchesDataService::getLatestMatches($this->_websoccer, $this->_db, 5, TRUE);
     return array('matches' => $matches);
 }
 public function getTemplateParameters()
 {
     $matches = MatchesDataService::getLatestMatchesByUser($this->_websoccer, $this->_db, $this->_userId);
     return array("matches" => $matches);
 }
 public function renderView()
 {
     $this->_match = MatchesDataService::getLiveMatch($this->_websoccer, $this->_db);
     return count($this->_match);
 }
 /**
  * Provides simulated matches of specified team.
  *
  * @param WebSoccer $websoccer Application context.
  * @param DbConnection $db DB connection.
  * @param int $teamId ID of team.
  * @param int $startIndex fetch index start.
  * @param int $eps entries per page.
  * @return array list of found matches.
  */
 public static function getSimulatedMatches(WebSoccer $websoccer, DbConnection $db, $teamId, $startIndex, $eps)
 {
     $whereCondition = "(home_verein = %d OR gast_verein = %d) AND berechnet = '1' ORDER BY datum DESC";
     return MatchesDataService::getMatchesByCondition($websoccer, $db, $whereCondition, array($teamId, $teamId), $startIndex . "," . $eps);
 }
 private function _updatePlayerPosition($parameters, $matchId, $teamId)
 {
     $players = MatchesDataService::getMatchPlayerRecordsByField($this->_websoccer, $this->_db, $matchId, $teamId);
     $playersOnField = $players['field'];
     // read submitted player positions
     $submittedPositions = array();
     for ($playerNo = 1; $playerNo <= 11; $playerNo++) {
         $playerId = $parameters['player' . $playerNo];
         $playerPos = $parameters['player' . $playerNo . '_pos'];
         if ($playerId && $playerPos) {
             $submittedPositions[$playerId] = $playerPos;
         }
     }
     $updateTable = $this->_websoccer->getConfig('db_prefix') . '_spiel_berechnung';
     $whereCondition = 'id = %d';
     $setupMainMapping = array('T' => 'Torwart', 'LV' => 'Abwehr', 'RV' => 'Abwehr', 'IV' => 'Abwehr', 'DM' => 'Mittelfeld', 'LM' => 'Mittelfeld', 'ZM' => 'Mittelfeld', 'RM' => 'Mittelfeld', 'OM' => 'Mittelfeld', 'LS' => 'Sturm', 'MS' => 'Sturm', 'RS' => 'Sturm');
     foreach ($playersOnField as $player) {
         if (isset($submittedPositions[$player['id']])) {
             $newPos = $submittedPositions[$player['id']];
             $oldPos = $player['match_position_main'];
             if ($newPos != $oldPos) {
                 $position = $setupMainMapping[$newPos];
                 // recompute strength
                 $strength = $player['strength'];
                 // player becomes weaker: wrong position
                 if ($player['position'] != $position && $player['position_main'] != $newPos && $player['position_second'] != $newPos) {
                     $strength = round($strength * (1 - $this->_websoccer->getConfig('sim_strength_reduction_wrongposition') / 100));
                     // player becomes weaker: secondary position
                 } elseif (strlen($player['position_main']) && $player['position_main'] != $newPos && ($player['position'] == $position || $player['position_second'] == $newPos)) {
                     $strength = round($strength * (1 - $this->_websoccer->getConfig('sim_strength_reduction_secondary') / 100));
                 }
                 $this->_db->queryUpdate(array('position_main' => $newPos, 'position' => $position, 'w_staerke' => $strength), $updateTable, $whereCondition, $player['match_record_id']);
             }
         }
     }
 }
 /**
  * (non-PHPdoc)
  * @see IModel::getTemplateParameters()
  */
 public function getTemplateParameters()
 {
     $matchId = (int) $this->_websoccer->getRequestParameter('id');
     if ($matchId < 1) {
         throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND));
     }
     $match = MatchesDataService::getMatchSubstitutionsById($this->_websoccer, $this->_db, $matchId);
     if ($match['match_simulated']) {
         throw new Exception($this->_i18n->getMessage('match_details_match_completed'));
     }
     $teamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db);
     if ($match['match_home_id'] !== $teamId && $match['match_guest_id'] !== $teamId) {
         $teamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db);
     }
     if ($teamId !== $match['match_home_id'] && $match['match_guest_id'] !== $teamId) {
         throw new Exception('illegal match');
     }
     $teamPrefix = $teamId == $match['match_home_id'] ? 'home' : 'guest';
     $players = MatchesDataService::getMatchPlayerRecordsByField($this->_websoccer, $this->_db, $matchId, $teamId);
     $playersOnField = $players['field'];
     $playersOnBench = isset($players['bench']) ? $players['bench'] : array();
     $formation = array();
     if ($this->_websoccer->getRequestParameter('freekickplayer')) {
         $formation['freekickplayer'] = $this->_websoccer->getRequestParameter('freekickplayer');
     } else {
         $formation['freekickplayer'] = $match['match_' . $teamPrefix . '_freekickplayer'];
     }
     if ($this->_websoccer->getRequestParameter('offensive')) {
         $formation['offensive'] = $this->_websoccer->getRequestParameter('offensive');
     } else {
         $formation['offensive'] = $match['match_' . $teamPrefix . '_offensive'];
     }
     if ($this->_websoccer->getRequestParameter('longpasses')) {
         $formation['longpasses'] = $this->_websoccer->getRequestParameter('longpasses');
     } else {
         $formation['longpasses'] = $match['match_' . $teamPrefix . '_longpasses'];
     }
     if ($this->_websoccer->getRequestParameter('counterattacks')) {
         $formation['counterattacks'] = $this->_websoccer->getRequestParameter('counterattacks');
     } else {
         $formation['counterattacks'] = $match['match_' . $teamPrefix . '_counterattacks'];
     }
     // get existing formation
     $playerNo = 0;
     foreach ($playersOnField as $player) {
         $playerNo++;
         $formation['player' . $playerNo] = $player['id'];
         $formation['player' . $playerNo . '_pos'] = $player['match_position_main'];
     }
     // set setup
     $setup = array('defense' => 6, 'dm' => 3, 'midfield' => 4, 'om' => 3, 'striker' => 2, 'outsideforward' => 2);
     $setupMainMapping = array('LV' => 'defense', 'RV' => 'defense', 'IV' => 'defense', 'DM' => 'dm', 'LM' => 'midfield', 'ZM' => 'midfield', 'RM' => 'midfield', 'OM' => 'om', 'LS' => 'outsideforward', 'MS' => 'striker', 'RS' => 'outsideforward');
     $setupPosMapping = array('Abwehr' => 'defense', 'Mittelfeld' => 'midfield', 'Sturm' => 'striker');
     // override formation by user input and count setup
     for ($playerNo = 1; $playerNo <= 11; $playerNo++) {
         if ($this->_websoccer->getRequestParameter('player' . $playerNo) > 0) {
             $formation['player' . $playerNo] = $this->_websoccer->getRequestParameter('player' . $playerNo);
             $formation['player' . $playerNo . '_pos'] = $this->_websoccer->getRequestParameter('player' . $playerNo . '_pos');
         }
     }
     // bench
     $benchNo = 0;
     foreach ($playersOnBench as $player) {
         $benchNo++;
         $formation['bench' . $benchNo] = $player['id'];
     }
     for ($benchNo = 1; $benchNo <= 5; $benchNo++) {
         if ($this->_websoccer->getRequestParameter('bench' . $benchNo)) {
             $formation['bench' . $benchNo] = $this->_websoccer->getRequestParameter('bench' . $benchNo);
         } else {
             if (!isset($formation['bench' . $benchNo])) {
                 $formation['bench' . $benchNo] = '';
             }
         }
     }
     // subs
     for ($subNo = 1; $subNo <= 3; $subNo++) {
         if ($this->_websoccer->getRequestParameter('sub' . $subNo . '_out')) {
             $formation['sub' . $subNo . '_out'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_out');
             $formation['sub' . $subNo . '_in'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_in');
             $formation['sub' . $subNo . '_minute'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_minute');
             $formation['sub' . $subNo . '_condition'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_condition');
             $formation['sub' . $subNo . '_position'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_position');
         } else {
             if (isset($match[$teamPrefix . '_sub' . $subNo . '_out'])) {
                 $formation['sub' . $subNo . '_out'] = $match[$teamPrefix . '_sub' . $subNo . '_out'];
                 $formation['sub' . $subNo . '_in'] = $match[$teamPrefix . '_sub' . $subNo . '_in'];
                 $formation['sub' . $subNo . '_minute'] = $match[$teamPrefix . '_sub' . $subNo . '_minute'];
                 $formation['sub' . $subNo . '_condition'] = $match[$teamPrefix . '_sub' . $subNo . '_condition'];
                 $formation['sub' . $subNo . '_position'] = $match[$teamPrefix . '_sub' . $subNo . '_position'];
             } else {
                 $formation['sub' . $subNo . '_out'] = '';
                 $formation['sub' . $subNo . '_in'] = '';
                 $formation['sub' . $subNo . '_minute'] = '';
                 $formation['sub' . $subNo . '_condition'] = '';
                 $formation['sub' . $subNo . '_position'] = '';
             }
         }
     }
     return array('setup' => $setup, 'players' => $players, 'formation' => $formation, 'minute' => $match['match_minutes']);
 }
 public function getTemplateParameters()
 {
     $matchinfo = MatchesDataService::getLastMatch($this->_websoccer, $this->_db);
     return array("last_match" => $matchinfo);
 }
    $formation["type"] = $match["match_type"];
    // update tactical parameters in match table
    $columnsPrefix = $teamPrefix == "guest" ? "gast" : "home";
    $matchColumns = array($columnsPrefix . "_offensive" => $formation["offensive"], $columnsPrefix . "_longpasses" => $formation["longpasses"], $columnsPrefix . "_counterattacks" => $formation["counterattacks"]);
    // update substitutions
    for ($subNo = 1; $subNo <= 3; $subNo++) {
        $matchColumns[$columnsPrefix . "_w" . $subNo . "_raus"] = $formation[$teamPrefix . "_sub" . $subNo . "_out"];
        $matchColumns[$columnsPrefix . "_w" . $subNo . "_rein"] = $formation[$teamPrefix . "_sub" . $subNo . "_in"];
        $matchColumns[$columnsPrefix . "_w" . $subNo . "_minute"] = $formation[$teamPrefix . "_sub" . $subNo . "_minute"];
        $matchColumns[$columnsPrefix . "_w" . $subNo . "_condition"] = $formation[$teamPrefix . "_sub" . $subNo . "_condition"];
    }
    $db->queryUpdate($matchColumns, $website->getConfig("db_prefix") . "_spiel", "id = %d", array($matchId));
    // create player records
    MatchSimulationExecutor::addPlayers($website, $db, $team, $formation, $teamPrefix);
}
$match = MatchesDataService::getMatchById($website, $db, $matchId, FALSE, FALSE);
if (!count($match)) {
    throw new Exception("illegal match id");
}
$positions = array('T', 'LV', 'IV', 'RV', 'LM', 'DM', 'ZM', 'OM', 'RM', 'LS', 'MS', 'RS');
// ******** form for adding players
echo "<form action=\"" . $_SERVER['PHP_SELF'] . "\" class=\"form-horizontal\" method=\"post\">";
echo "<input type=\"hidden\" name=\"action\" value=\"create\">";
echo "<input type=\"hidden\" name=\"site\" value=\"{$site}\">";
echo "<input type=\"hidden\" name=\"match\" value=\"{$matchId}\">";
echo "<fieldset><legend>" . $i18n->getMessage("match_manage_createplayer_title") . "</legend>";
echo "<div class=\"control-group\">";
echo "<label class=\"control-label\" for=\"team_id\">" . $i18n->getMessage("entity_player_verein_id") . "</label>";
echo "<div class=\"controls\">";
echo "<select name=\"team_id\" id=\"team_id\">";
echo "<option value=\"" . $match["match_home_id"] . "\">" . escapeOutput($match["match_home_name"]) . "</option>";