/** * (non-PHPdoc) * @see IModel::getTemplateParameters() */ public function getTemplateParameters() { $teamId = (int) $this->_websoccer->getRequestParameter('id'); if ($teamId < 1) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } $team = TeamsDataService::getTeamById($this->_websoccer, $this->_db, $teamId); if (!isset($team['team_id'])) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } // get current season $result = $this->_db->querySelect('id', $this->_websoccer->getConfig('db_prefix') . '_saison', 'liga_id = %d AND beendet = \'0\' ORDER BY name DESC', $team['team_league_id'], 1); $season = $result->fetch_array(); $result->free(); // get records $history = array(); if ($season) { $columns = array('H.matchday' => 'matchday', 'H.rank' => 'rank'); $fromTable = $this->_websoccer->getConfig('db_prefix') . '_leaguehistory AS H'; $result = $this->_db->querySelect('matchday, rank', $fromTable, 'season_id = %d AND team_id = %s ORDER BY matchday ASC', array($season['id'], $team['team_id'])); while ($historyRecord = $result->fetch_array()) { $history[] = $historyRecord; } $result->free(); } // count teams in league $result = $this->_db->querySelect('COUNT(*) AS cnt', $this->_websoccer->getConfig('db_prefix') . '_verein', 'liga_id = %d AND status = \'1\'', $team['team_league_id'], 1); $teams = $result->fetch_array(); $result->free(); return array('teamName' => $team['team_name'], 'history' => $history, 'noOfTeamsInLeague' => $teams['cnt'], 'leagueid' => $team['team_league_id']); }
/** * (non-PHPdoc) * @see IModel::getTemplateParameters() */ public function getTemplateParameters() { $teamId = (int) $this->_websoccer->getRequestParameter('id'); if ($teamId < 1) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } $team = TeamsDataService::getTeamById($this->_websoccer, $this->_db, $teamId); if (!isset($team['team_id'])) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } $stadium = StadiumsDataService::getStadiumByTeamId($this->_websoccer, $this->_db, $teamId); // compute strength level of national team if ($team['is_nationalteam']) { $dbPrefix = $this->_websoccer->getConfig('db_prefix'); $result = $this->_db->querySelect('AVG(P.w_staerke) AS avgstrength', $dbPrefix . '_spieler AS P INNER JOIN ' . $dbPrefix . '_nationalplayer AS NP ON P.id = NP.player_id', 'NP.team_id = %d', $team['team_id']); $players = $result->fetch_array(); $result->free(); if ($players) { $team['team_strength'] = $players['avgstrength']; } } if (!$team['is_nationalteam']) { $playerfacts = $this->getPlayerFacts($teamId); } else { $playerfacts = array(); } $team['victories'] = $this->getVictories($team['team_id'], $team['team_league_id']); $team['cupvictories'] = $this->getCupVictories($team['team_id']); return array('team' => $team, 'stadium' => $stadium, 'playerfacts' => $playerfacts); }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $user = $this->_websoccer->getUser(); $clubId = $user->getClubId($this->_websoccer, $this->_db); $team = TeamsDataService::getTeamById($this->_websoccer, $this->_db, $clubId); // check if it is own player $player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $parameters["id"]); if ($clubId != $player["team_id"]) { throw new Exception("nice try"); } $this->_db->queryUpdate(array("captain_id" => $parameters["id"]), $this->_websoccer->getConfig("db_prefix") . "_verein", "id = %d", $clubId); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("myteam_player_select_as_captain_success"), "")); // check if captain has been changed and show disappointment if ($team["captain_id"] && $team["captain_id"] != $parameters["id"]) { $oldPlayer = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $team["captain_id"]); // maybe player has moved to new team, then just ignore it if ($oldPlayer["team_id"] == $clubId) { $newSatisfaction = round($oldPlayer["player_strength_satisfaction"] * 0.6); $this->_db->queryUpdate(array("w_zufriedenheit" => $newSatisfaction), $this->_websoccer->getConfig("db_prefix") . "_spieler", "id = %d", $oldPlayer["player_id"]); $playername = strlen($oldPlayer["player_pseudonym"]) ? $oldPlayer["player_pseudonym"] : $oldPlayer["player_firstname"] . " " . $oldPlayer["player_lastname"]; $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_WARNING, $this->_i18n->getMessage("myteam_player_select_as_captain_warning_old_captain", $playername), "")); } } return null; }