function user_stats_login_count_update in User Stats 6
Same name and namespace in other branches
- 7 user_stats.module \user_stats_login_count_update()
Manage the login count of a given user.
Parameters
$uid: Unique id of the user who's record should be updated.
$op: Whether the user login count should be incremented, decremented, or reset. Possible values are:
- 'increment'
- 'decrement'
- 'reset'
2 calls to user_stats_login_count_update()
- user_stats_login_count_reset_action in ./
user_stats.module - Implementation of a Drupal action. Resets a user's login count.
- user_stats_user in ./
user_stats.module - Implementation of hook_user().
File
- ./
user_stats.module, line 700 - User Stats provides commonly requested user statistics for themers. These are:
Code
function user_stats_login_count_update($op, $uid) {
if (!is_numeric($uid)) {
return;
}
switch ($op) {
case 'increment':
if (user_stats_isset('login_count', $uid)) {
// Update existing value.
db_query("UPDATE {user_stats_values} SET value = value + 1\n WHERE name = 'login_count' AND uid = %d", $uid);
}
else {
// If there isn't a value insert it.
db_query("INSERT INTO {user_stats_values} (name, uid, value)\n VALUES ('login_count', %d, 1)", $uid);
}
break;
case 'decrement':
if (user_stats_isset('login_count', $uid)) {
// Update existing value.
db_query("UPDATE {user_stats_values} SET value = value - 1\n WHERE name = 'login_count' AND uid = %d", $uid);
}
else {
// If there isn't a value insert it.
db_query("INSERT INTO {user_stats_values} (name, uid, value)\n VALUES ('login_count', %d, 0)", $uid);
}
break;
case 'reset':
db_query("DELETE FROM {user_stats_values}\n WHERE name = 'login_count' AND uid = %d", $uid);
break;
}
// Flush token cache.
if (module_exists('token')) {
token_get_values('user', NULL, TRUE);
}
// Flush internal cache.
user_stats_cache_set('reset', $uid);
// Allow modules to react to a statistic change.
module_invoke_all('user_stats', 'login_count', $op, $uid, user_stats_get_stats('login_count', $uid));
}