function local_mail_extend_navigation($root) { global $CFG, $COURSE, $PAGE, $SESSION, $SITE, $USER; if (!get_config('local_mail', 'version')) { return; } $courses = local_mail_get_my_courses(); $count = local_mail_message::count_menu($USER->id); // My mail $text = get_string('mymail', 'local_mail'); if (!empty($count->inbox)) { $text .= ' (' . $count->inbox . ')'; } $node = navigation_node::create($text, null, navigation_node::TYPE_ROOTNODE); if (!empty($count->inbox)) { $node->add_class('local_mail_new_messages'); } $child = $root->add_node($node, 'mycourses'); $child->add_class('mail_root'); // Compose $text = get_string('compose', 'local_mail'); $url = new moodle_url('/local/mail/compose.php'); $urlrecipients = new moodle_url('/local/mail/recipients.php'); if ($PAGE->url->compare($url, URL_MATCH_BASE) or $PAGE->url->compare($urlrecipients, URL_MATCH_BASE)) { $url->param('m', $PAGE->url->param('m')); } else { $url = new moodle_url('/local/mail/create.php'); if ($COURSE->id != $SITE->id) { $url->param('c', $COURSE->id); $url->param('sesskey', sesskey()); } } $node->add(s($text), $url); // Inbox $text = get_string('inbox', 'local_mail'); if (!empty($count->inbox)) { $text .= ' (' . $count->inbox . ')'; } $url = new moodle_url('/local/mail/view.php', array('t' => 'inbox')); $child = $node->add(s($text), $url); $child->add_class('mail_inbox'); // Starred $text = get_string('starredmail', 'local_mail'); $url = new moodle_url('/local/mail/view.php', array('t' => 'starred')); $node->add(s($text), $url); // Drafts $text = get_string('drafts', 'local_mail'); if (!empty($count->drafts)) { $text .= ' (' . $count->drafts . ')'; } $url = new moodle_url('/local/mail/view.php', array('t' => 'drafts')); $child = $node->add(s($text), $url); $child->add_class('mail_drafts'); // Sent $text = get_string('sentmail', 'local_mail'); $url = new moodle_url('/local/mail/view.php', array('t' => 'sent')); $node->add(s($text), $url); // Courses if ($courses) { $text = get_string('courses', 'local_mail'); $nodecourses = $node->add($text, null, navigation_node::TYPE_CONTAINER); foreach ($courses as $course) { $text = $course->shortname; if (!empty($count->courses[$course->id])) { $text .= ' (' . $count->courses[$course->id] . ')'; } $params = array('t' => 'course', 'c' => $course->id); $url = new moodle_url('/local/mail/view.php', $params); $child = $nodecourses->add(s($text), $url); $child->hidden = !$course->visible; $child->add_class('mail_course_'.$course->id); } } // Labels $labels = local_mail_label::fetch_user($USER->id); if ($labels) { $text = get_string('labels', 'local_mail'); $nodelabels = $node->add($text, null, navigation_node::TYPE_CONTAINER); foreach ($labels as $label) { $text = $label->name(); if (!empty($count->labels[$label->id()])) { $text .= ' (' . $count->labels[$label->id()] . ')'; } $params = array('t' => 'label', 'l' => $label->id()); $url = new moodle_url('/local/mail/view.php', $params); $child = $nodelabels->add(s($text), $url); $child->add_class('mail_label_'.$label->id()); } } // Trash $text = get_string('trash', 'local_mail'); $url = new moodle_url('/local/mail/view.php', array('t' => 'trash')); $node->add(s($text), $url); // Preferences $text = get_string('preferences'); $url = new moodle_url('/local/mail/preferences.php'); $node->add(s($text), $url); // User profile if (empty($CFG->messaging) and $PAGE->url->compare(new moodle_url('/user/view.php'), URL_MATCH_BASE)) { $userid = optional_param('id', false, PARAM_INT); if (local_mail_valid_recipient($userid)) { $vars = array('course' => $COURSE->id, 'recipient' => $userid); $PAGE->requires->string_for_js('sendmessage', 'local_mail'); $PAGE->requires->js_init_code('M.local_mail = ' . json_encode($vars)); $PAGE->requires->js('/local/mail/user.js'); } } // Users list if (empty($CFG->messaging) and $PAGE->url->compare(new moodle_url('/user/index.php'), URL_MATCH_BASE)) { $userid = optional_param('id', false, PARAM_INT); $vars = array('course' => $COURSE->id); $PAGE->requires->string_for_js('choosedots', 'moodle'); $PAGE->requires->strings_for_js(array( 'bulkmessage', 'to', 'cc', 'bcc', ), 'local_mail'); $PAGE->requires->js_init_code('M.local_mail = ' . json_encode($vars)); $PAGE->requires->js('/local/mail/users.js'); } // Block progress if ($PAGE->url->compare(new moodle_url('/blocks/progress/overview.php'), URL_MATCH_BASE)) { $userid = optional_param('id', false, PARAM_INT); $vars = array('course' => $COURSE->id); $PAGE->requires->string_for_js('choosedots', 'moodle'); $PAGE->requires->strings_for_js(array( 'bulkmessage', 'to', 'cc', 'bcc', ), 'local_mail'); $PAGE->requires->js_init_code('M.local_mail = ' . json_encode($vars)); $PAGE->requires->js('/local/mail/users.js'); } }
public function test_fetch_menu() { $label1 = local_mail_label::create(201, 'label1'); $label2 = local_mail_label::create(201, 'label2'); $message1 = local_mail_message::create(201, 101); $message2 = local_mail_message::create(202, 101); $message2->add_recipient('to', 201); $message2->send(); $message2->set_unread(201, false); $message2->add_label($label1); $message2->add_label($label2); $message3 = local_mail_message::create(201, 102); $message3->add_recipient('to', 202); $message3->send(); $message4 = local_mail_message::create(202, 101); $message4->add_recipient('to', 201); $message4->send(); $message4->add_label($label1); $message4->set_starred(201, true); $result = local_mail_message::count_menu(201); $this->assertNotEmpty($result); $this->assertEquals(1, $result->inbox); $this->assertEquals(1, $result->drafts); $this->assertEquals(array(101 => 1), $result->courses); $this->assertEquals(array($label1->id() => 1), $result->labels); }
function local_mail_extends_navigation($root) { global $CFG, $COURSE, $PAGE, $SESSION, $SITE, $USER, $DB; //Aqui $consulta = "SELECT count(*) as contador\n\t\t FROM " . $CFG->prefix . "course AS c JOIN " . $CFG->prefix . "context AS ctx ON c.id = ctx.instanceid JOIN " . $CFG->prefix . "role_assignments AS ra ON ra.contextid = ctx.id JOIN " . $CFG->prefix . "user AS u ON u.id = ra.userid WHERE (c.id = " . $COURSE->id . " AND u.id = " . $USER->id . " AND ra.roleid = 5) OR ( " . $USER->id . " = 2) OR (u.id =" . $USER->id . " AND ra.roleid = 5)"; $bandera = 0; if ($courses = $DB->get_records_sql($consulta)) { foreach ($courses as $course) { if ($course->contador >= 1) { $bandera = 1; } else { $bandera = 0; } } } if ($bandera == 1) { if (!get_config('local_mail', 'version')) { return; } $courses = local_mail_get_my_courses(); $count = local_mail_message::count_menu($USER->id); // My mail $text = get_string('mymail', 'local_mail'); if (!empty($count->inbox)) { $text .= ' (' . $count->inbox . ')'; } $node = navigation_node::create($text, null, navigation_node::TYPE_ROOTNODE); if (!empty($count->inbox)) { $node->add_class('local_mail_new_messages'); } $child = $root->add_node($node, 'mycourses'); $child->add_class('mail_root'); // Compose $text = get_string('compose', 'local_mail'); $url = new moodle_url('/local/mail/compose.php'); $urlrecipients = new moodle_url('/local/mail/recipients.php'); if ($PAGE->url->compare($url, URL_MATCH_BASE) or $PAGE->url->compare($urlrecipients, URL_MATCH_BASE)) { $url->param('m', $PAGE->url->param('m')); } else { $url = new moodle_url('/local/mail/create.php'); if ($COURSE->id != $SITE->id) { $url->param('c', $COURSE->id); $url->param('sesskey', sesskey()); } } $node->add(s($text), $url); // Inbox $text = get_string('inbox', 'local_mail'); if (!empty($count->inbox)) { $text .= ' (' . $count->inbox . ')'; } $url = new moodle_url('/local/mail/view.php', array('t' => 'inbox')); $child = $node->add(s($text), $url); $child->add_class('mail_inbox'); // Starred $text = get_string('starredmail', 'local_mail'); $url = new moodle_url('/local/mail/view.php', array('t' => 'starred')); $node->add(s($text), $url); // Drafts $text = get_string('drafts', 'local_mail'); if (!empty($count->drafts)) { $text .= ' (' . $count->drafts . ')'; } $url = new moodle_url('/local/mail/view.php', array('t' => 'drafts')); $child = $node->add(s($text), $url); $child->add_class('mail_drafts'); // Sent $text = get_string('sentmail', 'local_mail'); $url = new moodle_url('/local/mail/view.php', array('t' => 'sent')); $node->add(s($text), $url); // Courses if ($courses) { $text = get_string('courses', 'local_mail'); $nodecourses = $node->add($text, null, navigation_node::TYPE_CONTAINER); foreach ($courses as $course) { $text = $course->shortname; if (!empty($count->courses[$course->id])) { $text .= ' (' . $count->courses[$course->id] . ')'; } $params = array('t' => 'course', 'c' => $course->id); $url = new moodle_url('/local/mail/view.php', $params); $child = $nodecourses->add(s($text), $url); $child->hidden = !$course->visible; $child->add_class('mail_course_' . $course->id); } } // Labels $labels = local_mail_label::fetch_user($USER->id); if ($labels) { $text = get_string('labels', 'local_mail'); $nodelabels = $node->add($text, null, navigation_node::TYPE_CONTAINER); foreach ($labels as $label) { $text = $label->name(); if (!empty($count->labels[$label->id()])) { $text .= ' (' . $count->labels[$label->id()] . ')'; } $params = array('t' => 'label', 'l' => $label->id()); $url = new moodle_url('/local/mail/view.php', $params); $child = $nodelabels->add(s($text), $url); $child->add_class('mail_label_' . $label->id()); } } // Trash $text = get_string('trash', 'local_mail'); $url = new moodle_url('/local/mail/view.php', array('t' => 'trash')); $node->add(s($text), $url); //Aqui } // User profile if (empty($CFG->messaging) and $PAGE->url->compare(new moodle_url('/user/view.php'), URL_MATCH_BASE)) { $userid = optional_param('id', false, PARAM_INT); if (local_mail_valid_recipient($userid)) { $vars = array('course' => $COURSE->id, 'recipient' => $userid); $PAGE->requires->string_for_js('sendmessage', 'local_mail'); $PAGE->requires->js_init_code('M.local_mail = ' . json_encode($vars)); $PAGE->requires->js('/local/mail/user.js'); } } // Users list if (empty($CFG->messaging) and $PAGE->url->compare(new moodle_url('/user/index.php'), URL_MATCH_BASE)) { $userid = optional_param('id', false, PARAM_INT); $vars = array('course' => $COURSE->id); $PAGE->requires->string_for_js('choosedots', 'moodle'); $PAGE->requires->strings_for_js(array('bulkmessage', 'to', 'cc', 'bcc'), 'local_mail'); $PAGE->requires->js_init_code('M.local_mail = ' . json_encode($vars)); $PAGE->requires->js('/local/mail/users.js'); } }
function local_mail_get_info() { global $USER; $count = local_mail_message::count_menu($USER->id); $text = get_string('mymail', 'local_mail'); if (empty($count->inbox)) { $count->root = $text; } else { $count->root = $text . ' (' . $count->inbox . ')'; } $text = get_string('inbox', 'local_mail'); if (empty($count->inbox)) { $count->inbox = $text; } else { $count->inbox = $text . ' (' . $count->inbox . ')'; } $text = get_string('drafts', 'local_mail'); if (empty($count->drafts)) { $count->drafts = $text; } else { $count->drafts = $text . ' (' . $count->drafts . ')'; } $labels = local_mail_label::fetch_user($USER->id); if ($labels) { foreach ($labels as $label) { $text = $label->name(); if (empty($count->labels[$label->id()])) { $count->labels[$label->id()] = $text; } else { $count->labels[$label->id()] = $text . ' (' . $count->labels[$label->id()] . ')'; } } } if (!($courses = local_mail_get_my_courses())) { return; } foreach ($courses as $course) { $text = $course->shortname; if (empty($count->courses[$course->id])) { $count->courses[$course->id] = $text; } else { $count->courses[$course->id] = $text . ' (' . $count->courses[$course->id] . ')'; } } return $count; }