当前位置: 首页>>代码示例>>PHP>>正文


PHP chat_send_chatmessage函数代码示例

本文整理汇总了PHP中chat_send_chatmessage函数的典型用法代码示例。如果您正苦于以下问题:PHP chat_send_chatmessage函数的具体用法?PHP chat_send_chatmessage怎么用?PHP chat_send_chatmessage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了chat_send_chatmessage函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_message_sent

 public function test_message_sent()
 {
     global $DB;
     $this->resetAfterTest();
     $this->setAdminUser();
     $course = $this->getDataGenerator()->create_course();
     $user1 = $this->getDataGenerator()->create_user();
     $user2 = $this->getDataGenerator()->create_user();
     $chat = $this->getDataGenerator()->create_module('chat', array('course' => $course->id));
     $cm = $DB->get_record('course_modules', array('id' => $chat->cmid));
     // Logging in first user to the chat.
     $this->setUser($user1->id);
     $sid1 = chat_login_user($chat->id, 'ajax', 0, $course);
     // Logging in second user to the chat.
     $this->setUser($user2->id);
     $sid2 = chat_login_user($chat->id, 'ajax', 0, $course);
     // Getting the chatuser record.
     $chatuser1 = $DB->get_record('chat_users', array('sid' => $sid1));
     $chatuser2 = $DB->get_record('chat_users', array('sid' => $sid2));
     $sink = $this->redirectEvents();
     // Send a messaging from the first user. We pass the CM to chat_send_chatmessage() this time.
     // This ensures that the event triggered when sending a message is filled with the correct information.
     $this->setUser($user1->id);
     $messageid = chat_send_chatmessage($chatuser1, 'Hello!', false, $cm);
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     $this->assertInstanceOf('\\mod_chat\\event\\message_sent', $event);
     $this->assertEquals($messageid, $event->objectid);
     $this->assertEquals($user1->id, $event->relateduserid);
     $this->assertEquals($user1->id, $event->userid);
     $expected = array($course->id, 'chat', 'talk', "view.php?id={$cm->id}", $chat->id, $cm->id, $user1->id);
     $this->assertEventLegacyLogData($expected, $event);
     // Send a messaging from the first user. We DO NOT pass the CM to chat_send_chatmessage() this time.
     // This ensures that the event triggered when sending a message is filled with the correct information.
     $sink->clear();
     $this->setUser($user2->id);
     $messageid = chat_send_chatmessage($chatuser2, 'Hello!');
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     $this->assertInstanceOf('\\mod_chat\\event\\message_sent', $event);
     $this->assertEquals($messageid, $event->objectid);
     $this->assertEquals($user2->id, $event->relateduserid);
     $this->assertEquals($user2->id, $event->userid);
     $expected = array($course->id, 'chat', 'talk', "view.php?id={$cm->id}", $chat->id, $cm->id, $user2->id);
     $this->assertEventLegacyLogData($expected, $event);
     // Sending a message from the system should not trigger any event.
     $sink->clear();
     $this->setAdminUser();
     chat_send_chatmessage($chatuser1, 'enter', true);
     $this->assertEquals(0, $sink->count());
     $sink->close();
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:54,代码来源:events_test.php

示例2: chat_delete_old_users

/**
 * Delete the old and in the way
 *
 * @global object
 * @global object
 */
function chat_delete_old_users()
{
    // Delete the old and in the way.
    global $CFG, $DB;
    $timeold = time() - $CFG->chat_old_ping;
    $timeoldext = time() - $CFG->chat_old_ping * 10;
    // JSless gui_basic needs much longer timeouts.
    $query = "(version<>'basic' AND lastping<?) OR (version='basic' AND lastping<?)";
    $params = array($timeold, $timeoldext);
    if ($oldusers = $DB->get_records_select('chat_users', $query, $params)) {
        $DB->delete_records_select('chat_users', $query, $params);
        foreach ($oldusers as $olduser) {
            chat_send_chatmessage($olduser, 'exit', true);
        }
    }
}
开发者ID:Gavinthisisit,项目名称:Moodle,代码行数:22,代码来源:lib.php

示例3: disconnect_session

 function disconnect_session($sessionid)
 {
     global $DB;
     $info = $this->sets_info[$sessionid];
     $DB->delete_records('chat_users', array('sid' => $sessionid));
     $msg = new stdClass();
     $msg->chatid = $info['chatid'];
     $msg->userid = $info['userid'];
     $msg->groupid = $info['groupid'];
     $msg->system = 1;
     $msg->message = 'exit';
     $msg->timestamp = time();
     $this->trace('User has disconnected, destroying uid ' . $info['userid'] . ' with SID ' . $sessionid, E_USER_WARNING);
     chat_send_chatmessage($info['chatuser'], $msg->message, true);
     // *************************** IMPORTANT
     //
     // Kill him BEFORE broadcasting, otherwise we 'll get infinite recursion!
     //
     // **********************************************************************
     $latesender = $info['user'];
     $this->dismiss_set($sessionid);
     $this->message_broadcast($msg, $latesender);
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:23,代码来源:chatd.php

示例4: send_chat_message

 /**
  * Send a message on the given chat session.
  *
  * @param int $chatsid the chat session id
  * @param string $messagetext the message text
  * @param string $beepid the beep message id
  * @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 send_chat_message($chatsid, $messagetext, $beepid = '')
 {
     global $DB;
     $params = self::validate_parameters(self::send_chat_message_parameters(), array('chatsid' => $chatsid, 'messagetext' => $messagetext, 'beepid' => $beepid));
     $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);
     $chatmessage = clean_text($params['messagetext'], FORMAT_MOODLE);
     if (!empty($params['beepid'])) {
         $chatmessage = 'beep ' . $params['beepid'];
     }
     if (!empty($chatmessage)) {
         // Send the message.
         $messageid = chat_send_chatmessage($chatuser, $chatmessage, 0, $cm);
         // Update ping time.
         $chatuser->lastmessageping = time() - 2;
         $DB->update_record('chat_users', $chatuser);
     } else {
         $messageid = 0;
     }
     $result = array();
     $result['messageid'] = $messageid;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:42,代码来源:external.php

示例5: array

    $SESSION->chatprefs = array();
}
if (!isset($SESSION->chatprefs[$chat->id])) {
    $SESSION->chatprefs[$chat->id] = array();
    $SESSION->chatprefs[$chat->id]['chatentered'] = time();
}
$chatentered = $SESSION->chatprefs[$chat->id]['chatentered'];
$refreshedmessage = '';
if (!empty($refresh) and data_submitted()) {
    $refreshedmessage = $message;
    chat_delete_old_users();
} else {
    if (empty($refresh) and data_submitted() and confirm_sesskey()) {
        if ($message != '') {
            $chatuser = $DB->get_record('chat_users', array('sid' => $chat_sid));
            chat_send_chatmessage($chatuser, $message, 0, $cm);
            $DB->set_field('chat_users', 'lastmessageping', time(), array('sid' => $chat_sid));
        }
        chat_delete_old_users();
        $url = new moodle_url('/mod/chat/gui_basic/index.php', array('id' => $id, 'newonly' => $newonly, 'last' => $last));
        redirect($url);
    }
}
$PAGE->set_title("{$strchat}: {$course->shortname}: " . format_string($chat->name, true) . "{$groupname}");
echo $OUTPUT->header();
echo $OUTPUT->container_start(null, 'page-mod-chat-gui_basic');
echo $OUTPUT->heading(format_string($course->shortname), 1);
echo $OUTPUT->heading(format_string($chat->name), 2);
echo $OUTPUT->heading(get_string('participants'), 3);
echo $OUTPUT->box_start('generalbox', 'participants');
echo '<ul>';
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:31,代码来源:index.php

示例6: print_error

}
//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, 'deleted' => 0, 'suspended' => 0)))) {
    // no optimisation here, it would break again in future!
    print_error('invaliduser');
}
\core\session\manager::set_user($user);
$PAGE->set_pagelayout('embedded');
//Setup course, lang and theme
$PAGE->set_course($course);
$courseid = $chatuser->course;
if (!($cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $courseid))) {
    print_error('invalidcoursemodule');
}
if ($beep) {
    chat_send_chatmessage($chatuser, "beep {$beep}", 0, $cm);
    $chatuser->lastmessageping = time();
    // A beep is a ping  ;-)
}
$chatuser->lastping = time();
$DB->set_field('chat_users', 'lastping', $chatuser->lastping, array('id' => $chatuser->id));
$refreshurl = "users.php?chat_sid={$chat_sid}";
/// Get list of users
if (!($chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid))) {
    print_error('errornousers', 'chat');
}
$uidles = array();
foreach ($chatusers as $chatuser) {
    $uidles[] = $chatuser->id;
}
$module = array('name' => 'mod_chat_header', 'fullpath' => '/mod/chat/gui_header_js/module.js', 'requires' => array('node'));
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:31,代码来源:users.php

示例7: print_error

}
\core\session\manager::set_user($user);

$PAGE->set_pagelayout('embedded');

// Setup course, lang and theme.
$PAGE->set_course($course);

$courseid = $chatuser->course;

if (!$cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $courseid)) {
    print_error('invalidcoursemodule');
}

if ($beep) {
    chat_send_chatmessage($chatuser, "beep $beep", 0, $cm);
    $chatuser->lastmessageping = time(); // A beep is a ping.
}

$chatuser->lastping = time();
$DB->set_field('chat_users', 'lastping', $chatuser->lastping, array('id' => $chatuser->id));

$refreshurl = "users.php?chat_sid=$chatsid";

// Get list of users.

if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid)) {
    print_error('errornousers', 'chat');
}

$uidles = Array();
开发者ID:ruddj,项目名称:moodle,代码行数:31,代码来源:users.php


注:本文中的chat_send_chatmessage函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。