Re: Automatic Group Assignment By Posts Number. How Does It Work?
Hi,
the function is in this file
includes/functions_post.php
function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_id, &$user_id)
Here is the portion of the code:
$sql = "SELECT ug.user_id, g.group_id as g_id, u.user_posts, u.user_color_group, u.user_color, g.group_count, g.group_color, g.group_count_max FROM (" . GROUPS_TABLE . " g, " . USERS_TABLE . " u)
LEFT JOIN ". USER_GROUP_TABLE." ug ON g.group_id = ug.group_id AND ug.user_id = '" . $user_id . "'
WHERE u.user_id = '" . $user_id . "'
AND g.group_single_user = '0'
AND g.group_count_enable = '1'
AND g.group_moderator <> '" . $user_id . "'";
$result = $db->sql_query($sql);
while ($group_data = $db->sql_fetchrow($result))
{
$user_already_added = (empty($group_data['user_id'])) ? false : true;
$user_add = (($group_data['group_count'] == $group_data['user_posts']) && ($user_id != ANONYMOUS)) ? true : false;
$user_remove = ($group_data['group_count'] > $group_data['user_posts'] || $group_data['group_count_max'] < $group_data['user_posts']) ? true : false;
if ($user_add && !$user_already_added)
{
update_user_color($user_id, $group_data['group_color'], $group_data['g_id'], false, false);
update_user_posts_details($user_id, $group_data['group_color'], '', false, false);
empty_cache_folders(USERS_CACHE_FOLDER);
//user join a autogroup
$sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
VALUES (" . $group_data['g_id'] . ", $user_id, '0')";
$db->sql_query($sql);
}
elseif ($user_already_added && $user_remove)
{
update_user_color($user_id, $config['active_users_color'], 0);
update_user_posts_details($user_id, '', '', false, false);
empty_cache_folders(USERS_CACHE_FOLDER);
//remove user from auto group
$sql = "DELETE FROM " . USER_GROUP_TABLE . "
WHERE group_id = '" . $group_data['g_id'] . "'
AND user_id = '" . $user_id . "'";
$db->sql_query($sql);
}
}
}