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