Skip to content
Browse files

added rudimentary play tracking

  • Loading branch information...
1 parent a7b224e commit b8c8f6c888b1bd2533874cacd929780063a88416 @mikevalstar committed Jan 11, 2013
View
2 class/game.class.php
@@ -16,7 +16,7 @@ class game extends basedata{
var $_editwhencol = 'modified_when';
static function lookup_by_name($name){
- $sql = "SELECT `venue_pk` FROM `game` WHERE `game_name` = ? AND `deleted_when` IS NULL";
+ $sql = "SELECT `game_pk` FROM `game` WHERE `game_name` = ? AND `deleted_when` IS NULL";
$par = array($name);
$results = DBQ::prepare_execute($sql, $par);
if($row = $results->fetch()){
View
67 class/play.class.php
@@ -0,0 +1,67 @@
+<?PHP
+
+class play extends basedata{
+ var $_table = 'play';
+ var $_keycol = 'play_pk';
+ var $_cols = array('game_fk', 'playtime', 'started', 'ranked');
+
+ /* Messaging vars */
+ var $_msg_obj_replace = "Game Play";
+
+ var $_createbycol = 'created_by';
+ var $_createwhencol = 'created_when';
+ var $_delbycol = 'deleted_by';
+ var $_delwhencol = 'deleted_when';
+ var $_editbycol = 'modified_by';
+ var $_editwhencol = 'modified_when';
+
+ static function static_load($id){
+ return new play($id);
+ }
+
+ function save($dd = array()){
+ $ret = parent::save($dd);
+
+ $players = array();
+ foreach($dd['user_fk'] as $k => $v){
+ if($v != ''){
+ $players[] = array(
+ 'user_fk' => $v,
+ 'score' => $dd['score'][$k],
+ 'win' => $dd['win'][$k]
+ );
+ }
+ }
+
+ $this->add_players($players);
+
+ return $ret;
+ }
+
+ // parent game
+ function game(){
+ if($this->game_fk != ''){
+ $game = new game($this->game_fk);
+ return $game;
+ }
+ return false;
+ }
+
+ // Players
+ function playerslist(){
+ $sql = " SELECT * FROM `play_player`, `user` WHERE `user_fk` = `user_pk` AND `play_fk` = ? ";
+ $par = array($this->id);
+ $results = DBQ::prepare_execute($sql, $par);
+
+ return $results->fetchAll();
+ }
+
+ function add_players($p = array()){
+ foreach($p as $v){
+ $sql = "INSERT INTO `play_player` (`play_fk`, `user_fk`, `score`, `win`, `rank_change`) VALUES (?,?,?,?,?) ";
+ $par = array($this->id, $v['user_fk'], floatval($v['score']), $v['win'], 0);
+ $results = DBQ::prepare_execute($sql, $par);
+ }
+ }
+
+}
View
24 class/playlist.class.php
@@ -0,0 +1,24 @@
+<?PHP
+
+class playlist extends baselist{
+
+ var $_table = array('play', 'game');
+ var $_idcol = 'play_pk';
+ var $_filter_cols = array('game_name', 'owners_txt');
+ var $_display_cols = array('game_name', 'game_fk', 'play_pk', 'playtime', 'ranked', 'started');
+ var $_del_col = 'play`.`deleted_when';
+
+ /* settable properties / default values / Set as needed */
+ var $rows = 20;
+ var $orderby = 'started';
+ var $direction = 'desc';
+
+ function __construct($for_user = false){
+ $this->_ext_where[] = " AND `game_pk` = `game_fk` ";
+
+ if($for_user){
+ //$this->_ext_where[] = " AND `user_fk` = ".intval($for_user)." ";
+ }
+ }
+
+}
View
1 content/index.php
@@ -27,6 +27,7 @@
case 'events':
case 'users':
case 'massmail':
+ case 'plays':
if(!isset($_SESSION['user'])){
header('location: /login');
die();
View
35 docs/db.sql
@@ -95,11 +95,44 @@ CREATE TABLE `event_game_vote` (
UNIQUE KEY `game_fk` (`event_fk`,`user_fk`,`game_fk`)
);
-
ALTER TABLE `game` ADD `bgg_id` INT( 11 ) NOT NULL AFTER `parent_fk`;
ALTER TABLE `game` ADD `bgg_data` text NULL AFTER `bgg_id`;
ALTER TABLE `game` ADD `bgg_rating` DOUBLE( 6, 3 ) NOT NULL DEFAULT '0' AFTER `bgg_id`;
ALTER TABLE `event` ADD `location` VARCHAR( 250 ) NOT NULL AFTER `event_name`;
ALTER TABLE `game` ADD `scoring_type` INT( 2 ) NOT NULL DEFAULT '1' AFTER `team` ,
ADD `game_weight` DOUBLE( 6, 3 ) NOT NULL DEFAULT '1' AFTER `scoring_type`;
+
+DROP TABLE IF EXISTS `play`;
+CREATE TABLE `play` (
+ `play_pk` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `game_fk` int(11) unsigned NOT NULL,
+ `playtime` int(5) NOT NULL,
+ `started` datetime NOT NULL,
+ `ranked` int(1) NOT NULL DEFAULT '0',
+ `created_by` int(11) unsigned NOT NULL,
+ `created_when` datetime NOT NULL,
+ `deleted_by` int(11) unsigned DEFAULT NULL,
+ `deleted_when` datetime DEFAULT NULL,
+ `modified_by` int(11) unsigned NOT NULL,
+ `modified_when` datetime NOT NULL,
+ PRIMARY KEY (`play_pk`)
+);
+
+DROP TABLE IF EXISTS `play_player`;
+CREATE TABLE `play_player` (
+ `play_player_pk` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `play_fk` int(11) unsigned NOT NULL,
+ `user_fk` int(11) unsigned NOT NULL,
+ `score` double(10,2) NOT NULL,
+ `win` int(1) NOT NULL,
+ `rank_change` double(6,2) NOT NULL,
+ PRIMARY KEY (`play_player_pk`)
+);
+
+ALTER TABLE `user` ADD `ranking` INT( 8 ) NOT NULL DEFAULT '2000' AFTER `name_last`;
+
+ALTER TABLE `play_player` ADD UNIQUE (
+`play_fk` ,
+`user_fk`
+);
View
25 routes/manage/plays.php
@@ -0,0 +1,25 @@
+<?PHP
+
+$plays = new playlist();
+$plays->rows = isset($_REQUEST['rows']) ? $_REQUEST['rows'] : 20;
+$currentpage = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
+$filter = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : '';
+if(isset($_REQUEST['orderby'])) $plays->set_orderby($_REQUEST['orderby']);
+if(isset($_REQUEST['direction'])) $plays->set_direction($_REQUEST['direction']);
+
+// display the page
+if(getBestSupportedMimeType(array('text/html', 'application/json')) == 'application/json'){
+ bTemplate::jsonResponse($plays->resultsjson($filter, $currentpage));
+}else{
+ // fallback to html
+ $T = new bTemplate('manage', 'plays.tpl');
+ $T->assign('results', $plays->results($filter, $currentpage));
+ $T->assign('currentpage', $currentpage);
+ $T->assign('pagecount', $plays->pagecount());
+ $T->assign('rowcount', $plays->rowcount());
+ $T->assign('rows', $plays->rows);
+ $T->assign('filter', $filter);
+ $T->assign('orderby', $plays->orderby);
+ $T->assign('direction', $plays->direction);
+ $T->run();
+}
View
40 routes/manage/plays_item.php
@@ -0,0 +1,40 @@
+<?PHP
+
+$play = new play($PATH[1]);
+
+if(isset($_POST['action'])){
+ switch($_POST['action']){
+ case 'save':
+ $_POST['started'] = date('Y-m-d H:i:s', strtotime($_POST['started'] . ' ' . $_POST['started_time']));
+ $play->save($_POST);
+ header('location: /plays/' . $play->id );
+ die();
+ break;
+ case 'delete':
+ $play->delete();
+ header('location: /plays');
+ die();
+ break;
+ case 'restore':
+ $play->restore();
+ header('location: /plays/' . $play->id );
+ die();
+ break;
+ }
+}
+
+// display the page
+if(getBestSupportedMimeType(array('text/html', 'application/json')) == 'application/json'){
+ bTemplate::jsonResponse($play->resultsjson($filter, $currentpage));
+}else{
+ // fallback to html
+ if(!$play->isnew()){
+ $T = new bTemplate('manage', 'plays_item_ro.tpl');
+ $T->assign('play', $play);
+ $T->run();
+ }else{
+ $T = new bTemplate('manage', 'plays_item.tpl');
+ $T->assign('play', $play);
+ $T->run();
+ }
+}
View
2 template/manage/events_item.tpl
@@ -34,7 +34,7 @@
</div>
</div>
<div class="control-group">
- <label class="control-label" for="location">Name</label>
+ <label class="control-label" for="location">Location</label>
<div class="controls">
<input type="text" id="location" name="location" class="span6 required" value="{$event->location|x}" />
</div>
View
8 template/manage/games_item.tpl
@@ -29,6 +29,9 @@
<ul class="nav nav-tabs">
<li class="active"><a href="#game" data-toggle="tab">Game</a></li>
<li><a href="#owners" data-toggle="tab">Owners</a></li>
+ {if $game->game_weight > 1}
+ <li><a href="#plays" data-toggle="tab">Game Plays</a></li>
+ {/if}
</ul>
<div class="tab-content">
<div class="tab-pane active" id="game">
@@ -153,6 +156,11 @@
<div class="tab-pane" id="owners">
{include file="sublists/owners_table.tpl" results=$game->ownerslist()->results_all() addowner=true removeowner=true}
</div>
+ {if $game->game_weight > 1}
+ <div class="tab-pane" id="plays">
+ {include file="sublists/gameplays.tpl" results=array()}
+ </div>
+ {/if}
</div>
</div>
</div>
View
1 template/manage/layout.tpl
@@ -23,6 +23,7 @@
<ul class="nav" style="padding-left: 145px; font-size: 0.9em;">
<li><a href="/Events">Events</a></li>
<li><a href="/Games">Games</a></li>
+ <li><a href="/Plays">Plays</a></li>
<li><a href="/Users">Users</a></li>
<li><a href="/MassMail">Mass Email</a></li>
</ul>
View
32 template/manage/plays.tpl
@@ -0,0 +1,32 @@
+{extends 'layout.tpl'}
+{block "navbar-top"}
+{/block}
+{block name="content"}
+
+<h2 class="pull-left">Game Plays</h2>
+<div class="btn-group pull-right">
+ <a class="btn" href="/plays"><i class="icon-list"></i> List</a>
+ <!-- <a class="btn" href="/plays/new"><i class="icon-plus"></i> Add</a> -->
+</div>
+<div class="clearfix"></div>
+
+<table class="table table-striped">
+ <thead>
+ <tr>
+ {include file="common/searchheader.tpl" title="Game" col="game_name" baselink="/plays" orderby=$orderby direction=$direction filter=$filter}
+ {include file="common/searchheader.tpl" title="Played" col="started" baselink="/plays" orderby=$orderby direction=$direction filter=$filter}
+ {include file="common/searchheader.tpl" title="Duration" col="playtime" baselink="/plays" orderby=$orderby direction=$direction filter=$filter}
+ </tr>
+ </thead>
+ <tbody>
+ {foreach from=$results item=row}
+ <tr class="linkrow" data-link="/play/{$row['play_pk']}/{$row['game_name']|prettyurlencode}">
+ <td>{$row['game_name']|x}</td>
+ <td>{$row['started']|x}</td>
+ <td>{$row['playtime']|x} Min</td>
+ </tr>
+ {/foreach}
+ </tbody>
+</table>
+{include file='common/pager.tpl' currentpage=$currentpage pagecount=$pagecount rows=$rows rowcount=$rowcount orderby=$orderby direction=$direction filter=$filter}
+{/block}
View
91 template/manage/plays_item.tpl
@@ -0,0 +1,91 @@
+{extends 'layout.tpl'}
+{block name="content"}
+{assign 'game' $play->game()}
+
+<h2 class="pull-left">Play {$play->id}</h2>
+
+<h1>DO NOT USE THIS INPUT METHOD, CURRENTLY BROKEN, ENTER FROM GAME PAGE</h1>
+
+{if !$play->isnew()}
+<div class="btn-group pull-right">
+ <form id="form_game_delete" method="post">
+ <input type="hidden" name="action" value="delete" />
+ <button class="btn btn-danger" data-submitfor="#form_game_delete"><i class="icon-trash icon-white"></i> Delete</button>
+ </form>
+</div>
+{/if}
+
+<div class="clearfix"></div>
+
+<form method="post">
+<input type="hidden" name="action" value="save" />
+<input type="hidden" name="game_fk" id="game_fk" value="{if $game}{$game->id}{/if}" />
+<div class="row">
+ <div class="span4">
+ <div class="control-group">
+ <label class="control-label" for="inputNotes">Game</label>
+ <div class="controls">
+ <input type="text" name="parent" class="fillgamename span4 required" data-idfill="#game_fk" value="{if $game}{$game->game_name}{/if}" placeholder="Game Name - Required" autocomplete="off" />
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="started">Started Date</label>
+ <div class="controls">
+ <input type="text" id="started" name="started" class="span2 datepicker required" value="{$play->started|extract_date}" />
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="started_time">Started Time</label>
+ <div class="controls">
+ <input type="text" id="started_time" name="started_time" class="span2 timepicker required" value="{$play->started|extract_time}" />
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="playtime">Length</label>
+ <div class="controls">
+ <div class="input-append">
+ <input type="text" id="playtime" name="playtime" style="width:4em" value="{$play->playtime}" />
+ <span class="add-on">Min</span>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="span8">
+ {if $game}
+ <table class="table">
+ <thead>
+ <th>Player</th>
+ <th>Score</th>
+ <th>Outcome</th>
+ </thead>
+ <tbody>
+ {for $x=1 to $game->max_players}
+ <tr>
+ <td>
+ <input type="hidden" id="user{$x}" name="user_fk[]" value="{$game->parent_fk}" />
+ <input type="text" id="player{$x}" name="player[]" class="filluseremail" data-idfill="#user{$x}" autocomplete="off" value="" />
+ </td>
+ <td><input type="text" id="score{$x}" name="score[]" value="" /></td>
+ <td>
+ <select name="win[]">
+ <option value="1">Win</option>
+ <option value="0">Loss</option>
+ </select>
+ </td>
+ </tr>
+ {/for}
+ </tbody>
+ </table>
+ {/if}
+ </div>
+</div>
+<div class="row">
+ <div class="span12">
+ <div class="form-actions">
+ <button type="submit" class="btn btn-primary">Save</button>
+ </div>
+ </div>
+</div>
+</form>
+
+{/block}
View
58 template/manage/plays_item_ro.tpl
@@ -0,0 +1,58 @@
+{extends 'layout.tpl'}
+{block name="content"}
+{assign 'game' $play->game()}
+
+<h2 class="pull-left">Play {$play->id}</h2>
+
+<div class="btn-group pull-right">
+ <form id="form_game_delete" method="post">
+ <input type="hidden" name="action" value="delete" />
+ <button class="btn btn-danger" data-submitfor="#form_game_delete"><i class="icon-trash icon-white"></i> Delete</button>
+ </form>
+</div>
+
+<div class="clearfix"></div>
+
+<div class="row">
+ <div class="span4">
+ <div class="control-group">
+ <label class="control-label" for="inputNotes">Game</label>
+ <div class="controls">
+ {$game->game_name}
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="started">Started</label>
+ <div class="controls">
+ {$play->started|extract_date} {$play->started|extract_time}
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="playtime">Length</label>
+ <div class="controls">
+ {$play->playtime} Min
+ </div>
+ </div>
+ </div>
+ <div class="span8">
+ <table class="table">
+ <thead>
+ <th>Player</th>
+ <th>Score</th>
+ <th>Outcome</th>
+ </thead>
+ <tbody>
+ {foreach from=$play->playerslist() item=row}
+ <tr>
+ <td>{$row['name_first']|x} {$row['name_last']|x}</td>
+ <td>{$row['score']}</td>
+ <td>{if $row['win'] == 1}Win{else}Loss{/if}</td>
+ </tr>
+ {/foreach}
+ </tbody>
+ </table>
+ </div>
+</div>
+
+
+{/block}
View
81 template/manage/sublists/gameplays.tpl
@@ -0,0 +1,81 @@
+<table class="table table-striped">
+ <thead>
+ <tr>
+ <th>When</th>
+ <th>Length</th>
+ </tr>
+ </thead>
+ <tbody>
+ {foreach from=$results item=row}
+ <tr class="linkrow" data-link="/plays/{$row['game_play_pk']}">
+ <td>When</td>
+ <td>Length</td>
+ </tr>
+ {/foreach}
+ </tbody>
+</table>
+
+<h3>Enter a Play</h3>
+
+<form method="post" action="/plays/new">
+<div class="row">
+ <input type="hidden" name="action" value="save" />
+ <input type="hidden" name="game_fk" value="{$game->id}" />
+ <div class="span4">
+ <div class="control-group">
+ <label class="control-label" for="started">Started Date</label>
+ <div class="controls">
+ <input type="text" id="started" name="started" class="span2 datepicker required" value="" />
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="started_time">Started Time</label>
+ <div class="controls">
+ <input type="text" id="started_time" name="started_time" class="span2 timepicker required" value="" />
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="playtime">Length</label>
+ <div class="controls">
+ <div class="input-append">
+ <input type="text" id="playtime" name="playtime" style="width:4em" value="" />
+ <span class="add-on">Min</span>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="span8">
+ <table class="table">
+ <thead>
+ <th>Player</th>
+ <th>Score</th>
+ <th>Outcome</th>
+ </thead>
+ <tbody>
+ {for $x=1 to $game->max_players}
+ <tr>
+ <td>
+ <input type="hidden" id="user{$x}" name="user_fk[]" value="" />
+ <input type="text" id="player{$x}" name="player[]" class="filluseremail" data-idfill="#user{$x}" autocomplete="off" value="" />
+ </td>
+ <td><input type="text" id="score{$x}" name="score[]" value="" /></td>
+ <td>
+ <select name="win[]">
+ <option value="1">Win</option>
+ <option value="0">Loss</option>
+ </select>
+ </td>
+ </tr>
+ {/for}
+ </tbody>
+ </table>
+ </div>
+</div>
+<div class="row">
+ <div class="span12">
+ <div class="form-actions">
+ <button type="submit" class="btn btn-primary">Save</button>
+ </div>
+ </div>
+</div>
+</form>

0 comments on commit b8c8f6c

Please sign in to comment.
Something went wrong with that request. Please try again.