예제 #1
0
 /**
  * Triggered when user sends chat message
  *
  * @param \core\event\base $event
  */
 public static function process_chat_message_event(\mod_chat\event\message_sent $event)
 {
     // public static function process_chat_message_event(\core\event\base $event){
     global $CFG, $USER, $COURSE, $DB;
     require_once $CFG->dirroot . "/local/morph/classes/logger/Logger.php";
     require_once $CFG->dirroot . "/local/morph/classes/alerts_controller.php";
     require_once $CFG->dirroot . "/mod/project/lib.php";
     require_once $CFG->dirroot . "/mod/project/classes/event/chat_message_sent.php";
     require_once $CFG->dirroot . "/mod/chat/locallib.php";
     $log = new moodle\local\morph\Logger(array("prefix" => 'chat_'));
     $message = $event->get_record_snapshot('chat_messages', $event->objectid);
     $log->debug("MESSAGE RECORDSNAPSHOT:" . json_encode($message));
     $chatuser = $DB->get_record('chat_users', array('chatid' => $message->chatid, 'userid' => $USER->id, 'groupid' => $message->groupid));
     $log->debug("CHAT USER:"******" CONFIG:" . json_encode($config));
     $projectconfig = json_decode(json_encode($config), true);
     // $projectconfig=get_object_wars($config);
     $log->debug("PROJECT CONFIG:" . json_encode($projectconfig));
     $log->debug("SENDING NEW CHAT EVENT:" . json_encode($params));
     $event = $eventclass::create($params);
     $event->add_morph_record_snapshot('chat_messages', $message);
     $event->add_morph_other_data('messagelength', strlen($message->message));
     $event->add_morph_other_data('config', $projectconfig);
     $event->trigger();
     ///Finished triggering new event
 }
예제 #2
0
/**
 * Send a message on the chat.
 *
 * @param object $chatuser The chat user record.
 * @param string $messagetext The message to be sent.
 * @param bool $system False for non-system messages, true for system messages.
 * @param object $cm The course module object, pass it to save a database query when we trigger the event.
 * @return int The message ID.
 * @since Moodle 2.6
 */
function chat_send_chatmessage($chatuser, $messagetext, $system = false, $cm = null)
{
    global $DB;
    $message = new stdClass();
    $message->chatid = $chatuser->chatid;
    $message->userid = $chatuser->userid;
    $message->groupid = $chatuser->groupid;
    $message->message = $messagetext;
    $message->system = $system ? 1 : 0;
    $message->timestamp = time();
    $messageid = $DB->insert_record('chat_messages', $message);
    $DB->insert_record('chat_messages_current', $message);
    $message->id = $messageid;
    if (!$system) {
        if (empty($cm)) {
            $cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $chatuser->course);
        }
        $params = array('context' => context_module::instance($cm->id), 'objectid' => $message->id, 'relateduserid' => $chatuser->userid);
        $event = \mod_chat\event\message_sent::create($params);
        $event->add_record_snapshot('chat_messages', $message);
        $event->trigger();
    }
    return $message->id;
}