From ea5f4abbb9bbb601e56d1aef354765b7ef22b789 Mon Sep 17 00:00:00 2001 From: Wilson Wise Date: Tue, 2 Sep 2014 15:31:46 -0400 Subject: [PATCH 1/5] Better Empty Challenge When a new challenge is created, the default School ID should be set to `999` instead of `0` to create a better experience with the displays should the user not actually enter their picks. --- controllers/AdminChallengeController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/AdminChallengeController.php b/controllers/AdminChallengeController.php index bd41a16..a5fe751 100644 --- a/controllers/AdminChallengeController.php +++ b/controllers/AdminChallengeController.php @@ -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; } From 77feb3356da75276aaeebe66600eb420c22ac0e0 Mon Sep 17 00:00:00 2001 From: Wilson Wise Date: Wed, 3 Sep 2014 14:28:51 -0400 Subject: [PATCH 2/5] Show other users' picks only when the challenge is not active. --- controllers/AppController.php | 3 +++ controllers/MainController.php | 18 ++++++++++++++++++ views/templates/main/week.html.twig | 11 +++++++++++ 3 files changed, 32 insertions(+) diff --git a/controllers/AppController.php b/controllers/AppController.php index 72a96f3..4aee285 100644 --- a/controllers/AppController.php +++ b/controllers/AppController.php @@ -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)) { @@ -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; diff --git a/controllers/MainController.php b/controllers/MainController.php index 046e048..388202c 100644 --- a/controllers/MainController.php +++ b/controllers/MainController.php @@ -92,6 +92,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 { @@ -495,6 +497,22 @@ 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) { + $log->log('info', 'User page', $user_page); + $log->log('info', 'Active user', $active_user); + return ($user_page === $active_user); + } else { + return TRUE; + } + } } ?> diff --git a/views/templates/main/week.html.twig b/views/templates/main/week.html.twig index 536ca46..4335391 100644 --- a/views/templates/main/week.html.twig +++ b/views/templates/main/week.html.twig @@ -15,6 +15,15 @@ userData = {}; {% endif %} + + {% if not show_results %} + + {% endif %} {% endblock %} {% block content %} @@ -44,6 +53,8 @@ or {{ macros.link("/", "Cancel", base_path) }}

+ {% elseif user_logged_in %} +

Visit {{ macros.link("/week", "your page", base_path) }} to enter your picks.

{% else %}

{{ macros.link("/login", "Login", base_path) }} to enter your picks.

{% endif %} From 963ae3a7366f55fcad4c8198f74f20601c38570c Mon Sep 17 00:00:00 2001 From: Wilson Wise Date: Sat, 6 Sep 2014 11:31:41 -0400 Subject: [PATCH 3/5] Reminders will now be sent in Production. Fixed bug with checking environment. --- controllers/AdminController.php | 7 +++++-- controllers/AppController.php | 4 ++++ index.php | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/controllers/AdminController.php b/controllers/AdminController.php index b7a5b7a..f9c5747 100644 --- a/controllers/AdminController.php +++ b/controllers/AdminController.php @@ -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')) { @@ -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 { diff --git a/controllers/AppController.php b/controllers/AppController.php index 72a96f3..fd3745a 100644 --- a/controllers/AppController.php +++ b/controllers/AppController.php @@ -83,5 +83,9 @@ static function getReferrer() { return $referrer; } + + static function getEnv() { + return (int) option('env'); + } } ?> diff --git a/index.php b/index.php index 16574bb..9af0cf0 100644 --- a/index.php +++ b/index.php @@ -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, From 27160ca212fba097507c16349da67c415ecaee38 Mon Sep 17 00:00:00 2001 From: Wilson Wise Date: Mon, 8 Sep 2014 15:19:10 -0400 Subject: [PATCH 4/5] Across all pages, others picks are not shown while the challenge is active --- controllers/MainController.php | 96 ++++++++++++++--------- views/templates/main/picks-week.html.twig | 9 +++ views/templates/main/picks.html.twig | 9 +++ 3 files changed, 79 insertions(+), 35 deletions(-) diff --git a/controllers/MainController.php b/controllers/MainController.php index 388202c..22e0970 100644 --- a/controllers/MainController.php +++ b/controllers/MainController.php @@ -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 @@ -236,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', @@ -286,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 { @@ -318,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, @@ -327,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); } @@ -506,13 +509,36 @@ static function show_results($challenge_active, $user_page, $active_user) { $log = option('log'); if ($challenge_active) { - $log->log('info', 'User page', $user_page); - $log->log('info', 'Active user', $active_user); 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; + } } ?> diff --git a/views/templates/main/picks-week.html.twig b/views/templates/main/picks-week.html.twig index 7198094..9fb1e2a 100644 --- a/views/templates/main/picks-week.html.twig +++ b/views/templates/main/picks-week.html.twig @@ -2,6 +2,15 @@ {% block head %} {{ parent() }} + {% if not show_results %} + + + {% endif %} diff --git a/views/templates/main/picks.html.twig b/views/templates/main/picks.html.twig index 41559c7..ad37415 100644 --- a/views/templates/main/picks.html.twig +++ b/views/templates/main/picks.html.twig @@ -2,6 +2,15 @@ {% block head %} {{ parent() }} + {% if not show_results %} + + + {% endif %} {% endblock %} {% block content %} From 32cb70052b473f0cfb114088a741a0929731443f Mon Sep 17 00:00:00 2001 From: Wilson Wise Date: Tue, 9 Sep 2014 11:16:39 -0400 Subject: [PATCH 5/5] Bump to version 2.10.0 --- VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index 7227c77..80de12c 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -v2.9.1 +v2.10.0