예제 #1
0
파일: api_test.php 프로젝트: dg711/moodle
 public function test_mark_all_read_for_user_touser_with_type()
 {
     $sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
     $recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
     $this->send_fake_message($sender, $recipient, 'Notification', 1);
     $this->send_fake_message($sender, $recipient, 'Notification', 1);
     $this->send_fake_message($sender, $recipient, 'Notification', 1);
     $this->send_fake_message($sender, $recipient);
     $this->send_fake_message($sender, $recipient);
     $this->send_fake_message($sender, $recipient);
     \core_message\api::mark_all_read_for_user($recipient->id, 0, MESSAGE_TYPE_NOTIFICATION);
     $this->assertEquals(message_count_unread_messages($recipient), 3);
     \core_message\api::mark_all_read_for_user($recipient->id, 0, MESSAGE_TYPE_MESSAGE);
     $this->assertEquals(message_count_unread_messages($recipient), 0);
 }
예제 #2
0
/**
 * marks ALL messages being sent from $fromuserid to $touserid as read
 *
 * @deprecated since Moodle 3.2
 * @param int $touserid the id of the message recipient
 * @param int $fromuserid the id of the message sender
 * @return void
 */
function message_mark_messages_read($touserid, $fromuserid)
{
    debugging('message_mark_messages_read() is deprecated and is no longer used, please use
        \\core_message\\api::mark_all_read_for_user() instead.', DEBUG_DEVELOPER);
    \core_message\api::mark_all_read_for_user($touserid, $fromuserid);
}
예제 #3
0
 /**
  * Mark all notifications as read function.
  *
  * @since  3.2
  * @throws invalid_parameter_exception
  * @throws moodle_exception
  * @param  int      $useridto       the user id who received the message
  * @param  int      $useridfrom     the user id who send the message. -10 or -20 for no-reply or support user
  * @return external_description
  */
 public static function mark_all_messages_as_read($useridto, $useridfrom)
 {
     global $USER, $CFG;
     // Check if messaging is enabled.
     if (empty($CFG->messaging)) {
         throw new moodle_exception('disabled', 'message');
     }
     $params = self::validate_parameters(self::mark_all_messages_as_read_parameters(), array('useridto' => $useridto, 'useridfrom' => $useridfrom));
     $context = context_system::instance();
     self::validate_context($context);
     $useridto = $params['useridto'];
     $useridfrom = $params['useridfrom'];
     if (!empty($useridto)) {
         if (core_user::is_real_user($useridto)) {
             $userto = core_user::get_user($useridto, '*', MUST_EXIST);
         } else {
             throw new moodle_exception('invaliduser');
         }
     }
     if (!empty($useridfrom)) {
         // We use get_user here because the from user can be the noreply or support user.
         $userfrom = core_user::get_user($useridfrom, '*', MUST_EXIST);
     }
     // Check if the current user is the sender/receiver or just a privileged user.
     if ($useridto != $USER->id and $useridfrom != $USER->id and !has_capability('moodle/site:deleteanymessage', $context)) {
         throw new moodle_exception('accessdenied', 'admin');
     }
     \core_message\api::mark_all_read_for_user($useridto, $useridfrom, MESSAGE_TYPE_MESSAGE);
     return true;
 }
예제 #4
0
파일: index.php 프로젝트: dg711/moodle
    $user2->id = null;
    if (!empty($conversations)) {
        $contact = reset($conversations);
        $user2->id = $contact->userid;
    }
} else {
    // The user has specifically requested to see a conversation. Add the flag to
    // the context so that we can render the messaging app appropriately - this is
    // used for smaller screens as it allows the UI to be responsive.
    $requestedconversation = true;
}
// Mark the conversation as read.
if (!empty($user2->id)) {
    if ($currentuser && isset($conversations[$user2->id])) {
        // Mark the conversation we are loading as read.
        \core_message\api::mark_all_read_for_user($user1->id, $user2->id);
        // Ensure the UI knows it's read as well.
        $conversations[$user2->id]->isread = 1;
    }
    $messages = \core_message\api::get_messages($user1->id, $user2->id, 0, 20, 'timecreated DESC');
}
$messagearea = new \core_message\output\messagearea\message_area($user1->id, $user2->id, $conversations, $messages, $requestedconversation);
// Now the page contents.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('messages', 'message'));
// Display a message that the user is viewing someone else's messages.
if (!$currentuser) {
    $notify = new \core\output\notification(get_string('viewinganotherusersmessagearea', 'message'), \core\output\notification::NOTIFY_WARNING);
    echo $OUTPUT->render($notify);
}
echo $renderer->render($messagearea);