コード例 #1
0
 /**
  * @dataProvider chat_format_message_manually_provider
  */
 public function test_chat_format_message_manually($messagetext, $system, $willreturn, $expecttext, $refreshusers, $expectbeep)
 {
     $this->resetAfterTest();
     $course = $this->getDataGenerator()->create_course();
     $currentuser = $this->getDataGenerator()->create_user();
     $this->setUser($currentuser);
     $otheruser = $this->getDataGenerator()->create_user();
     // Replace the message texts.
     // These can't be done in the provider because it runs before the
     // test starts.
     $messagetext = str_replace('__CURRENTUSER__', $currentuser->id, $messagetext);
     $messagetext = str_replace('__OTHERUSER__', $otheruser->id, $messagetext);
     $message = (object) ['message' => $messagetext, 'timestamp' => time(), 'system' => $system];
     $result = chat_format_message_manually($message, $course->id, $currentuser, $currentuser);
     if (!$willreturn) {
         $this->assertFalse($result);
     } else {
         $this->assertNotFalse($result);
         if (!empty($expecttext)) {
             $expecttext = str_replace('__CURRENTUSER__', fullname($currentuser), $expecttext);
             $expecttext = str_replace('__CURRENTUSER_FIRST__', $currentuser->firstname, $expecttext);
             $this->assertRegexp($expecttext, $result->text);
         }
         $this->assertEquals($refreshusers, $result->refreshusers);
         $this->assertEquals($expectbeep, $result->beep);
     }
 }
コード例 #2
0
ファイル: lib.php プロジェクト: ajv/Offline-Caching
/**
 * @global object
 * @param object $message
 * @param int $courseid
 * @param object $currentuser
 * @param string $chat_lastrow
 * @return bool|string Returns HTML or false
 */
function chat_format_message($message, $courseid, $currentuser, $chat_lastrow = NULL)
{
    /// Given a message object full of information, this function
    /// formats it appropriately into text and html, then
    /// returns the formatted data.
    global $DB;
    static $users;
    // Cache user lookups
    if (isset($users[$message->userid])) {
        $user = $users[$message->userid];
    } else {
        if ($user = $DB->get_record('user', array('id' => $message->userid), 'id,picture,firstname,lastname')) {
            $users[$message->userid] = $user;
        } else {
            return NULL;
        }
    }
    return chat_format_message_manually($message, $courseid, $user, $currentuser, $chat_lastrow);
}
コード例 #3
0
ファイル: lib.php プロジェクト: Gavinthisisit/Moodle
/**
 * Given a message object this function formats it appropriately into text and html then returns the formatted data
 * @global object
 * @param object $message
 * @param int $courseid
 * @param object $currentuser
 * @param string $chatlastrow
 * @return bool|string Returns HTML or false
 */
function chat_format_message($message, $courseid, $currentuser, $chatlastrow = null)
{
    global $DB;
    static $users;
    // Cache user lookups.
    if (isset($users[$message->userid])) {
        $user = $users[$message->userid];
    } else {
        if ($user = $DB->get_record('user', array('id' => $message->userid), user_picture::fields())) {
            $users[$message->userid] = $user;
        } else {
            return null;
        }
    }
    return chat_format_message_manually($message, $courseid, $user, $currentuser, $chatlastrow);
}
コード例 #4
0
ファイル: chatd.php プロジェクト: EmmanuelYupit/educursos
 function message_broadcast($message, $sender)
 {
     if (empty($this->conn_sets)) {
         return true;
     }
     $now = time();
     // First of all, mark this chatroom as having had activity now
     $this->chatrooms[$message->chatid]['lastactivity'] = $now;
     foreach ($this->sets_info as $sessionid => $info) {
         // We need to get handles from users that are in the same chatroom, same group
         if ($info['chatid'] == $message->chatid && ($info['groupid'] == $message->groupid || $message->groupid == 0)) {
             // Simply give them the message
             $output = chat_format_message_manually($message, $info['courseid'], $sender, $info['user']);
             $this->trace('Delivering message "' . $output->text . '" to ' . $this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL]);
             if ($output->beep) {
                 $this->write_data($this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL], '<embed src="' . $this->_beepsoundsrc . '" autostart="true" hidden="true" />');
             }
             if ($info['quirks'] & QUIRK_CHUNK_UPDATE) {
                 $output->html .= $GLOBALS['CHAT_DUMMY_DATA'];
                 $output->html .= $GLOBALS['CHAT_DUMMY_DATA'];
                 $output->html .= $GLOBALS['CHAT_DUMMY_DATA'];
             }
             if (!$this->write_data($this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL], $output->html)) {
                 $this->disconnect_session($sessionid);
             }
             //$this->trace('Sent to UID '.$this->sets_info[$sessionid]['userid'].': '.$message->text_);
         }
     }
 }