Exemplo n.º 1
0
    public static function showTables()
    {
        global $lng, $tours;
        title($lng->getTrn('name', 'LeagueTables'));
        // Selector for the tournament
        $tour_id = 0;
        if (isset($_POST['tour_id'])) {
            $tour_id = $_POST['tour_id'];
        } else {
            if (isset($_GET['tour_id'])) {
                $tour_id = $_GET['tour_id'];
            }
        }
        $firstTour = 0;
        ?>
    <div class='boxWide'>
        <h3 class='boxTitle2'><?php 
        echo $lng->getTrn('tours', 'LeagueTables');
        ?>
</h3>
        <div class='boxBody'>
			<form method="POST">
				<select name="tour_id">
					<?php 
        $rTours = array_reverse($tours, true);
        foreach ($rTours as $trid => $desc) {
            if ($firstTour == 0) {
                $firstTour = $trid;
            }
            echo "<option value='{$trid}'" . ($trid == $tour_id ? 'SELECTED' : '') . " >{$desc['tname']}</option>\n";
        }
        /*Replace the prior foreach with this once lid is known.
          foreach ($rTours as $trif => $desc) {
            if($firstTour == 0 && $lid == $_SESSION["NS_node_id"]) {
              $firstTour = $trid;
            }
            if($lid == $_SESSION["NS_node_id"]) {
              echo "<option value='$trid'" . ($trid==$tour_id ? 'SELECTED' : '') . " >$desc[tname]</option>\n";
            }
          }
          */
        ?>
				</select>
				<input type="submit" value="OK">
			</form>
        </div>
    </div>
    <?php 
        if ($tour_id == 0) {
            $tour_id = $firstTour;
        }
        // create the tournament and get the sorting rules
        $tour = new Tour($tour_id);
        $SR = array_map(create_function('$val', 'return $val[0]."mv_".substr($val,1);'), $tour->getRSSortRule());
        // load all the teams according to the sorting rule
        list($teams, ) = Stats::getRaw(T_OBJ_TEAM, array(T_NODE_TOURNAMENT => $tour_id), array(1, 1000), $SR, false);
        // Dump all the raw info for the first team as debug so I can work out the fields
        /*
        echo "<!--\n";
        foreach (array_keys($teams[0]) as $field) {
        	echo $field. "=" . $teams[0][$field] . "\n";
        }
        echo "-->\n";
        */
        // Hard coded list of fields to show - matching existing SLOBB/ECBBL league tables
        $fields = array($lng->getTrn('table-coach', 'LeagueTables') => 'f_cname', $lng->getTrn('table-name', 'LeagueTables') => 'name', $lng->getTrn('table-race', 'LeagueTables') => 'f_rname', $lng->getTrn('table-tv', 'LeagueTables') => 'tv', $lng->getTrn('table-played', 'LeagueTables') => 'mv_played', $lng->getTrn('table-won', 'LeagueTables') => 'mv_won', $lng->getTrn('table-draw', 'LeagueTables') => 'mv_draw', $lng->getTrn('table-loss', 'LeagueTables') => 'mv_lost', $lng->getTrn('table-td', 'LeagueTables') => 'mv_sdiff', $lng->getTrn('table-cas', 'LeagueTables') => 'mv_tcdiff', $lng->getTrn('table-points', 'LeagueTables') => 'mv_pts');
        $unplayedTeams = self::getUnplayedTeamsForTournament($tour_id);
        $confs = 0;
        if (Module::isRegistered('Conference')) {
            $confs = Conference::getConferencesForTour($tour_id);
        }
        // Now the clean output.
        ?>
	<div class='boxWide'>
		<h3 class='boxTitle<?php 
        echo T_HTMLBOX_STATS;
        ?>
'><?php 
        echo $tour->name;
        ?>
</h3>
<?php 
        if ($confs == 0 || empty($confs)) {
            // no conferences at all, or not for this league - normal format
            echo <<<EOQ
\t\t<div class='boxBody'>
\t\t\t<table class="boxTable">
EOQ;
            $i = 0;
            self::showHeader($fields);
            self::showPlayedTeams($teams, $fields, $i);
            self::showUnplayedTeams($unplayedTeams, $i);
            echo <<<EOQ
\t\t\t</table>
\t\t</div>
EOQ;
        } else {
            // conferences - so show them one at a time
            $allConfIds = array();
            foreach ($confs as $conf) {
                $allConfIds = array_merge($allConfIds, $conf->teamIds);
                echo <<<EOQ
\t\t<div class='boxWide'>
\t\t\t<h4 class='boxTitleConf'>{$conf->name}</h4>
\t\t\t\t<table class="boxTable">
EOQ;
                $i = 0;
                self::showHeader($fields);
                self::showPlayedTeams($teams, $fields, $i, $conf->teamIds);
                self::showMissingConferenceTeams($teams, $i, $conf);
                echo <<<EOQ
\t\t\t\t</table>
\t\t</div>
EOQ;
            }
            // now check to see if we have teams that aren't in a conference and show them
            $allConfIds = array_unique($allConfIds);
            if (sizeof($allConfIds) < sizeof($teams) + sizeof($unplayedTeams)) {
                $title = $lng->getTrn('no-conf', 'LeagueTables');
                echo <<<EOQ
\t\t<div class='boxWide'>
\t\t\t<h4 class='boxTitleConf'>{$title}</h4>
\t\t\t<table class="boxTable">
EOQ;
                $noConfTeam = array();
                $noConfUPTeam = array();
                foreach ($teams as $t) {
                    if (!in_array($t['team_id'], $allConfIds)) {
                        array_push($noConfTeam, $t);
                    }
                }
                foreach ($unplayedTeams as $t) {
                    if (!in_array($t->team_id, $allConfIds)) {
                        array_push($noConfUPTeam, $t);
                    }
                }
                $i = 0;
                self::showHeader($fields);
                self::showPlayedTeams($noConfTeam, $fields, $i);
                self::showUnplayedTeams($noConfUPTeam, $i);
                echo <<<EOQ
\t\t\t</table>
\t\t</div>
EOQ;
            }
        }
        echo "</div>";
    }