示例#1
0
?>
\" id=\"mod-chat-gui_header_js-jsupdate\"><div style=\"display: none\" id=\"msgStarted\">&nbsp;</div>");
        }
        //]]>
        </script>
    </head>
    <body>

<?php 
// Ensure the HTML head makes it out there.
echo $CHAT_DUMMY_DATA;
for ($n = 0; $n <= CHAT_MAX_CLIENT_UPDATES; $n++) {
    // Ping first so we can later shortcut as needed.
    $chatuser->lastping = time();
    $DB->set_field('chat_users', 'lastping', $chatuser->lastping, array('id' => $chatuser->id));
    if ($message = chat_get_latest_message($chatuser->chatid, $chatuser->groupid)) {
        $chatnewlasttime = $message->timestamp;
        $chatnewlastid = $message->id;
    } else {
        $chatnewlasttime = 0;
        $chatnewlastid = 0;
        print " \n";
        print $CHAT_DUMMY_DATA;
        sleep($CFG->chat_refresh_room);
        continue;
    }
    $timenow = time();
    $params = array('groupid' => $chatuser->groupid, 'lastid' => $chatlastid, 'lasttime' => $chatlasttime, 'chatid' => $chatuser->chatid);
    $groupselect = $chatuser->groupid ? " AND (groupid=:groupid OR groupid=0) " : "";
    $newcriteria = '';
    if ($chatlastid > 0) {
示例#2
0
 /**
  * Get the latest messages from the given chat session.
  *
  * @param int $chatsid the chat session id
  * @param int $chatlasttime last time messages were retrieved (epoch time)
  * @return array of warnings and the new message id (0 if the message was empty)
  * @since Moodle 3.0
  * @throws moodle_exception
  */
 public static function get_chat_latest_messages($chatsid, $chatlasttime = 0)
 {
     global $DB, $CFG;
     $params = self::validate_parameters(self::get_chat_latest_messages_parameters(), array('chatsid' => $chatsid, 'chatlasttime' => $chatlasttime));
     $warnings = array();
     // Request and permission validation.
     if (!($chatuser = $DB->get_record('chat_users', array('sid' => $params['chatsid'])))) {
         throw new moodle_exception('notlogged', 'chat');
     }
     $chat = $DB->get_record('chat', array('id' => $chatuser->chatid), '*', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($chat, 'chat');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     require_capability('mod/chat:chat', $context);
     $chatlasttime = $params['chatlasttime'];
     if (time() - $chatlasttime > $CFG->chat_old_ping) {
         chat_delete_old_users();
     }
     // Set default chat last time (to not retrieve all the conversations).
     if ($chatlasttime == 0) {
         $chatlasttime = time() - $CFG->chat_old_ping;
     }
     if ($latestmessage = chat_get_latest_message($chatuser->chatid, $chatuser->groupid)) {
         $chatnewlasttime = $latestmessage->timestamp;
     } else {
         $chatnewlasttime = 0;
     }
     $messages = chat_get_latest_messages($chatuser, $chatlasttime);
     $returnedmessages = array();
     foreach ($messages as $message) {
         // FORMAT_MOODLE is mandatory in the chat plugin.
         list($messageformatted, $format) = external_format_text($message->message, FORMAT_MOODLE, $context->id, 'mod_chat', '', 0);
         $returnedmessages[] = array('id' => $message->id, 'userid' => $message->userid, 'system' => (bool) $message->system, 'message' => $messageformatted, 'timestamp' => $message->timestamp);
     }
     // Update our status since we are active in the chat.
     $DB->set_field('chat_users', 'lastping', time(), array('id' => $chatuser->id));
     $result = array();
     $result['messages'] = $returnedmessages;
     $result['chatnewlasttime'] = $chatnewlasttime;
     $result['warnings'] = $warnings;
     return $result;
 }