function OnPostback() { # Get the match info and store it $i_id = $this->manager->GetItemId($this->match); $this->manager->ReadByMatchId(array($i_id)); $this->match = $this->manager->GetFirst(); if (!$this->match instanceof Match) { # This can be the case if the back button is used to go back to the "match has been deleted" page. $this->b_deleted = true; return; } # Check whether cancel was clicked if (isset($_POST['cancel'])) { $this->Redirect($this->match->GetNavigateUrl()); } # Check whether delete was clicked if (isset($_POST['delete'])) { # Check again that the requester has permission to delete this match $has_permission = (AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_MATCHES) or AuthenticationManager::GetUser()->GetId() == $this->match->GetAddedBy()->GetId()); if ($has_permission) { # Delete the match $this->manager->DeleteMatch(array($i_id)); # Remove match, and all dependent tournament matches, from search results foreach ($this->match->GetMatchesInTournament() as $tournament_match) { $this->SearchIndexer()->DeleteFromIndexById("match" . $tournament_match->GetId()); } $this->SearchIndexer()->DeleteFromIndexById("match" . $this->match->GetId()); $this->SearchIndexer()->CommitChanges(); require_once 'stoolball/data-change-notifier.class.php'; $notifier = new DataChangeNotifier($this->GetSettings()); $notifier->MatchUpdated($this->match, AuthenticationManager::GetUser(), false, true); # Update 'next 5 matches' $this->manager->ReadNext(); $this->a_next_matches = $this->manager->GetItems(); # Note success $this->b_deleted = true; } } }
/** * Creates the controls to edit the matches * */ private function CreateMatchControls(Match $tournament, XhtmlElement $box) { $css_class = 'TournamentEdit'; $box->SetCssClass($css_class); $this->SetCssClass(''); $box->SetXhtmlId($this->GetNamingPrefix()); $this->AddControl($box); # Preserve tournament title and date, because we need them for the page title when "add" is clicked $title = new TextBox($this->GetNamingPrefix() . 'Title', $tournament->GetTitle(), $this->IsValidSubmit()); $title->SetMode(TextBoxMode::Hidden()); $box->AddControl($title); $date = new TextBox($this->GetNamingPrefix() . 'Start', $tournament->GetStartTime(), $this->IsValidSubmit()); $date->SetMode(TextBoxMode::Hidden()); $box->AddControl($date); # Matches editor $this->EnsureAggregatedEditors(); $this->matches_editor->DataObjects()->SetItems($tournament->GetMatchesInTournament()); $this->matches_editor->SetTeams($tournament->GetAwayTeams()); $box->AddControl($this->matches_editor); }
/** * Saves the supplied match array as the matches in a tournament * @param Match $tournament_id */ public function SaveMatchesInTournament(Match $tournament) { $match_ids_to_keep = array(); foreach ($tournament->GetMatchesInTournament() as $match) { /* @var $match Match */ if (!$match instanceof Match or $match->GetMatchType() !== MatchType::TOURNAMENT_MATCH) { continue; } if ($match->GetId()) { $match_ids_to_keep[] = $match->GetId(); } } # Delete unwanted matches $match_ids_to_delete = array(); $sql = "SELECT match_id FROM nsa_match \r\n WHERE tournament_match_id = " . Sql::ProtectNumeric($tournament->GetId(), false, false) . "\r\n AND match_id NOT IN (" . join(',', $match_ids_to_keep) . ") "; $result = $this->GetDataConnection()->query($sql); while ($row = $result->fetch()) { $match_ids_to_delete[] = $row->match_id; } if (count($match_ids_to_delete)) { $this->DeleteMatch($match_ids_to_delete); } # Add and update matches foreach ($tournament->GetMatchesInTournament() as $match) { /* @var $match Match */ if (!$match instanceof Match or $match->GetMatchType() !== MatchType::TOURNAMENT_MATCH) { continue; } if (!$match->GetId()) { $this->SaveFixture($match); } $this->SaveMatchOrderInTournament($match->GetId(), $match->GetOrderInTournament()); $this->CopyTournamentMatchDetailsFromTournament($tournament, $match); } }
function OnPageLoad() { $is_tournament = $this->match->GetMatchType() == MatchType::TOURNAMENT; $class = $is_tournament ? "match" : "match vevent"; ?> <div class="$class" typeof="schema:SportsEvent" about="<?php echo Html::Encode($this->match->GetLinkedDataUri()); ?> "> <?php require_once 'xhtml/navigation/tabs.class.php'; $tabs = array('Summary' => ''); if ($is_tournament) { $tabs['Tournament statistics'] = $this->match->GetNavigateUrl() . '/statistics'; # Make sure the reader knows this is a tournament, and the player type $says_tournament = strpos(strtolower($this->match->GetTitle()), 'tournament') !== false; $player_type = PlayerType::Text($this->match->GetPlayerType()); $says_player_type = strpos(strtolower($this->match->GetTitle()), strtolower(rtrim($player_type, '\''))) !== false; $page_title = $this->match->GetTitle() . ", " . Date::BritishDate($this->match->GetStartTime(), false); if (!$says_tournament and !$says_player_type) { $page_title .= ' (' . $player_type . ' stoolball tournament)'; } else { if (!$says_tournament) { $page_title .= ' stoolball tournament'; } else { if (!$says_player_type) { $page_title .= ' (' . $player_type . ')'; } } } $heading = new XhtmlElement('h1', $page_title); $heading->AddAttribute("property", "schema:name"); echo $heading; } else { if ($this->match->GetMatchType() == MatchType::TOURNAMENT_MATCH) { $tabs['Match statistics'] = $this->match->GetNavigateUrl() . '/statistics'; $tabs['Tournament statistics'] = $this->match->GetTournament()->GetNavigateUrl() . '/statistics'; $page_title = $this->match->GetTitle() . " in the " . $this->match->GetTournament()->GetTitle(); } else { $tabs['Statistics'] = $this->match->GetNavigateUrl() . '/statistics'; $page_title = $this->match->GetTitle(); } $o_title = new XhtmlElement('h1', Html::Encode($page_title)); $o_title->AddAttribute("property", "schema:name"); # hCalendar $o_title->SetCssClass('summary'); $o_title_meta = new XhtmlElement('span', ' (stoolball)'); $o_title_meta->SetCssClass('metadata'); $o_title->AddControl($o_title_meta); if ($this->match->GetMatchType() !== MatchType::TOURNAMENT_MATCH) { $o_title->AddControl(", " . Date::BritishDate($this->match->GetStartTime(), false)); } echo $o_title; } echo new Tabs($tabs); ?> <div class="box tab-box"> <div class="dataFilter"></div> <div class="box-content"> <?php if ($is_tournament) { require_once 'stoolball/tournaments/tournament-control.class.php'; echo new TournamentControl($this->GetSettings(), $this->match); } else { require_once 'stoolball/matches/match-control.class.php'; echo new MatchControl($this->GetSettings(), $this->match); } $this->DisplayComments(); $this->ShowSocial(); ?> </div> </div> </div> <?php $this->AddSeparator(); # add/edit/delete options $user_is_admin = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_MATCHES); $user_is_owner = AuthenticationManager::GetUser()->GetId() == $this->match->GetAddedBy()->GetId(); $panel = new UserEditPanel($this->GetSettings(), 'this match'); $panel->AddCssClass("with-tabs"); if ($user_is_admin or $user_is_owner) { $link_text = $is_tournament ? 'tournament' : 'match'; $panel->AddLink('edit this ' . $link_text, $this->match->GetEditNavigateUrl()); } else { if ($this->match->GetMatchType() != MatchType::PRACTICE and !$is_tournament) { $panel->AddLink('update result', $this->match->GetEditNavigateUrl()); } } if ($is_tournament) { $panel->AddCssClass("with-tabs"); if ($user_is_admin or $user_is_owner) { $panel->AddLink('add or remove teams', $this->match->EditTournamentTeamsUrl()); } $panel->AddLink('add or remove matches', $this->match->GetEditTournamentMatchesUrl()); if (count($this->match->GetMatchesInTournament())) { $panel->AddLink('update results', $this->match->GetNavigateUrl() . "/matches/results"); } } if ($user_is_admin or $user_is_owner) { if ($is_tournament) { $panel->AddLink('edit where to list this tournament', $this->match->EditTournamentCompetitionsUrl()); } $link_text = $is_tournament ? 'tournament' : 'match'; $panel->AddLink('delete this ' . $link_text, $this->match->GetDeleteNavigateUrl()); } if ($this->match->GetMatchType() != MatchType::TOURNAMENT_MATCH and $this->match->GetStartTime() > time()) { $link_text = $is_tournament ? 'tournament' : 'match'; $panel->AddLink("add {$link_text} to your calendar", $this->match->GetCalendarNavigateUrl()); } echo $panel; if ($this->has_player_stats) { $tournament = $is_tournament ? $this->match : $this->match->GetTournament(); require_once 'stoolball/statistics-highlight-table.class.php'; echo new StatisticsHighlightTable($this->best_batting, $this->most_runs, $this->best_bowling, $this->most_wickets, $this->most_catches, "tournament"); echo '<p class="playerSummaryMore"><a href="' . $tournament->GetNavigateUrl() . '/statistics">Tournament statistics</a></p>'; } }