Example #1
0
//Get the user theme and enough info to be used in chat_format_message() which passes it along to
if (!($USER = $DB->get_record('user', array('id' => $chatuser->userid)))) {
    // no optimisation here, it would break again in future!
    chat_print_error('ERROR', get_string('invaliduserid', 'error'));
}
if (!($chat = $DB->get_record('chat', array('id' => $chatuser->chatid)))) {
    chat_print_error('ERROR', get_string('invalidcoursemodule', 'error'));
}
if (!($cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $course->id))) {
    chat_print_error('ERROR', get_string('invalidcoursemodule', 'error'));
}
// setup $PAGE so that format_text will work properly
$PAGE->set_cm($cm, $course, $chat);
if ($CFG->chat_use_cache) {
    $cache = new file_cache();
    $users = $cache->get('user');
    if (empty($users)) {
        $users = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid);
        $cache->set('user', $users);
    }
} else {
    $users = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid);
}
$users = format_user_list($users, $course);
if (!empty($chat_init)) {
    $response['users'] = $users;
    echo json_encode($response);
    exit;
}
// force deleting of timed out users if there is a silence in room or just entering
if (time() - $chat_lasttime > $CFG->chat_old_ping) {