MDL-53608 tool_lp: Replace deprecated method notify_message

This commit is contained in:
Issam Taboubi 2016-03-24 13:38:09 -04:00 committed by Frederic Massart
parent 9af8f0e2ba
commit 5548789716
5 changed files with 165 additions and 16 deletions

View File

@ -43,13 +43,14 @@ class assign_role_cohort extends moodleform {
* Form definition. * Form definition.
*/ */
public function definition() { public function definition() {
global $OUTPUT; global $PAGE;
$mform = $this->_form; $mform = $this->_form;
$roles = get_roles_for_contextlevels(CONTEXT_USER); $roles = get_roles_for_contextlevels(CONTEXT_USER);
if (empty($roles)) { if (empty($roles)) {
$warning = $OUTPUT->notify_problem(get_string('noassignableroles', 'tool_cohortroles')); $output = $PAGE->get_renderer('tool_cohortroles');
$warning = $output->notify_problem(get_string('noassignableroles', 'tool_cohortroles'));
$mform->addElement('html', $warning); $mform->addElement('html', $warning);
return; return;
} }

View File

@ -0,0 +1,76 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Renderer class for cohort roles
*
* @package tool_cohortroles
* @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_cohortroles\output;
defined('MOODLE_INTERNAL') || die();
use plugin_renderer_base;
use renderable;
/**
* Renderer class for cohort roles
*
* @package tool_cohortroles
* @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends plugin_renderer_base {
/**
* Output a nofication.
*
* @param string $message the message to print out
* @return string HTML fragment.
* @see \core\output\notification
*/
public function notify_message($message) {
$n = new \core\output\notification($message, \core\output\notification::NOTIFY_INFO);
return $this->render($n);
}
/**
* Output an error notification.
*
* @param string $message the message to print out
* @return string HTML fragment.
* @see \core\output\notification
*/
public function notify_problem($message) {
$n = new \core\output\notification($message, \core\output\notification::NOTIFY_ERROR);
return $this->render($n);
}
/**
* Output a success notification.
*
* @param string $message the message to print out
* @return string HTML fragment.
* @see \core\output\notification
*/
public function notify_success($message) {
$n = new \core\output\notification($message, \core\output\notification::NOTIFY_SUCCESS);
return $this->render($n);
}
}

View File

@ -33,11 +33,11 @@ $context = context_system::instance();
$pageurl = new moodle_url('/admin/tool/cohortroles/index.php'); $pageurl = new moodle_url('/admin/tool/cohortroles/index.php');
$renderer = $PAGE->get_renderer('core'); $output = $PAGE->get_renderer('tool_cohortroles');
echo $OUTPUT->header(); echo $output->header();
$title = get_string('assignroletocohort', 'tool_cohortroles'); $title = get_string('assignroletocohort', 'tool_cohortroles');
echo $OUTPUT->heading($title); echo $output->heading($title);
$form = new tool_cohortroles\form\assign_role_cohort(); $form = new tool_cohortroles\form\assign_role_cohort();
@ -47,12 +47,12 @@ if ($removeid) {
$result = \tool_cohortroles\api::delete_cohort_role_assignment($removeid); $result = \tool_cohortroles\api::delete_cohort_role_assignment($removeid);
if ($result) { if ($result) {
$notification = get_string('cohortroleassignmentremoved', 'tool_cohortroles'); $notification = get_string('cohortroleassignmentremoved', 'tool_cohortroles');
echo $OUTPUT->notify_success($notification); echo $output->notify_success($notification);
} else { } else {
$notification = get_string('cohortroleassignmentnotremoved', 'tool_cohortroles'); $notification = get_string('cohortroleassignmentnotremoved', 'tool_cohortroles');
echo $OUTPUT->notify_problem($notification); echo $output->notify_problem($notification);
} }
echo $OUTPUT->continue_button(new moodle_url($pageurl)); echo $output->continue_button(new moodle_url($pageurl));
} else if ($data = $form->get_data()) { } else if ($data = $form->get_data()) {
require_sesskey(); require_sesskey();
// We must create them all or none. // We must create them all or none.
@ -71,28 +71,28 @@ if ($removeid) {
} }
if ($saved == 0) { if ($saved == 0) {
$notification = get_string('nocohortroleassignmentssaved', 'tool_cohortroles'); $notification = get_string('nocohortroleassignmentssaved', 'tool_cohortroles');
echo $OUTPUT->notify_problem($notification); echo $output->notify_problem($notification);
} else if ($saved == 1) { } else if ($saved == 1) {
$notification = get_string('onecohortroleassignmentsaved', 'tool_cohortroles'); $notification = get_string('onecohortroleassignmentsaved', 'tool_cohortroles');
echo $OUTPUT->notify_success($notification); echo $output->notify_success($notification);
} else { } else {
$notification = get_string('acohortroleassignmentssaved', 'tool_cohortroles', $saved); $notification = get_string('acohortroleassignmentssaved', 'tool_cohortroles', $saved);
echo $OUTPUT->notify_success($notification); echo $output->notify_success($notification);
} }
echo $OUTPUT->continue_button(new moodle_url($pageurl)); echo $output->continue_button(new moodle_url($pageurl));
} else { } else {
$form->display(); $form->display();
$title = get_string('existingcohortroles', 'tool_cohortroles'); $title = get_string('existingcohortroles', 'tool_cohortroles');
echo $OUTPUT->heading($title); echo $output->heading($title);
$url = new moodle_url('/admin/tool/cohortroles/index.php'); $url = new moodle_url('/admin/tool/cohortroles/index.php');
$table = new tool_cohortroles\output\cohort_role_assignments_table(uniqid(), $url); $table = new tool_cohortroles\output\cohort_role_assignments_table(uniqid(), $url);
echo $table->out(50, true); echo $table->out(50, true);
echo $OUTPUT->spacer(); echo $output->spacer();
echo $OUTPUT->notify_message(get_string('backgroundsync', 'tool_cohortroles')); echo $output->notify_message(get_string('backgroundsync', 'tool_cohortroles'));
} }
echo $OUTPUT->footer(); echo $output->footer();

View File

@ -216,4 +216,40 @@ class renderer extends plugin_renderer_base {
$data = $page->export_for_template($this); $data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/user_competency_summary', $data); return parent::render_from_template('tool_lp/user_competency_summary', $data);
} }
/**
* Output a nofication.
*
* @param string $message the message to print out
* @return string HTML fragment.
* @see \core\output\notification
*/
public function notify_message($message) {
$n = new \core\output\notification($message, \core\output\notification::NOTIFY_INFO);
return $this->render($n);
}
/**
* Output an error notification.
*
* @param string $message the message to print out
* @return string HTML fragment.
* @see \core\output\notification
*/
public function notify_problem($message) {
$n = new \core\output\notification($message, \core\output\notification::NOTIFY_ERROR);
return $this->render($n);
}
/**
* Output a success notification.
*
* @param string $message the message to print out
* @return string HTML fragment.
* @see \core\output\notification
*/
public function notify_success($message) {
$n = new \core\output\notification($message, \core\output\notification::NOTIFY_SUCCESS);
return $this->render($n);
}
} }

View File

@ -59,4 +59,40 @@ class renderer extends plugin_renderer_base {
$data = $nav->export_for_template($this); $data = $nav->export_for_template($this);
return parent::render_from_template('report_competency/user_course_navigation', $data); return parent::render_from_template('report_competency/user_course_navigation', $data);
} }
/**
* Output a nofication.
*
* @param string $message the message to print out
* @return string HTML fragment.
* @see \core\output\notification
*/
public function notify_message($message) {
$n = new \core\output\notification($message, \core\output\notification::NOTIFY_INFO);
return $this->render($n);
}
/**
* Output an error notification.
*
* @param string $message the message to print out
* @return string HTML fragment.
* @see \core\output\notification
*/
public function notify_problem($message) {
$n = new \core\output\notification($message, \core\output\notification::NOTIFY_ERROR);
return $this->render($n);
}
/**
* Output a success notification.
*
* @param string $message the message to print out
* @return string HTML fragment.
* @see \core\output\notification
*/
public function notify_success($message) {
$n = new \core\output\notification($message, \core\output\notification::NOTIFY_SUCCESS);
return $this->render($n);
}
} }