Improvements (debateable) to Teamplayer templates have made this project obsolete (debatable). We wont be updating it.
The index page has been redirected to the [Teamplayer page](http://teamplayer.statesman.com/web/home.php?site=default&tpl=new_schedule&SearchType=Schedules&mkt=&mode=2&tab=tab1&Sport=1#tab1.
This project uses Node.js for package management. Once you clone, you'll need to update:
npm install
to install packagesbower install
to installs client-side packagesgrunt build
will build the current files for publishinggrunt stage
will ftpush to the staging sitegrunt prod
will ftpush to production Configured to use grunt-ftpush task, which pushes all items in the public
folder.
assets
folderdist
folderfonts
folderindex.php
list.php
All configuration settings are stored in src/js/config.js
.
Setting up the regular season is as simple as setting the two variables at the top of that file, one for the number of weeks in the regular season and another for the first Friday of the regular season, which is what all of the other weeks will be calculated from.
You'll also need to include the base URL for your teamplayer gateway and the sport ID for football.
var numWeeks = 11;
var firstFriday = moment('2014-08-29', 'YYYY-MM-DD');
var urlBase = 'http://teamplayer.statesman.com';
var sportId = '1';
When you want to add a playoff week, go into src/js/config.js
and add them where it says to:
weeks.push({
title: 'Playoffs: Week 1',
date: '2015-11-12'
});
This app relies on two TeamPlayer templates, one Web template, and one query template. Both are included below so changes to Teamplayer templates can be tracked along with changes to the app's code.
The production version of the app draws from the Web template TickerJSON
and the dev version from TickerJSON_clone
. Production queries are generated by Ticker
and dev come from TickerClone
.
TickerJSON
<QUERY name=Sport SPORTID=$form_Sport>
<VAR $market = "">
<IFGREATER $form_Market 0>
<VAR $market = $form_Market>
</IFGREATER>
<?php
$scoreFields = array(
"Football" => "TotalPoints",
"Baseball" => "Runs",
"Boys Basketball" => "TotalPoints",
"Girls Basketball" => "TotalPoints",
"Boys Hockey" => "TotalGoals",
"Girls Hockey" => "TotalGoals",
"Boys Soccer" => "TotalGoals",
"Girls Soccer" => "TotalGoals",
"Boys Volleyball" => "FinalScore",
"Girls Volleyball" => "FinalScore",
"Field Hockey" => "TotalGoals",
"Softball" => "Runs",
"Boys Lacrosse" => "TotalGoals",
"Girls Lacrosse" => "TotalGoals"
);
?>
<VAR $sportName = $Sport_SportName>
<VAR $sqlSportName = strtolower(convertForSQL($sportName))>
<VAR $scoreField = $scoreFields[$sportName]>
<QUERY name=Ticker SPORTID=$form_Sport SPORTNAME=$sqlSportName SCOREFIELD=$scoreField STARTDATE=$form_StartDate ENDDATE=$form_EndDate MARKET=$market>
<?php header('Content-Type: application/json'); ?>
<?php
// Loop through each of the data rows and set some custom fields
foreach($Ticker_rows as $key => $row) {
// Make GameScoreIsFinal a boolean for easier templating
if($row['GameScoreIsFinal'] === "1") {
$Ticker_rows[$key]['GameScoreIsFinal'] = TRUE;
}
else {
$Ticker_rows[$key]['GameScoreIsFinal'] = FALSE;
}
// Set a boolean for the winner that can be used during templating
if($Ticker_rows[$key]['GameScoreIsFinal']) {
if(intval($row['AwayTeamScore']) > intval($row['HomeTeamScore'])) {
$Ticker_rows[$key]['AwayTeamWon'] = TRUE;
}
else {
$Ticker_rows[$key]['HomeTeamWon'] = TRUE;
}
}
// Set the boolean for game stats to true if they're marked complete
if($row['GameStatStatus'] === "3") {
$Ticker_rows[$key]['GameStatStatus'] = TRUE;
}
// Return the gametime as a UNIX timestamp for easier client-side parsing
$timeStamp = strtotime($row['GameTime'] . ' ' . $row['GameDate']) + 3600;
$Ticker_rows[$key]['GameTimestamp'] = $timeStamp;
unset($Ticker_rows[$key]['GameTime']);
unset($Ticker_rows[$key]['GameDate']);
if($row['AwayTotalYards'] == "0" && $row['HomeTotalYards'] == "0") {
$Ticker_rows[$key]['GameStats'] = false;
}
elseif($row['AwayTotalYards'] == null && $row['HomeTotalYards'] == null) {
$Ticker_rows[$key]['GameStats'] = false;
}
else {
$Ticker_rows[$key]['GameStats'] = true;
}
}
$json = json_encode($Ticker_rows);
if(array_key_exists('callback', $_GET)){
$callback = $_GET['callback'];
$json = $callback . '(' . $json . ');';
}
echo $json;
?>
GameJSON
<QUERY name=Sport SPORTID=$form_Sport>
<?php
$scoreFields = array(
"Football" => "TotalPoints",
"Baseball" => "Runs",
"Boys Basketball" => "TotalPoints",
"Girls Basketball" => "TotalPoints",
"Boys Hockey" => "TotalGoals",
"Girls Hockey" => "TotalGoals",
"Boys Soccer" => "TotalGoals",
"Girls Soccer" => "TotalGoals",
"Boys Volleyball" => "FinalScore",
"Girls Volleyball" => "FinalScore",
"Field Hockey" => "TotalGoals",
"Softball" => "Runs",
"Boys Lacrosse" => "TotalGoals",
"Girls Lacrosse" => "TotalGoals"
);
?>
<VAR $sportName = $Sport_SportName>
<VAR $sqlSportName = strtolower(convertForSQL($sportName))>
<VAR $scoreField = $scoreFields[$sportName]>
<QUERY name=GameJSON GAMEID=$form_id SPORTNAME=$sqlSportName SCOREFIELD=$scoreField>
<?php /* Get team records via some existing TeamPlayer queries */ ?>
<VAR $statType = "overall">
<QUERY name=TeamSeasonStats ID=$GameJSON_rows[0]["HomeTeamID"] SPORTNAME=$sqlSportName CATEGORY=$statType SEASON=$form_Season>
<?php $GameJSON_rows[0]['HomeOverallWins'] = $TeamSeasonStats_Win; ?>
<?php $GameJSON_rows[0]['HomeOverallLosses'] = $TeamSeasonStats_Loss; ?>
<VAR $statType = "overall">
<VAR $TeamSeasonStats_query = "">
<QUERY name=TeamSeasonStats ID=$GameJSON_rows[0]["AwayTeamID"] SPORTNAME=$sqlSportName CATEGORY=$statType SEASON=$form_Season>
<?php $GameJSON_rows[0]['AwayOverallWins'] = $TeamSeasonStats_Win; ?>
<?php $GameJSON_rows[0]['AwayOverallLosses'] = $TeamSeasonStats_Loss; ?>
<?php /* Get each team's history by team IDs */ ?>
<VAR $awayTeamID = $GameJSON_rows[0]['AwayTeamID']>
<VAR $homeTeamID = $GameJSON_rows[0]['HomeTeamID']>
<QUERY name=HistoryJSON AWAYID=$awayTeamID HOMEID=$homeTeamID>
<?php /* Run each game through the below queries to get scores */ ?>
<?php $historyList = array(); ?>
<?php foreach($HistoryJSON_rows as $history): ?>
<VAR $archiveTag = "z_">
<VAR $gameId = $history["GameID"]>
<VAR $season = $history["GameSeason"]>
<QUERY name=Game ID=$gameId ARCHIVETAG=$archiveTag SEASON=$season>
<VAR $sportName = $Game_SportName>
<VAR $sportType = $Game_SportType>
<VAR $sqlSportName = strtolower(convertForSQL($sportName))>
<VAR $awayTeamID = $Game_GameAwayTeamID>
<VAR $homeTeamID = $Game_GameHomeTeamID>
<QUERY name=GameTeamStats GAMEID=$gameId SPORTNAME=$sqlSportName TEAMID=$awayTeamID prefix=Away ARCHIVETAG=$archiveTag SEASON=$season>
<QUERY name=GameTeamStats GAMEID=$gameId SPORTNAME=$sqlSportName TEAMID=$homeTeamID prefix=Home ARCHIVETAG=$archiveTag SEASON=$season>
<?php /* Generate an array with all of the results */ ?>
<?php $historyList[$history["GameSeason"]] = array(
'HomeTeamName' => $Home_TeamName,
'HomePoints' => $Home_TotalPoints,
'AwayTeamName' => $Away_TeamName,
'AwayPoints' => $Away_TotalPoints,
'GameDate' => $history["GameDate"]
);?>
<?php endforeach; ?>
<?php krsort($historyList); ?>
<?php $GameJSON_rows[0]['history'] = $historyList; ?>
<?php /* Convert some values to boolean for easier templating */ ?>
<?php if($GameJSON_rows[0]['GameScoreIsFinal'] == "1") {
$GameJSON_rows[0]['GameScoreIsFinal'] = true;
}
else {
$GameJSON_rows[0]['GameScoreIsFinal'] = false;
} ?>
if($GameJSON_rows[0]['AwayTotalYards'] == "0" && $GameJSON_rows[0]['HomeTotalYards'] == "0") {
$GameJSON_rows[0]['GameStats'] = false;
}
elseif($GameJSON_rows[0]['AwayTotalYards'] == null && $GameJSON_rows[0]['HomeTotalYards'] == null) {
$GameJSON_rows[0]['GameStats'] = false;
}
else {
$GameJSON_rows[0]['GameStats'] = true;
} ?>
<?php /* Send a JSON response, with a JSONP wrapper if necessary */ ?>
<?php header('Content-Type: application/json'); ?>
<?php
$json = json_encode($GameJSON_rows[0]);
if(array_key_exists('callback', $_GET)){
$callback = $_GET['callback'];
$json = $callback . '(' . $json . ');';
}
echo $json;
?>
Ticker
SELECT q_game.GameID,
GameAwayTeamID,
GameHomeTeamID,
GameDate,
GameTime,
GameScoreIsFinal,
GameLocation,
GameStatStatus,
away.TeamName AS AwayTeamName,
home.TeamName AS HomeTeamName,
away.TeamNickname AS AwayTeamNickname,
home.TeamNickname AS HomeTeamNickname,
awayscore.{$SCOREFIELD} AS AwayTeamScore,
homescore.{$SCOREFIELD} AS HomeTeamScore,
awayscore.TotalYards AS AwayTotalYards,
homescore.TotalYards AS HomeTotalYards,
away.TeamID AS AwayTeamID,
home.TeamID AS HomeTeamID,
venue.SchoolName AS VenueName
FROM `q_game`
LEFT JOIN game ON q_game.GameID = game.GameID
LEFT JOIN team AS away ON away.TeamID = GameAwayTeamID
LEFT JOIN team AS home ON home.TeamID = GameHomeTeamID
LEFT JOIN school AS venue ON game.GameLocation = venue.SchoolID
LEFT JOIN gameteam{$SPORTNAME} as awayscore ON awayscore.GameTeamTeamID = GameAwayTeamID AND awayscore.GameTeamGameID = q_game.GameID
LEFT JOIN gameteam{$SPORTNAME} as homescore ON homescore.GameTeamTeamID = GameHomeTeamID AND homescore.GameTeamGameID = q_game.GameID WHERE GameActive = 1 AND GameSportID = {$SPORTID} AND GameDate >= '{$STARTDATE}' AND GameDate <= '{$ENDDATE}'
GameJSON
SELECT q_game.GameID,
GameAwayTeamID,
GameHomeTeamID,
GameDate,
GameTime,
GameScoreIsFinal,
GameLocation,
away.TeamName AS AwayTeamName,
home.TeamName AS HomeTeamName,
away.TeamNickname AS AwayTeamNickname,
home.TeamNickname AS HomeTeamNickname,
awayscore.{$SCOREFIELD} AS AwayTeamScore,
homescore.{$SCOREFIELD} AS HomeTeamScore,
away.TeamID AS AwayTeamID,
home.TeamID AS HomeTeamID,
venue.SchoolName AS VenueName,
awayscore.TotalYards AS AwayTotalYards,
homescore.TotalYards AS HomeTotalYards,
awayscore.FirstDowns AS AwayFirstDowns,
homescore.FirstDowns AS HomeFirstDowns,
awayscore.PassCompletions AS AwayPassCompletions,
homescore.PassCompletions AS HomePassCompletions,
awayscore.PassAttempts AS AwayPassAttempts,
homescore.PassAttempts AS HomePassAttempts,
awayscore.PassCompletionPercentage AS AwayPassCompletionPercentage,
homescore.PassCompletionPercentage AS HomePassCompletionPercentage,
awayscore.PassingYards AS AwayPassingYards,
homescore.PassingYards AS HomePassingYards,
awayscore.PassingInterceptions AS AwayPassingInterceptions,
homescore.PassingInterceptions AS HomePassingInterceptions,
awayscore.RushingAttempts AS AwayRushingAttempts,
homescore.RushingAttempts AS HomeRushingAttempts,
awayscore.RushingYards AS AwayRushingYards,
homescore.RushingYards AS HomeRushingYards,
awayscore.RushingYardsPerAttempt AS AwayRushingYardsPerAttempt,
homescore.RushingYardsPerAttempt AS HomeRushingYardsPerAttempt,
awayscore.FirstQuarterPoints AS AwayFirstQuarterPoints,
homescore.FirstQuarterPoints AS HomeFirstQuarterPoints,
awayscore.SecondQuarterPoints AS AwaySecondQuarterPoints,
homescore.SecondQuarterPoints AS HomeSecondQuarterPoints,
awayscore.ThirdQuarterPoints AS AwayThirdQuarterPoints,
homescore.ThirdQuarterPoints AS HomeThirdQuarterPoints,
awayscore.FourthQuarterPoints AS AwayFourthQuarterPoints,
homescore.FourthQuarterPoints AS HomeFourthQuarterPoints,
awayscore.OvertimePoints AS AwayOvertimePoints,
homescore.OvertimePoints AS HomeOvertimePoints,
awayscore.YardsPerCatch AS AwayYardsPerCatch,
homescore.YardsPerCatch AS HomeYardsPerCatch,
homescore.Punts AS HomePunts,
awayscore.Punts AS AwayPunts,
awayscore.PuntingYards AS AwayPuntingYards,
homescore.PuntingYards AS HomePuntingYards,
awayscore.PuntingAverage AS AwayPuntingAverage,
homescore.PuntingAverage AS HomePuntingAverage,
awayscore.Fumbles AS AwayFumbles,
homescore.Fumbles AS HomeFumbles,
awayscore.FumblesLost AS AwayFumblesLost,
homescore.Fumbles AS HomeFumblesLost,
awayscore.Penalties AS AwayPenalties,
homescore.Penalties AS HomePenalties,
awayscore.PenaltyYards AS AwayPenaltyYards,
homescore.PenaltyYards AS HomePenaltyYards,
game.GameStatsFinal AS GameStatsFinal
FROM `q_game`
LEFT JOIN game ON q_game.GameID = game.GameID
LEFT JOIN team AS away ON away.TeamID = GameAwayTeamID
LEFT JOIN team AS home ON home.TeamID = GameHomeTeamID
LEFT JOIN school AS venue ON game.GameLocation = venue.SchoolID
LEFT JOIN gameteam{$SPORTNAME} as awayscore ON awayscore.GameTeamTeamID = GameAwayTeamID AND awayscore.GameTeamGameID = q_game.GameID
LEFT JOIN gameteam{$SPORTNAME} as homescore ON homescore.GameTeamTeamID = GameHomeTeamID AND homescore.GameTeamGameID = q_game.GameID
WHERE q_game.GameID = {$GAMEID}
HistoryJSON
SELECT GameID, GameSeason, GameDate FROM `z_game`
WHERE (GameAwayTeamID={$AWAYID} AND GameHomeTeamID={$HOMEID}) OR (GameAwayTeamID={$HOMEID} AND GameHomeTeamID={$AWAYID})