MDL-45758 tool_monitor: add missing alt on manage icons
[moodle.git] / admin / tool / monitor / classes / output / managerules / renderable.php
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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.
13 //
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/>.
17 /**
18  * Renderable class for manage rules page.
19  *
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
23  */
25 namespace tool_monitor\output\managerules;
27 defined('MOODLE_INTERNAL') || die;
29 require_once($CFG->libdir . '/tablelib.php');
31 /**
32  * Renderable class for manage rules page.
33  *
34  * @since      Moodle 2.8
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
38  */
39 class renderable extends \table_sql implements \renderable {
41     /**
42      * @var int course id.
43      */
44     public $courseid;
46     /**
47      * @var \context_course|\context_system context of the page to be rendered.
48      */
49     protected $context;
51     /**
52      * @var bool Does the user have capability to manage rules at site context.
53      */
54     protected $hassystemcap;
56     /**
57      * Sets up the table_log parameters.
58      *
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.
63      */
64     public function __construct($uniqueid, \moodle_url $url, $courseid = 0, $perpage = 100) {
65         parent::__construct($uniqueid);
67         $this->set_attribute('class', 'toolmonitor managerules generaltable generalbox');
68         $this->define_columns(array('name', 'description', 'plugin', 'eventname', 'filters', 'manage'));
69         $this->define_headers(array(
70                 get_string('name'),
71                 get_string('description'),
72                 get_string('plugin'),
73                 get_string('eventname'),
74                 get_string('frequency', 'tool_monitor'),
75                 get_string('manage', 'tool_monitor'),
76             )
77         );
78         $this->courseid = $courseid;
79         $this->pagesize = $perpage;
80         $systemcontext = \context_system::instance();
81         $this->context = empty($courseid) ? $systemcontext : \context_course::instance($courseid);
82         $this->hassystemcap = has_capability('tool/monitor:managerules', $systemcontext);
83         $this->collapsible(false);
84         $this->sortable(false);
85         $this->pageable(true);
86         $this->is_downloadable(false);
87         $this->define_baseurl($url);
88     }
90     /**
91      * Generate content for name column.
92      *
93      * @param \tool_monitor\rule $rule rule object
94      *
95      * @return string html used to display the column field.
96      */
97     public function col_name(\tool_monitor\rule $rule) {
98         return $rule->get_name($this->context);
99     }
101     /**
102      * Generate content for description column.
103      *
104      * @param \tool_monitor\rule $rule rule object
105      *
106      * @return string html used to display the column field.
107      */
108     public function col_description(\tool_monitor\rule $rule) {
109         return $rule->get_description($this->context);
110     }
112     /**
113      * Generate content for plugin column.
114      *
115      * @param \tool_monitor\rule $rule rule object
116      *
117      * @return string html used to display the column field.
118      */
119     public function col_plugin(\tool_monitor\rule $rule) {
120         return $rule->get_plugin_name();
121     }
123     /**
124      * Generate content for eventname column.
125      *
126      * @param \tool_monitor\rule $rule rule object
127      *
128      * @return string html used to display the column field.
129      */
130     public function col_eventname(\tool_monitor\rule $rule) {
131         return $rule->get_event_name();
132     }
134     /**
135      * Generate content for filters column.
136      *
137      * @param \tool_monitor\rule $rule rule object
138      *
139      * @return string html used to display the filters column field.
140      */
141     public function col_filters(\tool_monitor\rule $rule) {
142         return $rule->get_filters_description();
143     }
145     /**
146      * Generate content for manage column.
147      *
148      * @param \tool_monitor\rule $rule rule object
149      *
150      * @return string html used to display the manage column field.
151      */
152     public function col_manage(\tool_monitor\rule $rule) {
153         global $OUTPUT, $CFG;
154         $manage = '';
155         // We don't need to check for capability at course level since, user is never shown this page,
156         // if he doesn't have the capability.
157         if ($this->hassystemcap || ($rule->courseid !== 0)) {
158             // There might be site rules which the user can not manage.
159             $editurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/edit.php', array('ruleid' => $rule->id,
160                     'courseid' => $rule->courseid));
161             $copyurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php',
162                     array('ruleid' => $rule->id, 'action' => 'copy', 'courseid' => $this->courseid));
163             $deleteurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php', array('ruleid' => $rule->id,
164                     'action' => 'delete', 'courseid' => $rule->courseid));
166             $icon = $OUTPUT->render(new \pix_icon('t/edit', get_string('editrule', 'tool_monitor')));
167             $manage .= \html_writer::link($editurl, $icon, array('class' => 'action-icon'));
169             $icon = $OUTPUT->render(new \pix_icon('t/copy', get_string('duplicaterule', 'tool_monitor')));
170             $manage .= \html_writer::link($copyurl, $icon, array('class' => 'action-icon'));
172             $a = $rule->get_name($this->context);
173             $action = new \component_action('click', 'M.util.show_confirm_dialog', array('message' => get_string('ruleareyousure',
174                     'tool_monitor', $a)));
175             $icon = $OUTPUT->action_link($deleteurl, new \pix_icon('t/delete', get_string('deleterule', 'tool_monitor')), $action);
176             $manage .= $icon;
177         } else {
178             $manage = '-';
179         }
180         return $manage;
181     }
183     /**
184      * Query the reader. Store results in the object for use by build_table.
185      *
186      * @param int $pagesize size of page for paginated displayed table.
187      * @param bool $useinitialsbar do you want to use the initials bar.
188      */
189     public function query_db($pagesize, $useinitialsbar = true) {
191         $total = \tool_monitor\rule_manager::count_rules_by_courseid($this->courseid);
192         $this->pagesize($pagesize, $total);
193         $rules = \tool_monitor\rule_manager::get_rules_by_courseid($this->courseid, $this->get_page_start(),
194                 $this->get_page_size());
195         foreach ($rules as $rule) {
196             $this->rawdata[] = \tool_monitor\rule_manager::get_rule($rule);
197         }
198         // Set initial bars.
199         if ($useinitialsbar) {
200             $this->initialbars($total > $pagesize);
201         }
202     }