From 6b2500bb66d03f605eaf5a1f1fc4ef47a115cc48 Mon Sep 17 00:00:00 2001 From: Tristan Olive Date: Thu, 4 Jun 2015 02:03:58 -0400 Subject: [PATCH] Added user of the day to front page: * Altered boincuser database table to include uotd_time field * Added logic to determine the current user of the day (or establish a new one, if due) * Replaced screensaver info on front page with user of the day photo and link to profile (DBOINCP-110) --- .../boinc/modules/boincuser/boincuser.install | 27 +++++++- .../boinc/modules/boincuser/boincuser.module | 66 +++++++++++++++++-- .../boinc/themes/boinc/css/panels-styles.css | 31 ++++++++- 3 files changed, 116 insertions(+), 8 deletions(-) diff --git a/drupal/sites/default/boinc/modules/boincuser/boincuser.install b/drupal/sites/default/boinc/modules/boincuser/boincuser.install index d443c802b4..a9d41e21a6 100644 --- a/drupal/sites/default/boinc/modules/boincuser/boincuser.install +++ b/drupal/sites/default/boinc/modules/boincuser/boincuser.install @@ -56,7 +56,15 @@ function boincuser_schema() { ), 'penalty_expiration' => array( 'description' => t('A timestamp at which point any penalty period will - expire (i.e. restrictions on posting or community participation'), + expire (i.e. restrictions on posting or community participation)'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'uotd_time' => array( + 'description' => t('A timestamp of the last time this user was deemed + user of the day'), 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, @@ -90,3 +98,20 @@ function boincuser_update_6100() { db_add_field($result, 'boincuser', 'penalty_expiration', $spec); return $result; } + +/** + * Add uotd_time field to boincuser table + */ +function boincuser_update_6101() { + $result = array(); + $spec = array( + 'description' => 'A timestamp of the last time this user was deemed + user of the day', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ); + db_add_field($result, 'boincuser', 'uotd_time', $spec); + return $result; +} diff --git a/drupal/sites/default/boinc/modules/boincuser/boincuser.module b/drupal/sites/default/boinc/modules/boincuser/boincuser.module index 8e745d46df..ba5deb1cd5 100644 --- a/drupal/sites/default/boinc/modules/boincuser/boincuser.module +++ b/drupal/sites/default/boinc/modules/boincuser/boincuser.module @@ -1119,6 +1119,59 @@ function join_page($type = null) { function boincuser_home_page() { global $user; $site_name = variable_get('site_name', ''); + // Determine the user of the day + $current_uotd = db_fetch_object(db_query(" + SELECT + uid, + uotd_time + FROM {boincuser} + ORDER BY uotd_time DESC + LIMIT 1" + )); + if ($current_uotd->uotd_time < strtotime('today midnight')) { + // Select a new user of the day + // First get a list of users with recent credit + db_set_active('boinc'); + $users_with_credit = db_query(" + SELECT + id + FROM {user} u + JOIN {profile} p ON p.userid = u.id + WHERE expavg_credit > 1 + ORDER BY uotd_time ASC, RAND()" + ); + db_set_active('default'); + $active_users = array(); + while ($user_with_credit = db_fetch_object($users_with_credit)) { + $active_users[] = $user_with_credit->id; + } + $active_users = implode(',', $active_users); + $new_uotd_uid = db_result(db_query(" + SELECT + n.uid + FROM {node} n + JOIN {boincuser} bu ON bu.uid = n.uid + WHERE n.type = 'profile' + AND n.status = 1 + AND n.moderate = 0 + " . ($active_users ? " AND bu.boinc_id IN ({$active_users}) " : '') . " + ORDER BY RAND() + LIMIT 1" + )); + $uotd = user_load($new_uotd_uid); + if ($uotd->uid) { + db_query(" + UPDATE {boincuser} + SET uotd_time = '%d' + WHERE uid = '%d'", + time(), $uotd->uid + ); + } + } + else { + $uotd = user_load($current_uotd->uid); + } + $uotd_image = boincuser_get_user_profile_image($uotd->uid, FALSE); $output = '

'; $output .= ($user->uid) ? bts('Welcome back!') : ($site_name ? bts('What is @this_project?', array('@this_project' => $site_name)) : bts('Welcome!')); $output .= '

'; @@ -1133,10 +1186,15 @@ function boincuser_home_page() { $output .= ''; $output .= '
'; $output .= '
'; - $output .= '
'; - $output .= '
' . bts('About our screensaver') . '
'; - $output .= '
'; - $output .= '
'; + $output .= ' '; + $output .= '
'; + $output .= theme('imagefield_image', $uotd_image['image'], $uotd_image['alt'], + $uotd_image['alt'], array(), FALSE); + $output .= '
'; + $output .= '
' . bts('User of the day') . '
'; + $output .= '
' . $uotd->boincuser_name . '
'; + $output .= '
'; + $output .= '
'; $output .= '
' . bts('Over 500,000 volunteers and counting.') . '
'; $output .= '
'; $output .= '
' . bts('Windows') . '
'; diff --git a/drupal/sites/default/boinc/themes/boinc/css/panels-styles.css b/drupal/sites/default/boinc/themes/boinc/css/panels-styles.css index 37223ade19..fcf7cbaf27 100644 --- a/drupal/sites/default/boinc/themes/boinc/css/panels-styles.css +++ b/drupal/sites/default/boinc/themes/boinc/css/panels-styles.css @@ -60,14 +60,39 @@ position: relative; } .boinc-overview-details .detail-container { - background: url(../images/icon-screensaver.png) no-repeat top left; padding: 5px 0; position: absolute; bottom: 0; } -.boinc-overview-details .detail-section { +.boinc-overview-details .user-of-the-day { + display: block; float: left; - margin: 0 0 0 20px; +} +.boinc-overview-details a.user-of-the-day, +.boinc-overview-details a.user-of-the-day:hover { + color: inherit; + text-decoration: none; +} +.boinc-overview-details .user-of-the-day .text, +.boinc-overview-details .user-of-the-day .detail { + margin-left: 60px; +} +.boinc-overview-details .user-of-the-day .detail { + margin-top: 5px; +} +.boinc-overview-details .user-of-the-day .picture { + float: left; + margin-top: -7px; + max-height: 50px; + overflow: hidden; +} +.boinc-overview-details .user-of-the-day .picture img { + width: 50px; + margin: 0; +} +.boinc-overview-details .volunteers { + float: left; + margin: 0 0 0 40px; } .boinc-overview-details .text { font-size: 15px;