Exemple #1
0
 /**
  * Test count_unread_popup_notifications.
  */
 public function test_message_count_unread_popup_notifications()
 {
     $sender1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
     $sender2 = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
     $recipient1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test3', 'lastname' => 'User3'));
     $recipient2 = $this->getDataGenerator()->create_user(array('firstname' => 'Test4', 'lastname' => 'User4'));
     $this->send_fake_unread_popup_notification($sender1, $recipient1);
     $this->send_fake_unread_popup_notification($sender1, $recipient1);
     $this->send_fake_unread_popup_notification($sender2, $recipient1);
     $this->send_fake_unread_popup_notification($sender1, $recipient2);
     $this->send_fake_unread_popup_notification($sender2, $recipient2);
     $this->send_fake_unread_popup_notification($sender2, $recipient2);
     $this->send_fake_unread_popup_notification($sender2, $recipient2);
     $this->send_fake_unread_popup_notification($sender2, $recipient2);
     $this->assertEquals(\message_popup\api::count_unread_popup_notifications($recipient1->id), 3);
     $this->assertEquals(\message_popup\api::count_unread_popup_notifications($recipient2->id), 5);
 }
Exemple #2
0
 /**
  * Get unread notification count function.
  *
  * @since  3.2
  * @throws invalid_parameter_exception
  * @throws moodle_exception
  * @param  int      $useridto       the user id who received the message
  * @return external_description
  */
 public static function get_unread_popup_notification_count($useridto)
 {
     global $USER;
     $params = self::validate_parameters(self::get_unread_popup_notification_count_parameters(), array('useridto' => $useridto));
     $context = context_system::instance();
     self::validate_context($context);
     $useridto = $params['useridto'];
     if (!empty($useridto)) {
         if (core_user::is_real_user($useridto)) {
             $userto = core_user::get_user($useridto, '*', MUST_EXIST);
         } else {
             throw new moodle_exception('invaliduser');
         }
     }
     // Check if the current user is the sender/receiver or just a privileged user.
     if ($useridto != $USER->id and !has_capability('moodle/site:readallmessages', $context)) {
         throw new moodle_exception('accessdenied', 'admin');
     }
     return \message_popup\api::count_unread_popup_notifications($useridto);
 }