public static function manage() { $league = current(LeagueModel::get($_GET["id"])); // check permissions $visitor = User::getVisitor(); if ($visitor->id != $league->managerId) { Controller::requirePermissions(["AdminAllLeagues"]); } if (!empty($_POST)) { if (array_key_exists("update-team-numbers", $_POST)) { $teams = $league->getAssignedTeams(); foreach ($teams as $team) { if (array_key_exists("team" . $team->id . "number", $_POST)) { Team::update($team->id, null, null, null, null, $_POST["team" . $team->id . "number"]); } } Controller::addAlert(new Alert("success", "Team assigned numbers updated successfully")); } else { if (array_key_exists("update-league-details", $_POST)) { LeagueModel::update($_POST["id"], $_POST["name"], $_POST["manager"]); Controller::addAlert(new Alert("success", "League details updated successfully")); $league = current(LeagueModel::get($_POST["id"])); } } } // construct fixtures $fixtures = Fixture::get(null, $league->id); View::load("acp/league_manage.twig", ["users" => User::get(), "league" => $league, "fixtures" => $fixtures, "unassignedTeams" => Team::get(null, null, null, false, $_GET["id"])]); }
public static function delete() { Controller::requirePermissions(["AdminAccessDashboard"]); $fixture = current(FixtureModel::get($_GET["id"])); if (!$fixture) { Controller::addAlert(new Alert("success", "The specified fixture does not exist")); Controller::redirect("/acp/league"); } $league = $fixture->getLeague(); // check permissions $visitor = UserModel::getVisitor(); if ($visitor->id != $league->managerId) { Controller::requirePermissions(["AdminAllLeagues"]); } $fixture->delete(); Controller::addAlert(new Alert("success", "Fixture deleted successfully")); Controller::redirect("/acp/league/manage?id=" . $league->id); }
/** * Construct a nice array of dates to fixtures * * @return array like such: * [ * "18/09/2015" => [ * \stdClass( * $homeTeam, * $awayTeam * ), * \stdClass( * $homeTeam, * $awayTeam * ) * ] * ] */ public function constructFixtures() { // first we grab all fixtures for the league $fixtures = Fixture::get(null, $this->id, true); // we'll also be needing all sections $sections = LeagueSection::get(null, $this->id); // now we iterate over and expand them into teams /** * @var $returnData * struc: * [ * "18/09/2015" => [ * \stdClass( * $homeTeam, * $awayTeam * ), * \stdClass( * $homeTeam, * $awayTeam * ) * ] * ] */ $returnData = []; foreach ($fixtures as $fixture) { if (!array_key_exists($fixture->playByDate, $returnData)) { $returnData[$fixture->playByDate] = []; } if ($fixture->homeTeamId && $fixture->awayTeamId) { // id vs id are easy peasy $obj = new \stdClass(); $obj->homeTeam = $fixture->homeTeam->organization->name . " " . $fixture->homeTeam->designation; $obj->awayTeam = $fixture->awayTeam->organization->name . " " . $fixture->awayTeam->designation; $returnData[$fixture->playByDate][] = $obj; } else { foreach ($sections as &$section) { // pass by reference is important! otherwise we lose the assigned teams on the next loop and have to re-query (very costly!) $homeTeam = false; $awayTeam = false; $potentialTeams = $section->getAssignedTeams(); // dwbi this is quick cached foreach ($potentialTeams as $potentialTeam) { if ($fixture->homeTeamAssignedNumber == $potentialTeam->assignedNumber) { $homeTeam = $potentialTeam->organization->name . " " . $potentialTeam->designation; } else { if ($fixture->awayTeamAssignedNumber == $potentialTeam->assignedNumber) { $awayTeam = $potentialTeam->organization->name . " " . $potentialTeam->designation; } } } if ($homeTeam && $awayTeam) { $obj = new \stdClass(); $obj->homeTeam = $homeTeam; $obj->awayTeam = $awayTeam; $returnData[$fixture->playByDate][] = $obj; } } } } return $returnData; }