mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-45758 tool_monitor: added help icon renderer
Original issue - MDL-47152
This commit is contained in:
parent
27b6839fe2
commit
d55f3e03b1
93
admin/tool/monitor/classes/output/helpicon/renderable.php
Normal file
93
admin/tool/monitor/classes/output/helpicon/renderable.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* The file for the renderable class for the tool_monitor help icon.
|
||||
*
|
||||
* @package tool_monitor
|
||||
* @copyright 2014 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_monitor\output\helpicon;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/**
|
||||
* Renderable class for the tool_monitor help icon.
|
||||
*
|
||||
* @since Moodle 2.8
|
||||
* @package tool_monitor
|
||||
* @copyright 2014 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class renderable implements \renderable {
|
||||
|
||||
/**
|
||||
* @var string $type the type we are displaying the help icon for (either rule or subscription).
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* @var int $id the id of the type.
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*
|
||||
* @param string $type the type we are displaying the help icon for (either rule or subscription).
|
||||
* @param int $id the id of the type.
|
||||
*/
|
||||
public function __construct($type, $id) {
|
||||
$this->type = $type;
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to display for the help icon.
|
||||
*
|
||||
* @param string $type the type we are displaying the help icon for (either rule or subscription).
|
||||
* @param int $id the id of the type.
|
||||
* @param boolean $ajax Whether this help is called from an AJAX script.
|
||||
* This is used to influence text formatting and determines which format to output the doclink in.
|
||||
* @return string|object|array $a An object, string or number that can be used within translation strings
|
||||
*/
|
||||
public static function get_help_string_parameters($type, $id, $ajax = false) {
|
||||
if ($type == 'rule') {
|
||||
$rule = \tool_monitor\rule_manager::get_rule($id);
|
||||
|
||||
$langstring = new \stdClass();
|
||||
$langstring->eventname = $rule->get_event_name();
|
||||
$langstring->eventcomponent = $rule->get_plugin_name();
|
||||
$langstring->frequency = $rule->frequency;
|
||||
$langstring->minutes = $rule->timewindow / MINSECS;
|
||||
|
||||
return get_formatted_help_string('rulehelp', 'tool_monitor', $ajax, $langstring);
|
||||
}
|
||||
|
||||
// Must be a subscription.
|
||||
$sub = \tool_monitor\subscription_manager::get_subscription($id);
|
||||
|
||||
$langstring = new \stdClass();
|
||||
$langstring->eventname = $sub->get_event_name();
|
||||
$langstring->moduleinstance = $sub->get_instance_name();
|
||||
$langstring->frequency = $sub->frequency;
|
||||
$langstring->minutes = $sub->timewindow / MINSECS;
|
||||
|
||||
return get_formatted_help_string('subhelp', 'tool_monitor', $ajax, $langstring);
|
||||
}
|
||||
}
|
79
admin/tool/monitor/classes/output/helpicon/renderer.php
Normal file
79
admin/tool/monitor/classes/output/helpicon/renderer.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* The file for the renderer class for the tool_monitor help icon.
|
||||
*
|
||||
* @package tool_monitor
|
||||
* @copyright 2014 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_monitor\output\helpicon;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/**
|
||||
* Renderer class for tool_monitor help icons.
|
||||
*
|
||||
* @since Moodle 2.8
|
||||
* @package tool_monitor
|
||||
* @copyright 2014 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class renderer extends \plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Get the HTML for the help icon.
|
||||
*
|
||||
* @param renderable $renderable renderable widget
|
||||
*
|
||||
* @return string the HTML of the help icon to display.
|
||||
*/
|
||||
protected function render_renderable(renderable $renderable) {
|
||||
global $CFG;
|
||||
|
||||
// First get the help image icon.
|
||||
$src = $this->pix_url('help');
|
||||
|
||||
if ($renderable->type == 'rule') {
|
||||
$title = get_string('rulehelp', 'tool_monitor');
|
||||
} else { // Must be a subscription.
|
||||
$title = get_string('subhelp', 'tool_monitor');
|
||||
}
|
||||
|
||||
$alt = get_string('helpwiththis');
|
||||
|
||||
$attributes = array('src' => $src, 'alt' => $alt, 'class' => 'iconhelp');
|
||||
$output = \html_writer::empty_tag('img', $attributes);
|
||||
|
||||
// Now create the link around it - we need https on loginhttps pages.
|
||||
$urlparams = array();
|
||||
$urlparams['type'] = $renderable->type;
|
||||
$urlparams['id'] = $renderable->id;
|
||||
$urlparams['lang'] = current_language();
|
||||
$url = new \moodle_url($CFG->httpswwwroot . '/admin/tool/monitor/help.php', $urlparams);
|
||||
|
||||
// Note: this title is displayed only if JS is disabled, otherwise the link will have the new ajax tooltip.
|
||||
$title = get_string('helpprefix2', '', trim($title, ". \t"));
|
||||
|
||||
$attributes = array('href' => $url, 'title' => $title, 'aria-haspopup' => 'true', 'target' => '_blank');
|
||||
$output = \html_writer::tag('a', $output, $attributes);
|
||||
|
||||
// Now, finally the span.
|
||||
return \html_writer::tag('span', $output, array('class' => 'helptooltip'));
|
||||
}
|
||||
}
|
62
admin/tool/monitor/help.php
Normal file
62
admin/tool/monitor/help.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Displays help on a new page.
|
||||
*
|
||||
* @copyright 2014 Mark Nelson <markn@moodle.com>
|
||||
* @package tool_monitor
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
define('NO_MOODLE_COOKIES', true);
|
||||
|
||||
require_once('../../../config.php');
|
||||
|
||||
$type = required_param('type', PARAM_ALPHA);
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$lang = optional_param('lang', 'en', PARAM_LANG);
|
||||
|
||||
// We don't actually modify the session here as we have NO_MOODLE_COOKIES set.
|
||||
$SESSION->lang = $lang;
|
||||
|
||||
$PAGE->set_url('/admin/tool/monitor/help.php');
|
||||
$PAGE->set_pagelayout('popup');
|
||||
|
||||
if ($type == 'rule') {
|
||||
$item = \tool_monitor\rule_manager::get_rule($id);
|
||||
} else { // Must be a subscription.
|
||||
$item = \tool_monitor\subscription_manager::get_subscription($id);
|
||||
}
|
||||
|
||||
if ($item->courseid) {
|
||||
$PAGE->set_context(context_course::instance($item->courseid));
|
||||
} else { // Must be system context.
|
||||
$PAGE->set_context(context_system::instance());
|
||||
}
|
||||
|
||||
// Get the help string data.
|
||||
$data = tool_monitor\output\helpicon\renderable::get_help_string_parameters($type, $id);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
if (!empty($data->heading)) {
|
||||
echo $OUTPUT->heading($data->heading, 1, 'helpheading');
|
||||
}
|
||||
echo $data->text;
|
||||
if (isset($data->completedoclink)) {
|
||||
echo $data->completedoclink;
|
||||
}
|
||||
echo $OUTPUT->footer();
|
50
admin/tool/monitor/help_ajax.php
Normal file
50
admin/tool/monitor/help_ajax.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Displays help via AJAX call.
|
||||
*
|
||||
* @copyright 2014 Mark Nelson <markn@moodle.com>
|
||||
* @package tool_monitor
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
define('NO_MOODLE_COOKIES', true);
|
||||
define('AJAX_SCRIPT', true);
|
||||
|
||||
require_once('../../../config.php');
|
||||
|
||||
$type = required_param('type', PARAM_ALPHA);
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$lang = optional_param('lang', 'en', PARAM_LANG);
|
||||
|
||||
// We don't actually modify the session here as we have NO_MOODLE_COOKIES set.
|
||||
$SESSION->lang = $lang;
|
||||
$PAGE->set_url('/admin/tool/monitor/help_ajax.php');
|
||||
|
||||
if ($type == 'rule') {
|
||||
$item = \tool_monitor\rule_manager::get_rule($id);
|
||||
} else { // Must be a subscription.
|
||||
$item = \tool_monitor\subscription_manager::get_subscription($id);
|
||||
}
|
||||
|
||||
if ($item->courseid) {
|
||||
$PAGE->set_context(context_course::instance($item->courseid));
|
||||
} else { // Must be system context.
|
||||
$PAGE->set_context(context_system::instance());
|
||||
}
|
||||
|
||||
echo json_encode(tool_monitor\output\helpicon\renderable::get_help_string_parameters($type, $id, true));
|
Loading…
x
Reference in New Issue
Block a user