Skip to content

Commit

Permalink
Release v2.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilson Wise committed Sep 9, 2014
2 parents 1d706cb + 32cb700 commit 3a267f1
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 38 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.9.1
v2.10.0
2 changes: 1 addition & 1 deletion controllers/AdminChallengeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static function challenge_add() {
);
$temp = new StdClass;
$temp->cid = $db->insert_id;
$temp->sid = 0;
$temp->sid = 999;
$user_challenges[] = $temp;
}

Expand Down
7 changes: 5 additions & 2 deletions controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static function send_emails($week) {

$site_name = SITE_NAME;

$env = trim(option('env'));
$env = self::getEnv();

// Get commissioners
if ($result = $db->qry('SELECT username, email FROM {{users}} WHERE permissions = 2')) {
Expand All @@ -247,9 +247,12 @@ static function send_emails($week) {
$log->log('message', sprintf('Reminder email sent to %s', htmlspecialchars($to)));
mail($to, $subject, $message, $headers);
}
else {
elseif ($env === ENV_DEVELOPMENT) {
echo htmlspecialchars("{$headers}{$rn}{$rn}To: {$to}{$rn}{$rn}{$subject}{$rn}{$rn}$message{$rn}- - -{$rn}");
}
else {
$log->log('error', sprintf('Unmatched environment variable env(%s):%s', $env, gettype($env)));
}
}
}
else {
Expand Down
7 changes: 7 additions & 0 deletions controllers/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static function getUserInfoFromUid($id) {

static function getUserInfo($query, $arg) {
$db = option('db');
$log = option('log');
$usr = option('empty_user');

if ($result = $db->qry($query, $arg)) {
Expand All @@ -65,6 +66,8 @@ static function getUserInfo($query, $arg) {
$usr['reminder'] = $obj->reminder;
$usr['sub'] = $obj->submission;
}
} else {
$log->log('error', 'Issue fetching user info', $db->error);
}

return $usr;
Expand All @@ -83,5 +86,9 @@ static function getReferrer() {

return $referrer;
}

static function getEnv() {
return (int) option('env');
}
}
?>
110 changes: 77 additions & 33 deletions controllers/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,8 @@ static function week_user($week_num, $username) {

if (is_numeric($week_num) && $week_num <= $challenge_week) {
// First determine if challenge is active, default is no
$challenge_active = FALSE;
if ($week_num == $challenge_week) {
// Maybe
$now = time();
if ($result = $db->qry('SELECT DISTINCT week FROM {{challenges}} WHERE closetime > %s AND year = %s', $now, FC_YEAR)) {
while ($obj = $result->fetch_object()) {
$challenge_active = TRUE;
$show_form = TRUE;
}
}
$challenge_active = $show_form = self::is_challenge_active($week_num);
}

// There are some scenarios where we don't want to show the form
Expand Down Expand Up @@ -92,6 +84,8 @@ static function week_user($week_num, $username) {
'week_num' => $week_num,
'show_form' => $show_form,
'user_active' => $user_info['use'],
'user_logged_in' => $logged_user['use'],
'show_results' => self::show_results($challenge_active, $user_info['uid'], $logged_user['uid']),
));
}
else {
Expand Down Expand Up @@ -234,13 +228,14 @@ static function picks($user = FALSE) {
$db = option('db');
$log = option('log');

if ($user) {
$user_info = self::getUserInfoFromName($user);
} else {
$user_info = option('user_info');
}
$logged_user = option('user_info');
$user_info = self::getUserInfoFromName($user);
$challenge_week = (int) option('challenge_week');
$challenge_active = FALSE;

if ($user_info['name'] && $user_info['uid']) {
$challenge_active = self::is_challenge_active();

$db
->setQuery(
'challenge',
Expand Down Expand Up @@ -284,6 +279,7 @@ static function picks($user = FALSE) {
'title' => sprintf('%s\'s Picks', strtoupper($user_info['name'])),
'challenges' => array_reverse($challenges),
'user_subs' => $user_challenge_info,
'show_results' => self::show_results($challenge_active, $user_info['uid'], $logged_user['uid']),
));
}
else {
Expand Down Expand Up @@ -316,6 +312,9 @@ static function picks_week($week = FALSE) {
$week = option('standings_week');
}

$challenge_week = option('challenge_week');
$challenge_active = self::is_challenge_active($week);

$db->setQuery(
'challenge',
'SELECT c.cid, c.week, c.home_sid AS home_sid, hs.school AS home_school,
Expand All @@ -325,28 +324,34 @@ static function picks_week($week = FALSE) {
$week
);

if ($result = $db->useQuery('challenge')) {
$challenge = array();
while ($obj = $result->fetch_object()) {
$challenge[] = $obj;
}
if (is_numeric($week) && $week <= $challenge_week)
if ($result = $db->useQuery('challenge')) {
$challenge = array();
while ($obj = $result->fetch_object()) {
$challenge[] = $obj;
}

// Get all the user submissions for this week
$submissions = array();
if ($results = $db->qry('SELECT subvalue FROM {{submissions}} WHERE year = %s AND week = %s ORDER BY subkey', $year, $week)) {
while ($obj = $results->fetch_object()) {
$submissions[] = unserialize($obj->subvalue);
// Get all the user submissions for this week
$submissions = array();
if ($results = $db->qry('SELECT subvalue FROM {{submissions}} WHERE year = %s AND week = %s ORDER BY subkey', $year, $week)) {
while ($obj = $results->fetch_object()) {
$submissions[] = unserialize($obj->subvalue);
}
}
}

return self::template('main/picks-week.html.twig', array(
'page_name' => "Week $week Picks",
'title' => "Week $week Picks",
'challenge' => $challenge,
'submissions' => $submissions,
'week_num' => $week,
));
}
return self::template('main/picks-week.html.twig', array(
'page_name' => "Week $week Picks",
'title' => "Week $week Picks",
'challenge' => $challenge,
'submissions' => $submissions,
'week_num' => $week,
'show_results' => self::show_results($challenge_active, 1, 2),
));
}
else {
$log->log('error', 'Issue with challenge query.', $db->error);
halt(SERVER_ERROR);
}
else {
halt(NOT_FOUND);
}
Expand Down Expand Up @@ -495,6 +500,45 @@ static function get_standings() {
}
return $arr;
}

/**
* If the challenge is active, only show the results if the user page and active user match
* If the challenge is inactive, always show the results
*/
static function show_results($challenge_active, $user_page, $active_user) {
$log = option('log');

if ($challenge_active) {
return ($user_page === $active_user);
} else {
return TRUE;
}
}

/**
* Determine if a specific challenge is active or if any challenge is active
*/
static function is_challenge_active($week=NULL) {
$db = option('db');

$is_active = FALSE;
$challenge_week = (int) option('challenge_week');
$week = is_null($week) ? NULL : (int) $week;

if (is_null($week) || ($week && $week === $challenge_week)) {
$now = time();
if ($result = $db->qry('SELECT DISTINCT week FROM {{challenges}} WHERE closetime > %s AND year = %s', $now, FC_YEAR)) {
while ($obj = $result->fetch_object()) {
$selected_week = (int) $obj->week;
if ($selected_week === $challenge_week) {
$is_active = TRUE;
}
}
}
}

return $is_active;
}
}

?>
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function configure() {
option('db', $db->setPrefix(DB_PFIX));

// Setup template engine
$cache = $env == ENV_PRODUCTION ? CACHE_DIR : FALSE;
$cache = $env === ENV_PRODUCTION ? CACHE_DIR : FALSE;
$loader = new Twig_Loader_Filesystem(TEMPLATE_DIR);
$twig = new Twig_Environment($loader, array(
'cache' => $cache,
Expand Down
9 changes: 9 additions & 0 deletions views/templates/main/picks-week.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

{% block head %}
{{ parent() }}
{% if not show_results %}
<style type="text/css">
#content td.picked {
background-color: inherit;
font-weight: inherit;
}
</style>
<script>{{ now }}</script>
{% endif %}
<script type="application/javascript">
var useTab = {{ week_num }};
</script>
Expand Down
9 changes: 9 additions & 0 deletions views/templates/main/picks.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

{% block head %}
{{ parent() }}
{% if not show_results %}
<style type="text/css">
#content td.picked {
background-color: inherit;
font-weight: inherit;
}
</style>
<script>{{ now }}</script>
{% endif %}
{% endblock %}

{% block content %}
Expand Down
11 changes: 11 additions & 0 deletions views/templates/main/week.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
userData = {};
{% endif %}
</script>

{% if not show_results %}
<style type="text/css">
.user-pick {
background-color: inherit;
font-weight: inherit;
}
</style>
{% endif %}
{% endblock %}

{% block content %}
Expand Down Expand Up @@ -44,6 +53,8 @@
<input id="save_btn" type="submit" value="Save"> or {{ macros.link("/", "Cancel", base_path) }}
</p>
</form>
{% elseif user_logged_in %}
<p>Visit {{ macros.link("/week", "your page", base_path) }} to enter your picks.</p>
{% else %}
<p>{{ macros.link("/login", "Login", base_path) }} to enter your picks.</p>
{% endif %}
Expand Down

0 comments on commit 3a267f1

Please sign in to comment.