Getting online users for Each Group

Hello,

I am trying to get online users for each group, what I have done till now is this

in my plugin:

elgg_extend_view('groups/right_column', 'groupusers/online_users');

in my online_users file this is the code:

<div class="group_widget">
<h2><?php echo rozce_echo('Online Users'); ?></h2>
<?php
    $count = count(find_active_group_users(600, 9999));
    $members = find_active_group_users(1200,16,0);

    if($members) {
        echo rozce_view_entity_list($members, $count,0,10,false);
    }
   
?>   
</div>

what I was thinking was adding a new function called find_active_group_users this will extend over the core find_active_users , but I am having trouble getting the online users for groups

this is function of find_active_group_users:

function find_active_group_users($seconds = 600, $limit = 10, $offset = 0, $group_guid) {
    global $CONFIG;

    $seconds = (int)$seconds;
    $limit = (int)$limit;
    $offset = (int)$offset;

    $time = time() - $seconds;

    $access = get_access_sql_suffix("e");

    $query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}users_entity u on e.guid = u.guid where u.last_action >= {$time} and $access and e.container_guid = {$group_guid} order by u.last_action desc limit {$offset},{$limit}";

    return get_data($query, "entity_row_to_rozcestar");
}

what do I change in the SQL to add group context in it ?

Please help out,

 

Regards,

Aimash