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); }
/** * Return contents of course_overview block * * @return stdClass contents of block */ public function get_content() { global $USER, $CFG, $DB; require_once $CFG->dirroot . '/user/profile/lib.php'; if ($this->content !== NULL) { return $this->content; } $config = get_config('block_course_overview'); $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; $content = array(); $updatemynumber = optional_param('mynumber', -1, PARAM_INT); if ($updatemynumber >= 0) { block_course_overview_update_mynumber($updatemynumber); } profile_load_custom_fields($USER); list($sortedcourses, $sitecourses, $totalcourses) = block_course_overview_get_sorted_courses(); $overviews = block_course_overview_get_overviews($sitecourses); $renderer = $this->page->get_renderer('block_course_overview'); if (!empty($config->showwelcomearea)) { require_once $CFG->dirroot . '/message/lib.php'; $msgcount = message_count_unread_messages(); $this->content->text = $renderer->welcome_area($msgcount); } // Number of sites to display. if ($this->page->user_is_editing() && empty($config->forcedefaultmaxcourses)) { $this->content->text .= $renderer->editing_bar_head($totalcourses); } if (empty($sortedcourses)) { $this->content->text .= get_string('nocourses', 'my'); } else { // For each course, build category cache. $this->content->text .= $renderer->course_overview($sortedcourses, $overviews); $this->content->text .= $renderer->hidden_courses($totalcourses - count($sortedcourses)); if ($this->page->user_is_editing() && ajaxenabled()) { $this->page->requires->js_init_call('M.block_course_overview.add_handles'); } } return $this->content; }
$countunreadtotal = 0; //count of unread messages from all users //we're dealing with unread messages early so the contact list will accurately reflect what is read/unread $viewingnewmessages = false; if (!empty($user2)) { //are there any unread messages from $user2 $countunread = message_count_unread_messages($user1, $user2); if ($countunread > 0) { //mark the messages we're going to display as read message_mark_messages_read($user1->id, $user2->id); if ($viewing == MESSAGE_VIEW_UNREAD_MESSAGES) { $viewingnewmessages = true; } } } $countunreadtotal = message_count_unread_messages($user1); if ($currentuser && $countunreadtotal == 0 && $viewing == MESSAGE_VIEW_UNREAD_MESSAGES && empty($user2)) { // If the user has no unread messages, show the search box. // We don't do this when a user is viewing another user's messages as search doesn't // handle user A searching user B's messages properly. $viewing = MESSAGE_VIEW_SEARCH; } $blockedusers = message_get_blocked_users($user1, $user2); $countblocked = count($blockedusers); list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts($user1, $user2); message_print_contact_selector($countunreadtotal, $viewing, $user1, $user2, $blockedusers, $onlinecontacts, $offlinecontacts, $strangers, $showactionlinks, $page); echo html_writer::start_tag('div', array('class' => 'messagearea mdl-align')); if (!empty($user2)) { echo html_writer::start_tag('div', array('class' => 'mdl-left messagehistory')); $visible = 'visible'; $hidden = 'hiddenelement';
/** * Retrieve $user1's contacts (online, offline and strangers) * * @param object $user1 the user whose messages are being viewed * @param object $user2 the user $user1 is talking to. If they are a contact * they will have a variable called 'iscontact' added to their user object * @return array containing 3 arrays. array($onlinecontacts, $offlinecontacts, $strangers) */ function message_get_contacts($user1=null, $user2=null) { global $DB, $CFG, $USER; if (empty($user1)) { $user1 = $USER; } if (!empty($user2)) { $user2->iscontact = false; } $timetoshowusers = 300; //Seconds default if (isset($CFG->block_online_users_timetosee)) { $timetoshowusers = $CFG->block_online_users_timetosee * 60; } // time which a user is counting as being active since $timefrom = time()-$timetoshowusers; // people in our contactlist who are online $onlinecontacts = array(); // people in our contactlist who are offline $offlinecontacts = array(); // people who are not in our contactlist but have sent us a message $strangers = array(); $userfields = user_picture::fields('u', array('lastaccess')); // get all in our contactlist who are not blocked in our contact list // and count messages we have waiting from each of them $contactsql = "SELECT $userfields, COUNT(m.id) AS messagecount FROM {message_contacts} mc JOIN {user} u ON u.id = mc.contactid LEFT OUTER JOIN {message} m ON m.useridfrom = mc.contactid AND m.useridto = ? WHERE u.deleted = 0 AND mc.userid = ? AND mc.blocked = 0 GROUP BY $userfields ORDER BY u.firstname ASC"; $rs = $DB->get_recordset_sql($contactsql, array($user1->id, $user1->id)); foreach ($rs as $rd) { if ($rd->lastaccess >= $timefrom) { // they have been active recently, so are counted online $onlinecontacts[] = $rd; } else { $offlinecontacts[] = $rd; } if (!empty($user2) && $user2->id == $rd->id) { $user2->iscontact = true; } } $rs->close(); // get messages from anyone who isn't in our contact list and count the number // of messages we have from each of them $strangersql = "SELECT $userfields, count(m.id) as messagecount FROM {message} m JOIN {user} u ON u.id = m.useridfrom LEFT OUTER JOIN {message_contacts} mc ON mc.contactid = m.useridfrom AND mc.userid = m.useridto WHERE u.deleted = 0 AND mc.id IS NULL AND m.useridto = ? GROUP BY $userfields ORDER BY u.firstname ASC"; $rs = $DB->get_recordset_sql($strangersql, array($USER->id)); // Add user id as array index, so supportuser and noreply user don't get duplicated (if they are real users). foreach ($rs as $rd) { $strangers[$rd->id] = $rd; } $rs->close(); // Add noreply user and support user to the list, if they don't exist. $supportuser = core_user::get_support_user(); if (!isset($strangers[$supportuser->id])) { $supportuser->messagecount = message_count_unread_messages($USER, $supportuser); if ($supportuser->messagecount > 0) { $strangers[$supportuser->id] = $supportuser; } } $noreplyuser = core_user::get_noreply_user(); if (!isset($strangers[$noreplyuser->id])) { $noreplyuser->messagecount = message_count_unread_messages($USER, $noreplyuser); if ($noreplyuser->messagecount > 0) { $strangers[$noreplyuser->id] = $noreplyuser; } } return array($onlinecontacts, $offlinecontacts, $strangers); }
function render_cocustommenu() { global $CFG, $USER, $DB, $OUTPUT, $PAGE; $systemcontext = context_system::instance(); $usercontext =context_user::instance($USER->id); $content = '<ul class="nav">'; if (has_capability('local/cobaltsettings:manage', $systemcontext)) { $content .="<li class='dropdown'> <a href='#' class='dropdown-toggle' data-toggle='dropdown'>Organization Settings<b class='caret'></b></a> <ul class='dropdown-menu'> <li><a href=$CFG->wwwroot/local/cobaltsettings/category_level.php>CobaltLMS Entity Settings</a></li> <li><a href=$CFG->wwwroot/local/cobaltsettings/school_settings.php>Organization Settings</a></li> <li><a href=$CFG->wwwroot/local/cobaltsettings/gpa_settings.php>GPA/CGPA Settings</a></li> <li><a href=$CFG->wwwroot/local/prefix>Prefix and Suffix</a></li> </ul></li>"; } if (has_capability('local/collegestructure:manage', $systemcontext)) { $content .="<li class='dropdown'> <a href='#' class='dropdown-toggle' data-toggle='dropdown'>Hierarchy<b class='caret'></b></a> <ul class='dropdown-menu'>"; } if (has_capability('local/collegestructure:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/collegestructure>Organizations</a></li>"; } if (has_capability('local/departments:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/departments>Course Libraries</a></li>"; } if (has_capability('local/programs:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/programs>Programs</a></li>"; } if (has_capability('local/semesters:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/semesters>Course Offerings</a></li>"; } if (has_capability('local/curriculum:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/curriculum>Curriculums</a></li>"; } if (has_capability('local/modules:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/modules>Modules</a></li>"; } if (has_capability('local/cobaltcourses:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/cobaltcourses>Courses</a></li>"; } if (has_capability('local/classes:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/classes>Classes Management</a></li>"; } if (has_capability('local/collegestructure:manage', $systemcontext)) { $content .="</ul></li>"; } if (has_capability('local/gradeletter:manage', $systemcontext)) { $content .="<li class='dropdown'> <a href='#' class='dropdown-toggle' data-toggle='dropdown'>Assesments<b class='caret'></b></a> <ul class='dropdown-menu'>"; if (has_capability('local/gradeletter:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/gradeletter>Grade letters</a></li>"; } if (has_capability('local/examtype:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/examtype>Assesment type</a></li>"; } if (has_capability('local/lecturetype:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/lecturetype>Lecture type</a></li>"; } if (has_capability('local/gradesubmission:manage', $systemcontext) && has_capability('local/lecturetype:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/gradesubmission>Grade Submission</a></li>"; } if (has_capability('local/scheduleexam:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/scheduleexam>Assesments</a></li>"; } $content .="</ul></li>"; $content .="<li><a href=$CFG->wwwroot/local/helpmanuals/registrar/index.html target='_blank'>Help Manual</a></li>"; } /* if(has_capability('local/classroomresources:manage', $systemcontext)){ $content .="<li class='dropdown'> <a href='#' class='dropdown-toggle' data-toggle='dropdown'>Resourse Management<b class='caret'></b></a> <ul class='dropdown-menu'>"; $content .="<li><a href=$CFG->wwwroot/local/classroomresources/index.php>Manage Buildings</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/classroomresources/viewfloor.php>Manage Floors</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/classroomresources/viewclassroom.php>Manage Classrooms</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/classroomresources/viewresource.php>Manage Resources</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/classroomresources/view.php>Assign Resources</a></li>"; $content .="</ul></li>"; } */ // $content .='</ul>'; //for instructor starts------------------------------------------------------- if (has_capability('local/classes:submitgrades', $systemcontext)) { if (!is_siteadmin($USER->id)) { $content .="<li><a href=$CFG->wwwroot/local/academiccalendar>Events Calendar</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/classroomresources/timetable.php>Class Schedule</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/scheduleexam>Assesments Schedule</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/helpmanuals/instructor/index.html target='_blank'>Help Manual</a></li>"; } } //for instructor ends------------------------------------------------------- //For students starts----------------------------------------------------- if (isloggedin()) { $context = context_user::instance($USER->id); if (has_capability('local/classes:enrollclass', $context) && !is_siteadmin()) { //----------------------starts of my academics------------------------------ $content .="<li class='dropdown'> <a href='#' class='dropdown-toggle' data-toggle='dropdown'>My Learning<b class='caret'></b></a> <ul class='dropdown-menu'>"; $content .="<li><a href=$CFG->wwwroot/local/courseregistration/mycur.php>Curriculum</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/courseregistration/myclasses.php>Current Classes</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/scheduleexam>Scheduled Assesments</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/myacademics/transcript.php>Transcript</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/academiccalendar>Events Calender</a></li>"; $content .="</ul></li>"; //--------------------------------end of my academics-------------------------------------------------------------------------------- //--------------------------------course registration-------------------------------------------------------------------------------- $content .="<li class='dropdown'> <a href='#' class='dropdown-toggle' data-toggle='dropdown'>Course Registration<b class='caret'></b></a> <ul class='dropdown-menu'>"; $content .="<li><a href=$CFG->wwwroot/local/courseregistration/index.php>Register to Course/Class</a></li>"; $content .="</ul></li>"; //--------------------end of course registration---------------------------------------------------------------------------------------------- //--------------------Requests links---------------------------------------------------------------------------------------------------------- $content .="<li class='dropdown'> <a href='#' class='dropdown-toggle' data-toggle='dropdown'>My Requests<b class='caret'></b></a> <ul class='dropdown-menu'>"; $content .="<li><a href=$CFG->wwwroot/local/request/request_id.php>ID Card</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/request/request_profile.php>Profile Change</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/request/request_transcript.php>Transcript</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/request/course_exem.php>Course Exemption</a></li>"; $content .="</ul></li>"; //-----------------------------end of requests links------------------------------------------------------------------------------------------- $content .="<li><a href=$CFG->wwwroot/local/helpmanuals/student/index.html target='_blank'>Help Manual</a></li>"; } } // for mentor starts------------------------------------------- if (has_capability('local/classes:approvemystudentclasses', $systemcontext) && !is_siteadmin()) { $content .="<li><a href=$CFG->wwwroot/local/mentor>My Students</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/helpmanuals/mentor/index.html target='_blank'>Help Manual</a></li>"; } // mentor ends if (isloggedin() & !isguestuser()) { $msgnotification = message_count_unread_messages($USER); $heirarchy = new hierarchy(); $request = new requests(); $applicationnotice = $heirarchy->count_admissions_from_applicants($USER->id); $requestnotice = $request->all_student_requests_count($USER->id); $courserequestnotice = $heirarchy->count_course_requests_from_students($USER->id); $transcriptnotice = $heirarchy->count_transcript_req_from_student($USER->id); $courseexemptionnotice = $heirarchy->count_coureexe_req_from_student($USER->id); $profilechangenotice = $heirarchy->count_profilechange_req_from_student($USER->id); $idcardnotice = $heirarchy->count_idcard_req_from_student($USER->id); $newappnotice = $heirarchy->count_new_admission_req_from_student($USER->id); $transferappnotice = $heirarchy->count_transfer_admission_req_from_student($USER->id); $totalrequest = $courserequestnotice + $requestnotice; $content .="<li><a href=$CFG->wwwroot/message/ title='Messages' id='messages'> <sup id='msgnotice'>$msgnotification</sup></a></li>"; $context = context_user::instance($USER->id); if (has_capability('local/classes:enrollclass', $context) && !is_siteadmin()) { $allapprovals = $request->all_approved_requests($USER->id); $transcriptapprovals = $heirarchy->count_trasncripts_approve_from_registrar($USER->id); $courseexemptionapproval = $heirarchy->count_courseexe_approve_from_registrar($USER->id); $idcardapproval = $heirarchy->count_idcard_approve_from_registrar($USER->id); $profilechangeapproval = $heirarchy->count_profilechange_approve_from_registrar($USER->id); $content .="<li class='dropdown'> <a href='#' class='dropdown-toggle open' data-toggle='dropdown' id='allrequests' title='Request Approvals'> <sup id='arequests'>$allapprovals</sup></a> <ul class='dropdown-menu'>"; $content .="<li><a href=$CFG->wwwroot/local/request/request_transcript.php>Transcripts($transcriptapprovals)</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/request/course_exem.php>Coures Exemptions($courseexemptionapproval)</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/request/request_id.php>ID Card($idcardapproval)</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/request/request_profile.php>Profile Change($profilechangeapproval)</a></li>"; $content .="</ul></li>"; } if (has_capability('local/collegestructure:manage', $systemcontext) && !is_siteadmin($USER->id)) { $content .="<li class='dropdown'> <a href='#' class='dropdown-toggle' data-toggle='dropdown' id='apprequests' title='Applicant Requests'> <sup id='requests'>$applicationnotice</sup></a> <ul class='dropdown-menu'>"; $content .="<li><a href=$CFG->wwwroot/local/admission/viewapplicant.php>New Application($newappnotice)</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/admission/transferapplicant.php>Transfer Application($transferappnotice)</a></li>"; $content .="</ul></li>"; } if ((has_capability('local/collegestructure:manage', $systemcontext) || has_capability('local/classes:approvemystudentclasses', $systemcontext)) && !is_siteadmin($USER->id)) { $content .="<li class='dropdown'> <a href='#' class='dropdown-toggle' data-toggle='dropdown' id='allrequests' title='Requests'> <sup id='arequests'>$totalrequest</sup></a> <ul class='dropdown-menu'>"; } if ((has_capability('local/collegestructure:manage', $systemcontext) || has_capability('local/classes:approvemystudentclasses', $systemcontext)) && !is_siteadmin($USER->id)) { $content .="<li><a href=$CFG->wwwroot/local/courseregistration/registrar.php?current=pending>Approve Course (<b class='counts'>$courserequestnotice </b>)</a></li>"; } if (has_capability('local/collegestructure:manage', $systemcontext) && !is_siteadmin($USER->id)) { $content .="<li><a href=$CFG->wwwroot/local/request/approval_transcript.php>Approve Transcripts (<b class='counts'>$transcriptnotice</b>)</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/request/approveexem.php>Approve Coures Exemptions (<b class='counts'>$courseexemptionnotice</b>)</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/request/approval_id.php>Approve ID Card (<b class='counts'>$idcardnotice</b>)</a></li>"; $content .="<li><a href=$CFG->wwwroot/local/request/approval_profile.php>Approve Profile Change (<b class='counts'>$profilechangenotice</b>)</a></li>"; } if ((has_capability('local/collegestructure:manage', $systemcontext) || has_capability('local/classes:approvemystudentclasses', $systemcontext)) && !is_siteadmin($USER->id)) { $content .="</ul></li>"; } if (has_capability('local/academiccalendar:manage', $systemcontext)) { $content .="<li class='dropdown'> <a href='#' class='dropdown-toggle' data-toggle='dropdown' id='quicklinks'><img src= $CFG->wwwroot/theme/colms/pix/quicklinks.png class='dropdown-toggle' data-toggle='dropdown'/><b class='caret'></b></a> <ul class='dropdown-menu'>"; } if (has_capability('local/academiccalendar:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/academiccalendar>Events Calendar</a></li>"; } if (has_capability('local/admission:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/admission/viewapplicant.php>Online Registrations</a></li>"; } if (has_capability('local/courseregistration:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/courseregistration/registrar.php?current=pending>Course Enrollments</a></li>"; } if (has_capability('local/courseregistration:manage', $systemcontext)) { $content .="<li><a href=$CFG->wwwroot/local/evaluations/index.php>Evaluations</a></li>"; } if (has_capability('local/academiccalendar:manage', $systemcontext)) { $content .="</ul></li>"; } } $content .="</ul>"; //For students ends------------------------------------------------------ return $content; }
/** * Test message_count_unread_messages. */ public function test_message_count_unread_messages() { // Create users to send and receive message. $userfrom1 = $this->getDataGenerator()->create_user(); $userfrom2 = $this->getDataGenerator()->create_user(); $userto = $this->getDataGenerator()->create_user(); $this->assertEquals(0, message_count_unread_messages($userto)); // Send fake messages. $this->send_fake_message($userfrom1, $userto); $this->send_fake_message($userfrom2, $userto); $this->assertEquals(2, message_count_unread_messages($userto)); $this->assertEquals(1, message_count_unread_messages($userto, $userfrom1)); }
public function welcome_area() { global $OUTPUT, $USER; $output = $OUTPUT->box_start('welcome_area'); $picture = $OUTPUT->user_picture($USER, array('size' => 75, 'class' => 'welcome_userpicture')); $output .= html_writer::tag('div', $picture, array('class' => 'profilepicture')); $output .= $OUTPUT->box_start('welcome_message'); $output .= $OUTPUT->heading(get_string('welcome', 'block_my_course_overview', $USER->firstname)); //messages $count = message_count_unread_messages($USER); $plural = 's'; if ($count > 0) { $output .= get_string('you_have_messages', 'block_my_course_overview', $count); } else { $output .= get_string('you_have_no_messages', 'block_my_course_overview'); if ($count == 1) { $plural = ''; } } $output .= html_writer::link(new moodle_url('/message/index.php'), get_string('message' . $plural, 'block_my_course_overview')); $output .= $OUTPUT->box_end(); $output .= $OUTPUT->box('', 'flush'); $output .= $OUTPUT->box_end(); return $output; }