2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Renderable class to display a set of subscriptions in the manage subscriptions page.
20 * @package tool_monitor
21 * @copyright 2014 onwards Ankit Agarwal <ankit.agrr@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace tool_monitor\output\managesubs;
27 defined('MOODLE_INTERNAL') || die;
29 require_once($CFG->libdir . '/tablelib.php');
32 * Renderable class to display a set of subscriptions in the manage subscriptions page.
35 * @package tool_monitor
36 * @copyright 2014 onwards Ankit Agarwal <ankit.agrr@gmail.com>
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 class subs extends \table_sql implements \renderable {
47 * @var \context_course|\context_system context of the page to be rendered.
52 * @var \tool_monitor\output\helpicon\renderer the help icon renderer.
54 protected $helpiconrenderer;
57 * Sets up the table_log parameters.
59 * @param string $uniqueid unique id of form.
60 * @param \moodle_url $url url where this table is displayed.
61 * @param int $courseid course id.
62 * @param int $perpage Number of rules to display per page.
64 public function __construct($uniqueid, \moodle_url $url, $courseid = 0, $perpage = 100) {
67 parent::__construct($uniqueid);
69 $this->set_attribute('class', 'toolmonitor subscriptions generaltable generalbox');
70 $this->define_columns(array('name', 'instance', 'unsubscribe'));
71 $this->define_headers(array(
73 get_string('moduleinstance', 'tool_monitor'),
74 get_string('unsubscribe', 'tool_monitor')
77 $this->courseid = $courseid;
78 $this->pagesize = $perpage;
79 $systemcontext = \context_system::instance();
80 $this->context = empty($courseid) ? $systemcontext : \context_course::instance($courseid);
81 $this->collapsible(false);
82 $this->sortable(false);
83 $this->pageable(true);
84 $this->is_downloadable(false);
85 $this->define_baseurl($url);
86 $this->helpiconrenderer = $PAGE->get_renderer('tool_monitor', 'helpicon');
90 * Generate content for name column.
92 * @param \tool_monitor\subscription $sub subscription object
94 * @return string html used to display the column field.
96 public function col_name(\tool_monitor\subscription $sub) {
97 $name = $sub->get_name($this->context);
98 $helpicon = new \tool_monitor\output\helpicon\renderable('subscription', $sub->id);
99 $helpicon = $this->helpiconrenderer->render($helpicon);
101 return $name . $helpicon;
105 * Generate content for description column.
107 * @param \tool_monitor\subscription $sub subscription object
109 * @return string html used to display the column field.
111 public function col_instance(\tool_monitor\subscription $sub) {
112 return $sub->get_instance_name();
116 * Generate content for manage column.
118 * @param \tool_monitor\subscription $sub subscription object
120 * @return string html used to display the column field.
122 public function col_unsubscribe(\tool_monitor\subscription $sub) {
123 global $OUTPUT, $CFG;
125 $a = $sub->get_name($this->context);
126 $deleteurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/index.php', array('subscriptionid' => $sub->id,
127 'action' => 'unsubscribe', 'courseid' => $this->courseid));
128 $action = new \component_action('click', 'M.util.show_confirm_dialog', array('message' => get_string('subareyousure',
129 'tool_monitor', $a)));
130 $icon = $OUTPUT->action_link($deleteurl,
131 new \pix_icon('t/delete', get_string('deletesubscription', 'tool_monitor')), $action);
136 * Query the reader. Store results in the object for use by build_table.
138 * @param int $pagesize size of page for paginated displayed table.
139 * @param bool $useinitialsbar do you want to use the initials bar.
141 public function query_db($pagesize, $useinitialsbar = true) {
143 $total = \tool_monitor\subscription_manager::count_user_subscriptions_for_course($this->courseid);
144 $this->pagesize($pagesize, $total);
145 $subs = \tool_monitor\subscription_manager::get_user_subscriptions_for_course($this->courseid, $this->get_page_start(),
146 $this->get_page_size());
147 foreach ($subs as $subscription) {
148 $this->rawdata[] = \tool_monitor\subscription_manager::get_subscription($subscription->id);
151 if ($useinitialsbar) {
152 $this->initialbars($total > $pagesize);