Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/matchups.php
<?php
/**
 * Team-to-team matchups by position
 *
 * Not well-tested with new format, but should be OK.
 *
 * @author Stephen Rochelle <hide@address.com>
 * @version OFFL v0.2
 * @copyright Copyright (c) 2004 Stephen Rochelle.  Some rights reserved.
 * @package offl-ui
 */

$pageTitle = "Game Matchup";
require_once("offlconfig.php");
require_once($DOC_ROOT . "/lib/header.php"); 

if (isset($_GET["game_id"]))
{
	$game = new OFFL_Game($_GET["game_id"]);
	$year = $game->getYear();
	$week = $game->getWeek();
	$hTeam = new OFFL_FFLTeam($game->getHFFLTeamID());
	$vTeam = new OFFL_FFLTeam($game->getVFFLTeamID());

	$stats_lookup = new OFFL_PlayerStat();
	$game_lookup = new OFFL_NFLGame();

	$curr_year = getThisYear();
	$curr_week = getCurrentWeek($curr_year);

	$current = 0;
	if (($curr_week <= $week) && ($curr_year == $year))
		$current = 1; 
	if ($curr_year > $year)
		$current = 1; // future, use current rosters

	$hRoster = array();
	$hTeamRoster = array();
	$vRoster = array();
	$vTeamRoster = array();
	if ($current)
	{
		$hRosterPlayers = $hTeam->getRoster(TRUE); // get starters
		$vRosterPlayers = $vTeam->getRoster(TRUE);
		foreach ($hRosterPlayers as $player)
		{
			$hRoster[] = $player->getPlayerID();
			$hTeamRoster[] = $player->getNFLTeamID();
		}
		foreach ($vRosterPlayers as $player)
		{
			$vRoster[] = $player->getPlayerID();
			$vTeamRoster[] = $player->getNFLTeamID();
		}
	}
	else
	{
		$hPastRoster = new OFFL_PastRoster($year, $week, $game->getHFFLTeamID());
		$hStarter = $hPastRoster->getStarterArray();
		$hRosterTemp = $hPastRoster->getPlayerIDArray();
		$hTeamRosterTemp = $hPastRoster->getNFLTeamIDArray();
		foreach($hRosterTemp as $i=>$player_id)
		{
			if ($hStarter[$i])
			{	
				$hRoster[] = $player_id;
				$hTeamRoster[] = $hTeamRosterTemp[$i];
			}
		}
		$vPastRoster = new OFFL_PastRoster($year, $week, $game->getVFFLTeamID());
		$vStarter = $vPastRoster->getStarterArray();
		$vRosterTemp = $vPastRoster->getPlayerIDArray();
		$vTeamRosterTemp = $vPastRoster->getNFLTeamIDArray();
		foreach($vRosterTemp as $i=>$player_id)
		{
			if ($vStarter[$i])
			{	
				$vRoster[] = $player_id;
				$vTeamRoster[] = $vTeamRosterTemp[$i];
			}
		}

	}
?>
<h2 style="font-size: 11pt; margin-left: 6%;"><a href="<?php echo $WEB_ROOT; ?>/games.php?year=<?php echo $year; ?>&week=<?php echo $week; ?>"><?php echo $year; ?> Week <?php echo $week; ?></a></h2>
<table class="matchup">
	<tr>
		<th class="top" style="width:48%;" colspan="4"><a href="<?php echo $WEB_ROOT . "/teams.php?fflteam_id=" . $game->getVFFLTeamID(); ?>"><?php echo $vTeam->getFFLTeamFullName(); ?></a></th>
		<th class="top" >at</th>
		<th class="top"  style="width:48%;" colspan="4"><a href="<?php echo $WEB_ROOT . "/teams.php?fflteam_id=" . $game->getHFFLTeamID(); ?>"><?php echo $hTeam->getFFLTeamFullName(); ?></a></th>
	</tr>
	<tr>
		<th style="width:10px;"><abbr title="Position">Pos</abbr></th>
		<th>Player</th>
		<th>Team</th>
		<th style="width:10px;">Score</th>
		<th rowspan="302"><!-- enough to accomodate any size table --></th>
		<th style="width:10px;"><abbr title="Position">Pos</abbr></th>
		<th>Player</th>
		<th>Team</th>
		<th style="width:10px;">Score</th>
	</tr>
<?php

	$player_count = max(sizeof($hRoster), sizeof($vRoster));
	for ($i = 0; $i < $player_count; $i++)
	{
		echo "  <tr class=\"";
		if ($i % 2)
		{	echo "evenrow";	 }
		else
		{	echo "oddrow";	}
		echo "\">\n";

		if (array_key_exists($i, $vRoster))
		{
			$player = new OFFL_Player($vRoster[$i]);
			$stats = $stats_lookup->getStatsByPlayerIDYearWeek($player->getPlayerID(), $year, $week);
			if ($stats !== FALSE)
			{	$stats->setLeagueID($_SESSION["league_id"]);	}

			echo "		<td style=\"text-align:center;\"><abbr title=\"" . $player->getPositionName() . "\">" . $player->getPositionAbbv() . "</abbr></td>\n";
			echo "		<td class=\"pname\"><a href=\"$WEB_ROOT/players.php?player_id=" . $player->getPlayerID() . "\">" . $player->getName() . "</a></td>\n";

			$nflTeam = new OFFL_NFLTeam($vTeamRoster[$i]);
			$nflGame = $game_lookup->getNFLTeamGame($year, $week, $nflTeam->getNFLTeamID());
			if ($nflGame === FALSE) // bye week
			{
				echo "		<td><abbr title=\"" . $player->getNFLTeamCity() . " " . $player->getNFLTeamName() . "\">" . $player->getNFLTeamAbbv() . "</abbr>: Bye</td>\n";
			}
			else
			{
				$nflOpp = $nflGame->getNFLTeamGameOpponent($year, $week, $nflTeam->getNFLTeamID());
				if (strstr($nflOpp, "@") === FALSE)
				{
					echo "		<td><abbr title=\"" . $nflTeam->getNFLTeamCity() . " " . $nflTeam->getNFLTeamName() . "\">" . $nflTeam->getNFLTeamAbbv() . "</abbr> v " . strtolower($nflOpp) . "</td>\n";
				}
				else
				{
					echo "		<td><abbr title=\"" . $nflTeam->getNFLTeamCity() . " " . $nflTeam->getNFLTeamName() . "\">" . strtolower($nflTeam->getNFLTeamAbbv()) . "</abbr> @ " . strtoupper(substr($nflOpp,1)) . "</td>\n";
				}
			}

			if ($stats === FALSE)
				echo "		<td style=\"text-align:center;\">---</td>\n";
			else
				echo "		<td style=\"text-align:center;\">" . $stats->calculatePoints() . "</td>\n";

		}
		else
		{
			echo "		<td colspan=\"4\"></td>\n";
		}


		if (array_key_exists($i, $hRoster))
		{
			$player = new OFFL_Player($hRoster[$i]);
			$stats = $stats_lookup->getStatsByPlayerIDYearWeek($player->getPlayerID(), $year, $week);
			if ($stats !== FALSE)
			{	$stats->setLeagueID($_SESSION["league_id"]);	}

			echo "		<td><abbr title=\"" . $player->getPositionName() . "\">" . $player->getPositionAbbv() . "</abbr></td>\n";
			echo "		<td class=\"pname\"><a href=\"$WEB_ROOT/players.php?player_id=" . $player->getPlayerID() . "\">" . $player->getName() . "</a></td>\n";

			$nflTeam = new OFFL_NFLTeam($hTeamRoster[$i]);
			$nflGame = $game_lookup->getNFLTeamGame($year, $week, $nflTeam->getNFLTeamID());
			if ($nflGame === FALSE) // bye week
			{
				echo "		<td><abbr title=\"" . $player->getNFLTeamCity() . " " . $player->getNFLTeamName() . "\">" . $player->getNFLTeamAbbv() . "</abbr>: Bye</td>\n";
			}
			else
			{
				$nflOpp = $nflGame->getNFLTeamGameOpponent($year, $week, $nflTeam->getNFLTeamID());
				if (strstr($nflOpp, "@") === FALSE)
				{
					echo "		<td><abbr title=\"" . $nflTeam->getNFLTeamCity() . " " . $nflTeam->getNFLTeamName() . "\">" . $nflTeam->getNFLTeamAbbv() . "</abbr> v " . strtolower($nflOpp) . "</td>\n";
				}
				else
				{
					echo "		<td><abbr title=\"" . $nflTeam->getNFLTeamCity() . " " . $nflTeam->getNFLTeamName() . "\">" . strtolower($nflTeam->getNFLTeamAbbv()) . "</abbr> @ " . strtoupper(substr($nflOpp,1)) . "</td>\n";
				}
			}

			if ($stats === FALSE)
				echo "		<td>---</td>\n";
			else
				echo "		<td>" . $stats->calculatePoints() . "</td>\n";

		}
		else
		{
			echo "		<td colspan=\"4\"></td>\n";
		}
		echo "	</tr>\n";
	}

?>
	<tr><th colspan="9" style="height:3px;"></th></tr>
	<tr><td colspan="3"></td><td><?php echo $game->getVFFLTeamScore(); ?></td>
		<td colspan="3"></td><td><?php echo $game->getHFFLTeamScore(); ?></td></tr>
<!-- </table> -->
<?php /* NOW DO THE BENCHES FOR REFERENCE */

	if ($current)
	{ // pull current benches
		$hRosterPlayers = $hTeam->getRoster(); // get starters
		$vRosterPlayers = $vTeam->getRoster();
		foreach ($hRosterPlayers as $player)
		{
			if (!$player->getStarter())
			{
				$hBnRoster[] = $player->getPlayerID();
				$hBnTeamRoster[] = $player->getNFLTeamID();
			}
		}
		foreach ($vRosterPlayers as $player)
		{
			if (!$player->getStarter())
			{
				$vBnRoster[] = $player->getPlayerID();
				$vBnTeamRoster[] = $player->getNFLTeamID();
			}
		}
	}
	else
	{
		$hPastRoster = new OFFL_PastRoster($year, $week, $game->getHFFLTeamID());
		$hStarter = $hPastRoster->getStarterArray();
		$hRosterTemp = $hPastRoster->getPlayerIDArray();
		$hTeamRosterTemp = $hPastRoster->getNFLTeamIDArray();
		foreach($hRosterTemp as $i=>$player_id)
		{
			if (!$hStarter[$i])
			{	
				$hBnRoster[] = $player_id;
				$hBnTeamRoster[] = $hTeamRosterTemp[$i];
			}
		}
		$vPastRoster = new OFFL_PastRoster($year, $week, $game->getVFFLTeamID());
		$vStarter = $vPastRoster->getStarterArray();
		$vRosterTemp = $vPastRoster->getPlayerIDArray();
		$vTeamRosterTemp = $vPastRoster->getNFLTeamIDArray();
		foreach($vRosterTemp as $i=>$player_id)
		{
			if (!$vStarter[$i])
			{	
				$vBnRoster[] = $player_id;
				$vBnTeamRoster[] = $vTeamRosterTemp[$i];
			}
		}
	}
?>
<!-- <table class="matchup"> -->
	<tr>
		<th class="top" style="width:48%;" colspan="9">Benches</th>
	</tr>
	<tr>
		<th style="width:10px;"><abbr title="Position">Pos</abbr></th>
		<th>Player</th>
		<th>Team</th>
		<th style="width:10px;">Score</th>
<!--		<th rowspan="302"></th> -->
		<th style="width:10px;"><abbr title="Position">Pos</abbr></th>
		<th>Player</th>
		<th>Team</th>
		<th style="width:10px;">Score</th>
	</tr>
<?php

	$player_count = max(sizeof($hBnRoster), sizeof($vBnRoster));
	for ($i = 0; $i < $player_count; $i++)
	{
		echo "  <tr class=\"";
		if ($i % 2)
		{	echo "evenrow";	 }
		else
		{	echo "oddrow";	}
		echo "\">\n";

		if (is_array($vBnRoster) && array_key_exists($i, $vBnRoster))
		{
			$player = new OFFL_Player($vBnRoster[$i]);
			$stats = $stats_lookup->getStatsByPlayerIDYearWeek($player->getPlayerID(), $year, $week);
			if ($stats !== FALSE)
			{	$stats->setLeagueID($_SESSION["league_id"]);	}

			echo "		<td style=\"text-align:center;\"><abbr title=\"" . $player->getPositionName() . "\">" . $player->getPositionAbbv() . "</abbr></td>\n";
			echo "		<td class=\"pname\"><a href=\"$WEB_ROOT/players.php?player_id=" . $player->getPlayerID() . "\">" . $player->getName() . "</a></td>\n";

			$nflTeam = new OFFL_NFLTeam($vBnTeamRoster[$i]);
			$nflGame = $game_lookup->getNFLTeamGame($year, $week, $nflTeam->getNFLTeamID());
			if ($nflGame === FALSE) // bye week
			{
				echo "		<td><abbr title=\"" . $player->getNFLTeamCity() . " " . $player->getNFLTeamName() . "\">" . $player->getNFLTeamAbbv() . "</abbr>: Bye</td>\n";
			}
			else
			{
				$nflOpp = $nflGame->getNFLTeamGameOpponent($year, $week, $nflTeam->getNFLTeamID());
				if (strstr($nflOpp, "@") === FALSE)
				{
					echo "		<td><abbr title=\"" . $nflTeam->getNFLTeamCity() . " " . $nflTeam->getNFLTeamName() . "\">" . $nflTeam->getNFLTeamAbbv() . "</abbr> v " . strtolower($nflOpp) . "</td>\n";
				}
				else
				{
					echo "		<td><abbr title=\"" . $nflTeam->getNFLTeamCity() . " " . $nflTeam->getNFLTeamName() . "\">" . strtolower($nflTeam->getNFLTeamAbbv()) . "</abbr> @ " . strtoupper(substr($nflOpp,1)) . "</td>\n";
				}
			}

			if ($stats === FALSE)
				echo "		<td style=\"text-align:center;\">---</td>\n";
			else
				echo "		<td style=\"text-align:center;\">" . $stats->calculatePoints() . "</td>\n";

		}
		else
		{
			echo "		<td colspan=\"4\"></td>\n";
		}


		if (is_array($hBnRoster) && array_key_exists($i, $hBnRoster))
		{
			$player = new OFFL_Player($hBnRoster[$i]);
			$stats = $stats_lookup->getStatsByPlayerIDYearWeek($player->getPlayerID(), $year, $week);
			if ($stats !== FALSE)
			{	$stats->setLeagueID($_SESSION["league_id"]);	}

			echo "		<td><abbr title=\"" . $player->getPositionName() . "\">" . $player->getPositionAbbv() . "</abbr></td>\n";
			echo "		<td class=\"pname\"><a href=\"$WEB_ROOT/players.php?player_id=" . $player->getPlayerID() . "\">" . $player->getName() . "</a></td>\n";

			$nflTeam = new OFFL_NFLTeam($hBnTeamRoster[$i]);
			$nflGame = $game_lookup->getNFLTeamGame($year, $week, $nflTeam->getNFLTeamID());
			if ($nflGame === FALSE) // bye week
			{
				echo "		<td><abbr title=\"" . $player->getNFLTeamCity() . " " . $player->getNFLTeamName() . "\">" . $player->getNFLTeamAbbv() . "</abbr>: Bye</td>\n";
			}
			else
			{
				$nflOpp = $nflGame->getNFLTeamGameOpponent($year, $week, $nflTeam->getNFLTeamID());
				if (strstr($nflOpp, "@") === FALSE)
				{
					echo "		<td><abbr title=\"" . $nflTeam->getNFLTeamCity() . " " . $nflTeam->getNFLTeamName() . "\">" . $nflTeam->getNFLTeamAbbv() . "</abbr> v " . strtolower($nflOpp) . "</td>\n";
				}
				else
				{
					echo "		<td><abbr title=\"" . $nflTeam->getNFLTeamCity() . " " . $nflTeam->getNFLTeamName() . "\">" . strtolower($nflTeam->getNFLTeamAbbv()) . "</abbr> @ " . strtoupper(substr($nflOpp,1)) . "</td>\n";
				}
			}

			if ($stats === FALSE)
				echo "		<td>---</td>\n";
			else
				echo "		<td>" . $stats->calculatePoints() . "</td>\n";

		}
		else
		{
			echo "		<td colspan=\"4\"></td>\n";
		}
		echo "	</tr>\n";
	}

?>
<!--	<tr><th colspan="9" style="height:3px;"></th></tr>
	<tr><td colspan="3"></td><td><?php echo $game->getVFFLTeamScore(); ?></td>
		<td colspan="3"></td><td><?php echo $game->getHFFLTeamScore(); ?></td></tr>
-->
</table>

<?php



} // end if isset game_id
else
{
	echo "<h2 class=\"error\">No game specified.</h2>\n";
}

require($DOC_ROOT . "/lib/footer.php"); ?>
Return current item: Online Fantasy Football League