Пример #1
0
/**
 * Print the user's recent notifications
 * @param object $user1 the current user
 */
function message_print_recent_notifications($user=null) {
    global $USER;

    echo html_writer::start_tag('p', array('class' => 'heading'));
    echo get_string('mostrecentnotifications', 'message');
    echo html_writer::end_tag('p');

    if (empty($user)) {
        $user = $USER;
    }

    $notifications = message_get_recent_notifications($user);

    $showicontext = false;
    $showotheruser = false;
    message_print_recent_messages_table($notifications, $user, $showotheruser, $showicontext);
}
Пример #2
0
 /**
  * Test message_get_recent_notifications.
  */
 public function test_message_get_recent_notifications()
 {
     global $DB, $USER;
     // Set this user as the admin.
     $this->setAdminUser();
     // Create a user to send messages from.
     $user1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'user1'));
     // Add two messages - will mark them as notifications later.
     $m1 = message_post_message($user1, $USER, 'Message 1', FORMAT_PLAIN);
     $m2 = message_post_message($user1, $USER, 'Message 2', FORMAT_PLAIN);
     // Mark the second message as a notification.
     $updatemessage = new stdClass();
     $updatemessage->id = $m2;
     $updatemessage->notification = 1;
     $DB->update_record('message_read', $updatemessage);
     // Mark the first message as a notification and change the timecreated to 0.
     $updatemessage->id = $m1;
     $updatemessage->notification = 1;
     $updatemessage->timecreated = 0;
     $DB->update_record('message_read', $updatemessage);
     $notifications = message_get_recent_notifications($USER);
     // Get the messages.
     $firstmessage = array_shift($notifications);
     $secondmessage = array_shift($notifications);
     // Confirm that we have received the notifications with the maximum timecreated, rather than the max id.
     $this->assertEquals('Message 2', $firstmessage->smallmessage);
     $this->assertEquals('Message 1', $secondmessage->smallmessage);
 }