/**
  * This function tests the has_unread_mail() function.  There is not a lot
  * of mail in my test DB, so the numbers are small, but it should still be
  * sufficient to test.
  *
  */
 public function test_has_unread_mail()
 {
     // Friend has 4 unread mail -> {generic, delete, parent, last}.
     $this->setUser($this->friend);
     $unreadmails = block_course_message_has_unread_mail($this->testcourseid);
     $this->assertEquals($unreadmails, 4);
     // Admin user has no mail.
     $this->setAdminUser();
     $unreadmails = block_course_message_has_unread_mail($this->testcourseid);
     $this->assertEquals($unreadmails, 0);
     // Craig has 1 unread mail -> {child}.
     $this->setUser($this->craig);
     $unreadmails = block_course_message_has_unread_mail($this->testcourseid);
     $this->assertEquals($unreadmails, 1);
 }
 /**
  * This function checks to see if the user has new messages and echos the number of unread
  * records accordingly.  See locallib.php for the block_course_message_has_unread_mail() function.
  *
  */
 private function check_message()
 {
     $totalrecords = block_course_message_has_unread_mail($this->courseid);
     if ($totalrecords > 0) {
         echo "{$totalrecords}";
     } else {
         echo "0";
     }
 }
 /**
  * This method draws the unread mail indicator on the screen and sets the div to display depending on
  * whether or not the user has unread mail using the has_unread_mail() method.
  *
  */
 private function draw_unread_mail_indicator()
 {
     global $CFG, $COURSE, $USER;
     $this->content->footer .= '<div id="bar" class="unreadbar" ';
     $courseid = $COURSE->id;
     if (block_course_message_has_unread_mail($courseid) > 0) {
         $this->content->footer .= 'style="display:show;">';
     } else {
         $this->content->footer .= 'style="display:none;">';
     }
     $this->content->footer .= get_string('unreadbartext', BLOCK_CM_LANG_TABLE) . '</div>';
     // Also store the user's display preference.
     $this->content->footer .= '<input type="hidden" id="displaypreference" msg="' . block_course_message_get_display_preference($USER->id) . '"/>';
 }