public function test_fetch_user() { $label1 = local_mail_label::create(201, 'label1', 'red'); $label2 = local_mail_label::create(201, 'label2', 'green'); $label3 = local_mail_label::create(202, 'label3', 'blue'); $result = local_mail_label::fetch_user(201); $this->assertCount(2, $result); $this->assertContains($label1, $result); $this->assertContains($label2, $result); }
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 labels($type) { global $USER; $items = array(); $label = get_string('setlabels', 'local_mail'); $attributes = array( 'type' => 'submit', 'name' => 'assignlbl', 'value' => $label, 'class' => 'mail_button singlebutton' ); $output = html_writer::start_tag('noscript'); $output .= html_writer::empty_tag('input', $attributes); $output .= html_writer::end_tag('noscript'); $output .= html_writer::start_tag('span', array('class' => 'singlebutton mail_button mail_assignlbl mail_button_disabled mail_hidden')); $output .= html_writer::tag('span', $label); $url = $this->output->pix_url('t/expanded', 'moodle'); $output .= html_writer::empty_tag('img', array('src' => $url, 'alt' => 'expanded')); $output .= html_writer::end_tag('span'); // List labels and options $labels = local_mail_label::fetch_user($USER->id); $output .= html_writer::start_tag('div', array('class' => 'mail_hidden mail_labelselect')); foreach ($labels as $key => $label) { $content = html_writer::tag('span', '', array('class' => 'mail_adv_checkbox mail_checkbox0 mail_label_value_'.$label->id())); $content .= html_writer::tag('span', $label->name(), array('class' => 'mail_label_name')); $items[$key] = $content; } if (!empty($labels)) { $items[] = html_writer::tag('span', '', array('class' => 'mail_menu_label_separator')); } $items[] = html_writer::link('#', get_string('newlabel', 'local_mail'), array('class' => 'mail_menu_label_newlabel')); if (!empty($labels)) { $items[] = html_writer::link('#', get_string('applychanges', 'local_mail'), array('class' => 'mail_menu_label_apply')); } $output .= html_writer::alist($items, array('class' => 'mail_menu_labels')); $output .= html_writer::end_tag('div'); return $output; }
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_js_labels() { global $USER; $labels = local_mail_label::fetch_user($USER->id); $js = 'M.local_mail = {mail_labels: {'; $cont = 0; $total = count($labels); foreach ($labels as $label) { $js .= '"'.$label->id().'":{"id": "' . $label->id() . '", "name": "' . s($label->name()) . '", "color": "' . $label->color() . '"}'; $cont++; if ($cont < $total) { $js .= ','; } } $js .= '}};'; return $js; }
$data->labelid = clean_param_array($data->labelid, PARAM_INT); $labels = local_mail_label::fetch_user($USER->id); foreach ($labels as $label) { if ($data->labelid[$label->id()]) { $message->add_label($label); } else { $message->remove_label($label); } } } } else { if ($msgs) { $messages = local_mail_message::fetch_many($msgs); if (isset($data->labelid)) { $data->labelid = clean_param_array($data->labelid, PARAM_INT); $labels = local_mail_label::fetch_user($USER->id); } foreach ($messages as $message) { if (!$message->viewable($USER->id) or $message->deleted($USER->id)) { print_error('invalidmessage', 'local_mail'); } if (isset($data->labelid)) { foreach ($labels as $label) { if ($data->labelid[$label->id()]) { $message->add_label($label); } else { $message->remove_label($label); } } } }
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; }