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 = '