Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402]
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 * Contains class mod_feedback_templates_table 19 * 20 * @package mod_feedback 21 * @copyright 2016 Marina Glancy 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 global $CFG; 28 require_once($CFG->libdir . '/tablelib.php'); 29 30 /** 31 * Class mod_feedback_templates_table 32 * 33 * @package mod_feedback 34 * @copyright 2016 Marina Glancy 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class mod_feedback_templates_table extends flexible_table { 38 /** @var string|null Indicate whether we are managing template or not. */ 39 private $mode; 40 41 /** 42 * Constructor 43 * @param int $uniqueid all tables have to have a unique id, this is used 44 * as a key when storing table properties like sort order in the session. 45 * @param moodle_url $baseurl 46 * @param string $mode Indicate whether we are managing templates 47 */ 48 public function __construct($uniqueid, $baseurl, ?string $mode = null) { 49 parent::__construct($uniqueid); 50 $this->mode = $mode; 51 $tablecolumns = array('template'); 52 if ($this->mode) { 53 $tablecolumns[] = 'actions'; 54 } 55 56 $tableheaders = array(get_string('template', 'feedback'), ''); 57 58 $this->set_attribute('class', 'templateslist'); 59 60 $this->define_columns($tablecolumns); 61 $this->define_headers($tableheaders); 62 $this->define_baseurl($baseurl); 63 $this->column_class('template', 'template'); 64 $this->column_class('actions', 'text-right'); 65 $this->sortable(false); 66 } 67 68 /** 69 * Displays the table with the given set of templates 70 * @param array $templates 71 */ 72 public function display($templates) { 73 global $OUTPUT; 74 if (empty($templates)) { 75 echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'), 76 'generalbox boxaligncenter'); 77 return; 78 } 79 80 $this->setup(); 81 $strdeletefeedback = get_string('delete_template', 'feedback'); 82 83 foreach ($templates as $template) { 84 $data = []; 85 $url = new moodle_url($this->baseurl, array('templateid' => $template->id, 'sesskey' => sesskey())); 86 $data[] = $OUTPUT->action_link($url, format_string($template->name)); 87 88 // Only show the actions if we are managing templates. 89 if ($this->mode && has_capability('mod/feedback:deletetemplate', $this->get_context())) { 90 $deleteurl = new moodle_url('/mod/feedback/manage_templates.php', 91 $url->params() + ['deletetemplate' => $template->id]); 92 $deleteaction = new confirm_action(get_string('confirmdeletetemplate', 'feedback')); 93 $deleteicon = $OUTPUT->action_icon($deleteurl, new pix_icon('t/delete', $strdeletefeedback), $deleteaction); 94 if ($template->ispublic) { 95 $systemcontext = context_system::instance(); 96 if (!(has_capability('mod/feedback:createpublictemplate', $systemcontext) && 97 has_capability('mod/feedback:deletetemplate', $systemcontext))) { 98 $deleteicon = false; 99 } 100 } 101 $data[] = $deleteicon; 102 } 103 104 $this->add_data($data); 105 } 106 $this->finish_output(); 107 } 108 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body