Solution : how to display no of logged in users next to chat name

Solution : how to display no of logged in users next to chat name

by Anil Sharma -
Number of replies: 0

We have always wanted to display the no of logged in users next to the name of the chat on the course page. This makes its useful for everyone to decide even before clicking on the chat name if there are users logged in or not. 

These changes make it possible :


Step 1. Open file:: /course/lib.php to edit it
==========================================
(i) Go line no.(1021-1024) where it says -------->

       ' <a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
       ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.
       $instancename.'</a>';

//Add this code here //////////

 //-----------no of users display ------------------------------

                    if ($mod->modname == 'chat'){
                     $chat12=5;
                    $i=0;
                    $chatusers1 = chat_get_users12($chat12);
                    $timenow = time(); 
                   
                    if($chatusers1) {
                    foreach($chatusers1 as $chatuser){
                     $i++;       
                    }
                   }
                    $linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
                   
                       echo ' '.  $i.' '.'user(s) ';
                   
                    }

      //------------------end step 1-----------------------------------

=======================================================================

Step 2 :  Now go end of the file where it says------->

 choose_from_menu($choices, 'visible', $visible, '', '', 0, false, $hiddensection);
    echo '</td></tr>';
}

Add these line here :


//-------------display no of users -------------------------------

function chat_get_users12($chatid, $groupid=0) {
   
    global $CFG;

    if ($groupid) {
        $groupselect = " AND (c.groupid='$groupid' OR c.groupid='0')";
    } else {
        $groupselect = "";
    }

    return get_records_sql("SELECT DISTINCT u.id, u.firstname, u.lastname,u.class,u.section, u.picture, c.lastmessageping, c.firstping
                              FROM {$CFG->prefix}chat_users c,
                                   {$CFG->prefix}user u
                             WHERE c.chatid = '$chatid'
                               AND u.id = c.userid $groupselect
                             ORDER BY c.firstping ASC");
}

//----------------------------------end of changes-------------------------

Average of ratings: -