public function OnPreRender()
 {
     $by = $this->player->GetPlayerRole() == \Player::PLAYER ? ", " : " conceded by ";
     $this->AddControl('<h1><span property="schema:name">' . \Html::Encode($this->player->GetName()) . '</span>' . \Html::Encode($by . ' ' . $this->player->Team()->GetName() . $this->filter_description) . "</h1>");
     # When has this player played?
     $match_or_matches = $this->player->GetTotalMatches() == 1 ? " match" : " matches";
     $years = $this->player->GetPlayingYears();
     $filtered = "";
     if ($this->filter_description) {
         # If first played date is missing, the player came from PlayerManager because there were no statistics found
         if (!$this->filter_matched_nothing) {
             $filtered = " matching this filter";
         } else {
             $filtered = ", but none match this filter";
             $years = '';
         }
     }
     $team_name = '<span rel="schema:memberOf"><span about="' . \Html::Encode($this->player->Team()->GetLinkedDataUri()) . '" typeof="schema:SportsTeam"><a property="schema:name" rel="schema:url" href="' . \Html::Encode($this->player->Team()->GetNavigateUrl()) . "\">" . \Html::Encode($this->player->Team()->GetName()) . "</a></span></span>";
     if ($this->player->GetPlayerRole() == \Player::PLAYER) {
         if ($this->player->GetTotalMatches() == 0) {
             $played_total = " hasn't played any " . $match_or_matches;
         } else {
             $played_total = ' played <a href="/play/statistics/player-performances' . $this->filter_querystring . '">' . $this->player->GetTotalMatches() . $match_or_matches . '</a>';
         }
         $this->AddControl("<p>" . \Html::Encode($this->player->GetName()) . $played_total . " for {$team_name}{$filtered}{$years}.</p>");
         # Player of match
         if ($this->player->GetTotalPlayerOfTheMatchNominations() > 0) {
             $match_or_matches = $this->player->GetTotalPlayerOfTheMatchNominations() == 1 ? " match." : " matches.";
             $this->AddControl('<p>Nominated <a href="/play/statistics/player-of-match' . $this->filter_querystring . '">player of the match</a> in ' . $this->player->GetTotalPlayerOfTheMatchNominations() . $match_or_matches . "</p>");
         }
     } else {
         $this->AddControl("<p>{$team_name} recorded " . \Html::Encode($this->player->TotalRuns() . " " . strtolower($this->player->GetName()) . " in " . $this->player->GetTotalMatches() . $match_or_matches . "{$filtered}{$years}.") . "</p>");
     }
 }
コード例 #2
0
    public function OnPageLoad()
    {
        echo "<h1>" . htmlentities($this->GetPageTitle(), ENT_QUOTES, "UTF-8", false) . "</h1>";
        if ($this->add_player_already_exists) {
            ?>
            <p><a href="<?php 
            echo Html::Encode($this->player->GetPlayerUrl());
            ?>
"><?php 
            echo Html::Encode($this->player->GetName());
            ?>
</a> is already listed as a player.</p>
            <p>Return to <a href="<?php 
            echo Html::Encode($this->player->Team()->GetPlayersNavigateUrl());
            ?>
">players for <?php 
            echo Html::Encode($this->player->Team()->GetName());
            ?>
</a>.</p>
            <?php 
        } else {
            if ($this->player->GetPlayerRole() == Player::PLAYER) {
                $this->editor->SetDataObject($this->player);
                echo $this->editor;
            } else {
                ?>
Sorry, an extras player can't be renamed.<?php 
            }
        }
    }
 public function __construct(Player $player)
 {
     $this->searchable = new SearchItem("player", "player" . $player->GetId(), $player->GetPlayerUrl());
     $this->searchable->Description($player->GetPlayerDescription());
     $this->searchable->WeightOfType(20);
     if ($player->GetPlayerRole() == Player::PLAYER) {
         $this->searchable->Title($player->GetName() . ", " . $player->Team()->GetName());
         $this->searchable->WeightWithinType($player->GetTotalMatches());
     } else {
         $this->searchable->Title($player->GetName() . " conceded by " . $player->Team()->GetName());
     }
     $this->searchable->Keywords($this->searchable->Title());
 }
 /**
  * Merges the records for two players, retaining the id of the destination player
  * @param int $source_player_id
  * @param int $destination_player_id
  * @return void
  */
 public function MergePlayers(Player $source_player, Player $destination_player)
 {
     if (!$source_player->GetId()) {
         throw new Exception("source_player must have an Id");
     }
     if (!$destination_player->GetId()) {
         throw new Exception("destination_player must have an Id");
     }
     if ($source_player->GetPlayerRole() != PLAYER::PLAYER) {
         throw new Exception("Cannot merge source player because it's an extras player");
     }
     if ($destination_player->GetPlayerRole() != PLAYER::PLAYER) {
         throw new Exception("Cannot merge destination player because it's an extras player");
     }
     $players = $this->GetSettings()->GetTable("Player");
     $batting = $this->GetSettings()->GetTable("Batting");
     $bowling = $this->GetSettings()->GetTable("Bowling");
     $matches = $this->GetSettings()->GetTable("Match");
     $statistics = $this->GetSettings()->GetTable("PlayerMatch");
     # Make a note of matches where source player was involved
     $sql = "SELECT DISTINCT match_team_id FROM {$batting} WHERE player_id = " . $source_player->GetId();
     $result = $this->GetDataConnection()->query($sql);
     $source_batted = array();
     while ($row = $result->fetch()) {
         $source_batted[] = $row->match_team_id;
     }
     $sql = "SELECT match_team_id FROM {$statistics}\n\t\t\t\tWHERE player_id = " . $source_player->GetId() . " AND (run_outs > 0 OR catches > 0)";
     $result = $this->GetDataConnection()->query($sql);
     $source_fielded = array();
     while ($row = $result->fetch()) {
         $source_fielded[] = $row->match_team_id;
     }
     $sql = "SELECT match_team_id FROM {$statistics}\n\t\t\t\tWHERE player_id = " . $source_player->GetId() . " AND wickets IS NOT NULL";
     $result = $this->GetDataConnection()->query($sql);
     $source_bowled = array();
     while ($row = $result->fetch()) {
         $source_bowled[] = $row->match_team_id;
     }
     $sql = "SELECT match_id FROM {$statistics}\n\t\t\t\tWHERE player_id = " . $source_player->GetId() . " AND player_of_match = 1";
     $result = $this->GetDataConnection()->query($sql);
     $source_player_of_match = array();
     while ($row = $result->fetch()) {
         $source_player_of_match[] = $row->match_id;
     }
     # Transfer batting and bowling
     $this->LoggedQuery("UPDATE {$batting} SET player_id = " . Sql::ProtectNumeric($destination_player->GetId()) . "\n\t\tWHERE player_id = " . Sql::ProtectNumeric($source_player->GetId()));
     $this->LoggedQuery("UPDATE {$batting} SET dismissed_by_id = " . Sql::ProtectNumeric($destination_player->GetId()) . "\n\t\tWHERE dismissed_by_id = " . Sql::ProtectNumeric($source_player->GetId()));
     $this->LoggedQuery("UPDATE {$batting} SET bowler_id = " . Sql::ProtectNumeric($destination_player->GetId()) . "\n\t\tWHERE bowler_id = " . Sql::ProtectNumeric($source_player->GetId()));
     $this->LoggedQuery("UPDATE {$bowling} SET player_id = " . Sql::ProtectNumeric($destination_player->GetId()) . "\n\t\tWHERE player_id = " . Sql::ProtectNumeric($source_player->GetId()));
     # Update dismissals in stats table too, because then fielding statistics will update correctly below.
     # Normally dismissals are updated with the batting, but here it's quite possible we are only updating the fielding.
     $this->LoggedQuery("UPDATE {$statistics} SET caught_by = " . Sql::ProtectNumeric($destination_player->GetId()) . "\n\t\tWHERE caught_by = " . Sql::ProtectNumeric($source_player->GetId()));
     $this->LoggedQuery("UPDATE {$statistics} SET run_out_by = " . Sql::ProtectNumeric($destination_player->GetId()) . "\n\t\tWHERE run_out_by = " . Sql::ProtectNumeric($source_player->GetId()));
     if (!$this->is_internal_delete) {
         # Doing an internal delete the destination player will be Unknown. Transfer batting and bowling
         # because that preserves the position for other bowlers and batters as well as related statistics
         # such as number of runs. But set player of the match to null because there's not much value in
         # setting it unknown.
         # Transfer player of the match award
         $this->LoggedQuery("UPDATE {$matches} SET player_of_match_id = " . Sql::ProtectNumeric($destination_player->GetId()) . ",\n\t\t\tdate_changed = " . gmdate('U') . "\n\t\t\tWHERE player_of_match_id = " . Sql::ProtectNumeric($source_player->GetId()));
         $this->LoggedQuery("UPDATE {$matches} SET player_of_match_home_id = " . Sql::ProtectNumeric($destination_player->GetId()) . ",\n\t\t\tdate_changed = " . gmdate('U') . "\n\t\t\tWHERE player_of_match_home_id = " . Sql::ProtectNumeric($source_player->GetId()));
         $this->LoggedQuery("UPDATE {$matches} SET player_of_match_away_id = " . Sql::ProtectNumeric($destination_player->GetId()) . ",\n\t\t\tdate_changed = " . gmdate('U') . "\n\t\t\tWHERE player_of_match_away_id = " . Sql::ProtectNumeric($source_player->GetId()));
         # If a user has claimed either player, remember that. If two different claimants, prefer the destination one.
         if ($source_player->GetUser() instanceof User and $source_player->GetUser()->GetId()) {
             $this->LoggedQuery("UPDATE {$players}\n\t\t\t\tSET user_id = " . Sql::ProtectNumeric($source_player->GetUser()->GetId()) . ",\n\t\t\t\tdate_changed = " . gmdate('U') . "\n\t\t\t\tWHERE player_id = " . Sql::ProtectNumeric($destination_player->GetId()) . " AND user_id = NULL");
         }
         # Now that the source player's data has been moved, delete the source player
         $this->Delete(array($source_player->GetId()));
     }
     # Recalculate all the derived data
     # Note: this method is tightly integrated with the Delete() method. They call each other. When the source player
     # is deleted, above, it will call back into this method before all the derived statistics for the source player
     # have gone. Therefore the queries at the top of this method will find the source player still exists. That in turn
     # leads to these methods being called for a player which has only derived statistics, and no actual data. It is
     # important therefore to call DeleteObsoleteStatistics() to clear out the redundant records as soon as they created.
     require_once 'stoolball/statistics/statistics-manager.class.php';
     $statistics_manager = new StatisticsManager($this->GetSettings(), $this->GetDataConnection());
     if (count($source_batted)) {
         $statistics_manager->UpdateBattingStatistics(array($destination_player->GetId()), $source_batted);
     }
     if (count($source_fielded)) {
         $statistics_manager->UpdateFieldingStatistics(array($destination_player->GetId()), $source_fielded);
     }
     if (count($source_bowled)) {
         $statistics_manager->UpdateBowlingStatistics(array($destination_player->GetId()), $source_bowled);
     }
     foreach ($source_player_of_match as $match_id) {
         $statistics_manager->UpdatePlayerOfTheMatchStatistics($match_id);
         $statistics_manager->DeleteObsoleteStatistics($match_id);
     }
     $statistics_manager->UpdatePlayerStatistics(array($destination_player->GetId()));
     unset($statistics_manager);
 }
コード例 #5
0
    function OnPageLoad()
    {
        if (!$this->player instanceof Player) {
            echo new XhtmlElement('h1', 'Player already deleted');
            echo new XhtmlElement('p', "The player you're trying to delete does not exist or has already been deleted.");
            return;
        }
        echo new XhtmlElement('h1', 'Delete player: <cite>' . Html::Encode($this->player->GetName()) . '</cite>');
        if ($this->player->GetPlayerRole() != Player::PLAYER) {
            ?>
Sorry, an extras player can't be deleted.<?php 
            return;
        }
        if ($this->b_deleted) {
            echo "<p>" . Html::Encode($this->player->GetName()) . "'s information has been deleted.</p>\n\t\t\t<p><a href=\"" . Html::Encode($this->player->Team()->GetPlayersNavigateUrl()) . "\">List players for " . Html::Encode($this->player->Team()->GetName()) . "</a></p>";
        } else {
            $has_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_PLAYERS);
            if ($has_permission) {
                $s_detail = $this->player->GetName() . " has ";
                switch ($this->player->GetTotalMatches()) {
                    case 0:
                        $s_detail .= "not played any matches";
                        break;
                    case 1:
                        $s_detail .= "played one match";
                        break;
                    default:
                        $s_detail .= "played " . $this->player->GetTotalMatches() . " matches";
                        break;
                }
                $s_detail .= " for " . $this->player->Team()->GetName() . '. ';
                echo new XhtmlElement('p', Html::Encode($s_detail));
                ?>
<p>Deleting a player cannot be undone. Their scores and performances
will be removed from all match scorecards and statistics.</p>
<p>Are you sure you want to delete this player?</p>
<form action="<?php 
                echo Html::Encode($this->player->GetDeleteUrl());
                ?>
" method="post"
	class="deleteButtons">
<div><input type="submit" value="Delete player" name="delete" /> <input
	type="submit" value="Cancel" name="cancel" /></div>
</form>
				<?php 
                $this->AddSeparator();
                require_once 'stoolball/user-edit-panel.class.php';
                $panel = new UserEditPanel($this->GetSettings(), $this->player->GetName());
                $panel->AddLink("view this player", $this->player->GetPlayerUrl());
                $panel->AddLink("rename this player", $this->player->GetEditUrl());
                echo $panel;
            } else {
                ?>
<p>Sorry, you can't delete a player unless you're responsible for
updating their team.</p>
<p><a href="<?php 
                echo Html::Encode($this->player->GetPlayerUrl());
                ?>
">Go back to <?php 
                echo Html::Encode($this->player->GetName());
                ?>
's
profile</a></p>
				<?php 
            }
        }
    }
コード例 #6
0
 public function OnPageLoad()
 {
     if ($this->not_found) {
         require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/stoolball/section-404.php";
         return;
     }
     if ($this->regenerating) {
         echo $this->regenerating_control;
         return;
     }
     # Container element for structured data
     echo '<div typeof="schema:Person" about="' . htmlentities($this->player->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false) . '">';
     $querystring = '?player=' . $this->player->GetId();
     if ($_SERVER["QUERY_STRING"]) {
         $querystring = htmlspecialchars('?' . $_SERVER["QUERY_STRING"]);
     }
     require_once "stoolball/statistics/player-summary-control.class.php";
     echo new \Stoolball\Statistics\PlayerSummaryControl($this->player, $this->filter, $this->filter_matched_nothing, $querystring);
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         require_once 'xhtml/navigation/tabs.class.php';
         $tabs = array('Batting' => '', 'Bowling and fielding' => $this->player->GetPlayerUrl() . '/bowling');
         echo new Tabs($tabs);
         ?>
         <div class="box tab-box">
             <div class="dataFilter"></div>
             <div class="box-content">
         <?php 
     }
     # Filter control
     echo $this->filter_control;
     # Batting stats
     if ($this->player->TotalBattingInnings()) {
         //echo "<h2>Batting</h2>";
         # Overview table
         $batting_table = new XhtmlTable();
         $batting_table->SetCssClass("numeric");
         $batting_table->SetCaption("Batting");
         $batting_heading_row = new XhtmlRow(array('<abbr title="Innings" class="small">Inn</abbr><span class="large">Innings</span>', "Not out", "Runs", "50s", "100s", "Best", '<abbr title="Average" class="small">Avg</abbr><span class="large">Average</span>', '<abbr title="Strike rate" class="small">S/R</abbr><span class="large">Strike rate</span>'));
         $batting_heading_row->SetIsHeader(true);
         $batting_table->AddRow($batting_heading_row);
         $batting_table->AddRow(new XhtmlRow(array($this->player->TotalBattingInnings(), $this->player->NotOuts(), $this->player->TotalRuns(), $this->player->Fifties(), $this->player->Centuries(), $this->player->BestBatting(), is_null($this->player->BattingAverage()) ? "&#8211;" : $this->player->BattingAverage(), is_null($this->player->BattingStrikeRate()) ? "&#8211;" : $this->player->BattingStrikeRate())));
         echo $batting_table;
         if ($this->player->TotalBattingInnings()) {
             echo '<p class="statsViewAll"><a href="/play/statistics/individual-scores' . $querystring . '">Individual scores &#8211; view all and filter</a></p>';
         }
         ?>
         <span class="chart-js-template" id="score-spread-chart"></span>
         <span class="chart-js-template" id="batting-form-chart"></span>
         <span class="chart-js-template" id="dismissals-chart"></span>
         <?php 
     }
     $this->ShowSocial();
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         ?>
         </div>
         </div>
         <?php 
     }
     # End container for structured data
     echo "</div>";
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         $has_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS, $this->player->Team()->GetLinkedDataUri());
         $has_admin_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_PLAYERS);
         if ($has_permission) {
             $this->AddSeparator();
             $panel = new UserEditPanel($this->GetSettings());
             $panel->AddLink("rename this player", $this->player->GetEditUrl());
             if ($has_admin_permission) {
                 $panel->AddLink("delete this player", $this->player->GetDeleteUrl());
             }
             echo $panel;
         }
     }
 }
コード例 #7
0
 public function OnPageLoad()
 {
     if ($this->not_found) {
         require_once $_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/stoolball/section-404.php";
         return;
     }
     if ($this->regenerating) {
         echo $this->regenerating_control;
         return;
     }
     # Container element for structured data
     echo '<div typeof="schema:Person" about="' . htmlentities($this->player->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false) . '">';
     $querystring = '?player=' . $this->player->GetId();
     if ($_SERVER["QUERY_STRING"]) {
         $querystring = htmlspecialchars('?' . $_SERVER["QUERY_STRING"]);
     }
     require_once "stoolball/statistics/player-summary-control.class.php";
     echo new \Stoolball\Statistics\PlayerSummaryControl($this->player, $this->filter, $this->filter_matched_nothing, $querystring);
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         require_once 'xhtml/navigation/tabs.class.php';
         $tabs = array('Batting' => $this->player->GetPlayerUrl(), 'Bowling and fielding' => '');
         echo new Tabs($tabs);
         ?>
         <div class="box tab-box">
             <div class="dataFilter"></div>
             <div class="box-content">
         <?php 
     }
     # Filter control
     echo $this->filter_control;
     if ($this->player->Bowling()->GetCount()) {
         //			echo "<h2>Bowling</h2>";
         # Overview table
         $bowling_table = new XhtmlTable();
         $bowling_table->SetCssClass("numeric");
         $bowling_table->SetCaption("Bowling");
         $bowling_heading_row = new XhtmlRow(array('<abbr title="Innings" class="small">Inn</abbr><span class="large">Innings</span>', '<abbr title="Overs" class="small">Ov</abbr><span class="large">Overs</span>', '<abbr title="Maiden overs" class="small">Md</abbr><abbr title="Maiden overs" class="large">Mdns</abbr>', "Runs", '<abbr title="Wickets" class="small">Wk</abbr><abbr title="Wickets" class="large">Wkts</abbr>', "Best", '<abbr title="Economy" class="small">Econ</abbr><span class="large">Economy</span>', '<abbr title="Average" class="small">Avg</abbr><span class="large">Average</span>', '<abbr title="Strike rate" class="small">S/R</abbr><span class="large">Strike rate</span>', '<abbr title="5 wickets" class="small">5 wk</abbr><abbr title="5 wickets" class="large">5 wkts</abbr>'));
         $bowling_heading_row->SetIsHeader(true);
         $bowling_table->AddRow($bowling_heading_row);
         $bowling_table->AddRow(new XhtmlRow(array($this->player->BowlingInnings(), $this->player->Overs(), $this->player->MaidenOvers(), $this->player->RunsAgainst(), $this->player->WicketsTaken(), is_null($this->player->BestBowling()) ? "&#8211;" : $this->player->BestBowling(), is_null($this->player->BowlingEconomy()) ? "&#8211;" : $this->player->BowlingEconomy(), is_null($this->player->BowlingAverage()) ? "&#8211;" : $this->player->BowlingAverage(), is_null($this->player->BowlingStrikeRate()) ? "&#8211;" : $this->player->BowlingStrikeRate(), $this->player->FiveWicketHauls())));
         echo $bowling_table;
         echo '<p class="statsViewAll"><a href="/play/statistics/bowling-performances' . $querystring . '">Bowling performances &#8211; view all and filter</a></p>';
     }
     ?>
     <span class="chart-js-template" id="economy-chart"></span>
     <span class="chart-js-template" id="bowling-average-chart"></span>
     <span class="chart-js-template" id="wickets-chart"></span>
     <?php 
     # Fielding
     $catches = $this->player->GetCatches();
     $run_outs = $this->player->GetRunOuts();
     if ($catches or $run_outs) {
         $fielding_table = new XhtmlTable();
         $fielding_table->SetCssClass("numeric");
         $fielding_table->SetCaption("Fielding");
         $fielding_heading_row = new XhtmlRow(array('Catches', "Run-outs"));
         $fielding_heading_row->SetIsHeader(true);
         $fielding_table->AddRow($fielding_heading_row);
         $fielding_table->AddRow(new XhtmlRow(array($catches, $run_outs)));
         echo $fielding_table;
     }
     $this->ShowSocial();
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         ?>
         </div>
         </div>
         <?php 
     }
     # End container for structured data
     echo "</div>";
     if ($this->player->GetPlayerRole() == Player::PLAYER) {
         $has_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_TEAMS, $this->player->Team()->GetLinkedDataUri());
         $has_admin_permission = AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_PLAYERS);
         if ($has_permission) {
             $this->AddSeparator();
             $panel = new UserEditPanel($this->GetSettings());
             $panel->AddLink("rename this player", $this->player->GetEditUrl());
             if ($has_admin_permission) {
                 $panel->AddLink("delete this player", $this->player->GetDeleteUrl());
             }
             echo $panel;
         }
     }
 }