public function test_fetch() { $this->loadRecords('local_mail_labels', array(array('id', 'userid', 'name', 'color'), array(401, 201, 'label1', 'red'), array(402, 201, 'label2', ''))); $result = local_mail_label::fetch(401); $this->assertInstanceOf('local_mail_label', $result); $this->assertEquals(401, $result->id()); $this->assertEquals(201, $result->userid()); $this->assertEquals('label1', $result->name()); $this->assertEquals('red', $result->color()); }
public function toolbar($type, $courseid = 0, $params = null) { $replyall = isset($params['replyall']) ? $params['replyall'] : false; $paging = isset($params['paging']) ? $params['paging'] : null; $trash = isset($params['trash']) ? $params['trash'] : false; $labelid = isset($params['labelid']) ? $params['labelid'] : false; $toolbardown = false; if ($type === 'reply') { $viewcourse = array_key_exists($courseid, local_mail_get_my_courses()); $output = $this->reply($viewcourse); // all recipients $output .= $this->replyall(($viewcourse and $replyall)); $output .= $this->forward($viewcourse); $toolbardown = true; } else if ($type === 'forward') { $viewcourse = array_key_exists($courseid, local_mail_get_my_courses()); $output = $this->forward($viewcourse); $toolbardown = true; } else { $selectall = $this->selectall(); $labels = $extended = $goback = $search = $selectedlbl = ''; if (!$trash and $type !== 'trash') { $labels = $this->labels($type); } $read = $unread = ''; if ($type !== 'drafts') { $unread = $this->unread($type); $delete = $this->delete($trash); } else { $delete = $this->discard(); } $pagingbar = ''; if ($type !== 'view') { if ($type !== 'drafts') { $read = $this->read(); } $pagingbar = $this->paging($paging['offset'], $paging['count'], $paging['totalcount']); $search = $this->search(); } else { $goback = $this->goback($paging); } if ($type === 'label') { $extended = $this->optlabels(); $selectedlbl = $this->label(local_mail_label::fetch($labelid)); } $more = $this->moreactions(); $clearer = $this->output->container('', 'clearer'); $left = html_writer::tag('div', $goback . $selectall . $labels . $read . $unread . $delete . $extended . $more . $search . $selectedlbl, array('class' => 'mail_buttons')); $output = $left . $pagingbar . $clearer; } return $this->output->container($output, ($toolbardown ? 'mail_toolbar_down' : 'mail_toolbar')); }
$label->delete(); $url->param('t', 'inbox'); $url->remove_params(array('l')); redirect($url); } else { echo $OUTPUT->header(); $cancel = clone $url; $url->param('confirmlbl', '1'); $url->param('removelbl', '1'); echo $OUTPUT->confirm(get_string('labeldeleteconfirm', 'local_mail', $label->name()), $url, $cancel); echo $OUTPUT->footer(); } } else { if ($editlbl) { require_sesskey(); $label = local_mail_label::fetch($labelid); if (!$label or $label->userid() != $USER->id) { print_error('invalidlabel', 'local_mail'); } $courseid = $courseid ?: $SITE->id; if (!($course = $DB->get_record('course', array('id' => $courseid)))) { print_error('invalidcourse', 'error'); } // Check whether user can use mail in that course if ($course->id != $SITE->id) { $context = context_course::instance($course->id); require_capability('local/mail:usemail', $context); } $url->param('offset', $offset); local_mail_setup_page($course, $url); // Set up form
function local_mail_setlabel($type, $labelid, $labelname, $labelcolor) { global $CFG, $USER; $error = ''; $label = local_mail_label::fetch($labelid); $colors = local_mail_label::valid_colors(); $labelname = preg_replace('/\\s+/', ' ', $labelname); if ($label) { $labels = local_mail_label::fetch_user($USER->id); $repeatedname = false; foreach ($labels as $l) { $repeatedname = $repeatedname || ($l->name() === $labelname and $l->id() != $labelid); } if (!$repeatedname) { if ($labelname and (!$labelcolor or in_array($labelcolor, $colors))) { $label->save($labelname, $labelcolor); } else { $error = !$labelname ? get_string('erroremptylabelname', 'local_mail') : get_string('errorinvalidcolor', 'local_mail'); } } else { $error = get_string('errorrepeatedlabelname', 'local_mail'); } } else { $error = get_string('invalidlabel', 'local_mail'); } return array('msgerror' => $error, 'info' => '', 'html' => '', 'redirect' => $CFG->wwwroot . '/local/mail/view.php?t=' . $type . '&l=' . $labelid); }