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"])]);
 }
 /**
  * Get assigned teams
  *
  * @param int $orderMethod one of the order method constants (ASSIGNED_NUMBER, POINTS)
  * @return Team[]
  */
 public function getAssignedTeams($orderMethod = Team::ASSIGNED_NUMBER)
 {
     if (!$this->assignedTeams) {
         $this->assignedTeams = Team::get(null, null, null, $this->id, null, $orderMethod);
     }
     return $this->assignedTeams;
 }
 /**
  * Get team
  *
  * @return \sma\models\Team
  */
 public function getTeam()
 {
     if (!$this->team) {
         $this->team = TeamModel::get($this->teamId);
     }
     return $this->team;
 }
 public static function index()
 {
     Controller::requirePermissions(["AdminAccessDashboard"]);
     if (!empty($_POST)) {
         Setting::set("info_box_content", $_POST["info"]);
     }
     View::load("acp/index.twig", ["organizationCount" => count(Organization::get()), "teamCount" => count(Team::get()), "unassignedTeams" => Team::get(null, null, null, false, false), "info" => Setting::get("info_box_content"), "mismatches" => Match::get(null, null, null, null, null, Match::STATUS_MISMATCH)]);
 }
 public static function delete()
 {
     Controller::requireFields("get", ["id"], "/acp/team");
     Controller::requirePermissions(["AdminAccessDashboard", "AdminTeams", "AdminPlayers", "PerformDeletionOperations"]);
     $team = current(TeamModel::get($_GET["id"]));
     $team->delete();
     Controller::addAlert(new Alert("success", "Team deleted successfully"));
     Controller::redirect("/acp/team");
 }
 public static function manage()
 {
     Controller::requirePermissions(["AdminAccessDashboard", "AdminMatches"]);
     $match = current(MatchModel::get($_GET["id"]));
     if (!$match) {
         Controller::addAlert(new Alert("danger", "The match you specified could not be found."));
         Controller::redirect("/acp/match");
     }
     View::load("acp/match_manage.twig", ["match" => $match, "teams" => Team::get(null, null, null, null, $match->leagueId)]);
 }
 public static function teams()
 {
     $leagueId = array_key_exists("league", $_GET) ? $_GET["league"] : null;
     $organizationId = array_key_exists("organization", $_GET) ? $_GET["organization"] : null;
     if (array_key_exists("team", $_GET)) {
         $leagueSectionId = current(Team::get($_GET["team"]))->leagueSectionId;
     } else {
         $leagueSectionId = null;
     }
     $teams = Team::get(null, $organizationId, null, $leagueSectionId, $leagueId);
     $return = [];
     foreach ($teams as $team) {
         $data = new \stdClass();
         $data->id = $team->id;
         $data->string = $team->organization->name . " " . $team->designation;
         $return[] = $data;
     }
     echo json_encode($return);
 }
 /**
  * Get assigned teams
  *
  * @return \sma\models\Team[]
  */
 public function getAssignedTeams()
 {
     if (!$this->assignedTeams) {
         $this->assignedTeams = Team::get(null, null, null, null, $this->id);
     }
     return $this->assignedTeams;
 }
 public static function addplayer()
 {
     Controller::requireFields("post", ["name", "team"], "/acp/team");
     $team = current(TeamModel::get($_POST["team"]));
     if (!User::getVisitor()->checkPermissions(["RegisterTeamsForAnyOrganization"])) {
         Controller::requirePermissions(["RegisterTeamsForOwnOrganization"]);
         if ($team->organizationId != User::getVisitor()->organizationId) {
             ErrorHandler::forbidden();
         }
     }
     Player::add($_POST["name"], $team->id, false);
     Controller::addAlert(new Alert("success", "Player added successfully"));
     Controller::redirect("/team/edit?id=" . $team->id);
 }
 public static function submitted()
 {
     Controller::requirePermissions(["SubmitMatchReports"]);
     $visitor = User::getVisitor();
     $teams = Team::get(null, $visitor->organizationId);
     $teamIds = [];
     foreach ($teams as $team) {
         $teamIds[] = $team->id;
     }
     $reports = MatchReport::get(null, null, null, $teamIds, 25);
     View::load("match/submitted.twig", ["organizationReports" => $reports, "userReports" => MatchReport::get(null, null, $visitor->id, null, 25)]);
 }