[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
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/>. 16 17 /** 18 * Renderable class for manage rules page. 19 * 20 * @package tool_monitor 21 * @copyright 2014 onwards Ankit Agarwal <[email protected]> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace tool_monitor\output\managerules; 26 27 defined('MOODLE_INTERNAL') || die; 28 29 require_once($CFG->libdir . '/tablelib.php'); 30 31 /** 32 * Renderable class for manage rules page. 33 * 34 * @since Moodle 2.8 35 * @package tool_monitor 36 * @copyright 2014 onwards Ankit Agarwal <[email protected]> 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class renderable extends \table_sql implements \renderable { 40 41 /** 42 * @var int course id. 43 */ 44 public $courseid; 45 46 /** 47 * @var \context_course|\context_system context of the page to be rendered. 48 */ 49 protected $context; 50 51 /** 52 * @var bool Does the user have capability to manage rules at site context. 53 */ 54 protected $hassystemcap; 55 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); 66 67 $this->set_attribute('id', 'toolmonitorrules_table'); 68 $this->set_attribute('class', 'toolmonitor managerules generaltable generalbox'); 69 $this->define_columns(array('name', 'description', 'course', 'plugin', 'eventname', 'filters', 'manage')); 70 $this->define_headers(array( 71 get_string('rulename', 'tool_monitor'), 72 get_string('description'), 73 get_string('course'), 74 get_string('area', 'tool_monitor'), 75 get_string('event', 'tool_monitor'), 76 get_string('frequency', 'tool_monitor'), 77 get_string('manage', 'tool_monitor'), 78 ) 79 ); 80 $this->courseid = $courseid; 81 $this->pagesize = $perpage; 82 $systemcontext = \context_system::instance(); 83 $this->context = empty($courseid) ? $systemcontext : \context_course::instance($courseid); 84 $this->hassystemcap = has_capability('tool/monitor:managerules', $systemcontext); 85 $this->collapsible(false); 86 $this->sortable(false); 87 $this->pageable(true); 88 $this->is_downloadable(false); 89 $this->define_baseurl($url); 90 } 91 92 /** 93 * Generate content for name column. 94 * 95 * @param \tool_monitor\rule $rule rule object 96 * @return string html used to display the column field. 97 */ 98 public function col_name(\tool_monitor\rule $rule) { 99 return $rule->get_name($this->context); 100 } 101 102 /** 103 * Generate content for description column. 104 * 105 * @param \tool_monitor\rule $rule rule object 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 } 111 112 /** 113 * Generate content for course column. 114 * 115 * @param \tool_monitor\rule $rule rule object 116 * @return string html used to display the context column field. 117 */ 118 public function col_course(\tool_monitor\rule $rule) { 119 $coursename = $rule->get_course_name($this->context); 120 121 $courseid = $rule->courseid; 122 if (empty($courseid)) { 123 return $coursename; 124 } else { 125 return \html_writer::link(new \moodle_url('/course/view.php', array('id' => $courseid)), $coursename); 126 } 127 } 128 129 /** 130 * Generate content for plugin column. 131 * 132 * @param \tool_monitor\rule $rule rule object 133 * @return string html used to display the column field. 134 */ 135 public function col_plugin(\tool_monitor\rule $rule) { 136 return $rule->get_plugin_name(); 137 } 138 139 /** 140 * Generate content for eventname column. 141 * 142 * @param \tool_monitor\rule $rule rule object 143 * @return string html used to display the column field. 144 */ 145 public function col_eventname(\tool_monitor\rule $rule) { 146 return $rule->get_event_name(); 147 } 148 149 /** 150 * Generate content for filters column. 151 * 152 * @param \tool_monitor\rule $rule rule object 153 * @return string html used to display the filters column field. 154 */ 155 public function col_filters(\tool_monitor\rule $rule) { 156 return $rule->get_filters_description(); 157 } 158 159 /** 160 * Generate content for manage column. 161 * 162 * @param \tool_monitor\rule $rule rule object 163 * @return string html used to display the manage column field. 164 */ 165 public function col_manage(\tool_monitor\rule $rule) { 166 global $OUTPUT, $CFG; 167 $manage = ''; 168 // We don't need to check for capability at course level since, user is never shown this page, 169 // if he doesn't have the capability. 170 if ($this->hassystemcap || ($rule->courseid != 0)) { 171 // There might be site rules which the user can not manage. 172 $editurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/edit.php', array('ruleid' => $rule->id, 173 'courseid' => $rule->courseid, 'sesskey' => sesskey())); 174 $copyurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php', 175 array('ruleid' => $rule->id, 'action' => 'copy', 'courseid' => $this->courseid, 'sesskey' => sesskey())); 176 $deleteurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/managerules.php', array('ruleid' => $rule->id, 177 'action' => 'delete', 'courseid' => $rule->courseid, 'sesskey' => sesskey())); 178 179 $icon = $OUTPUT->render(new \pix_icon('t/edit', get_string('editrule', 'tool_monitor'))); 180 $manage .= \html_writer::link($editurl, $icon, array('class' => 'action-icon')); 181 182 $icon = $OUTPUT->render(new \pix_icon('t/copy', get_string('duplicaterule', 'tool_monitor'))); 183 $manage .= \html_writer::link($copyurl, $icon, array('class' => 'action-icon')); 184 185 $icon = $OUTPUT->render(new \pix_icon('t/delete', get_string('deleterule', 'tool_monitor'))); 186 $manage .= \html_writer::link($deleteurl, $icon, array('class' => 'action-icon')); 187 } else { 188 $manage = get_string('nopermission', 'tool_monitor'); 189 } 190 return $manage; 191 } 192 193 /** 194 * Query the reader. Store results in the object for use by build_table. 195 * 196 * @param int $pagesize size of page for paginated displayed table. 197 * @param bool $useinitialsbar do you want to use the initials bar. 198 */ 199 public function query_db($pagesize, $useinitialsbar = true) { 200 201 $total = \tool_monitor\rule_manager::count_rules_by_courseid($this->courseid); 202 $this->pagesize($pagesize, $total); 203 $rules = \tool_monitor\rule_manager::get_rules_by_courseid($this->courseid, $this->get_page_start(), 204 $this->get_page_size()); 205 $this->rawdata = $rules; 206 // Set initial bars. 207 if ($useinitialsbar) { 208 $this->initialbars($total > $pagesize); 209 } 210 } 211 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |