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 25defined('MOODLE_INTERNAL') || die(); 26 27global $CFG; 28require_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 */ 37class mod_feedback_templates_table extends flexible_table { 38 39 /** 40 * Constructor 41 * @param int $uniqueid all tables have to have a unique id, this is used 42 * as a key when storing table properties like sort order in the session. 43 * @param moodle_url $baseurl 44 */ 45 public function __construct($uniqueid, $baseurl) { 46 parent::__construct($uniqueid); 47 48 $tablecolumns = array('template', 'action'); 49 $tableheaders = array(get_string('template', 'feedback'), ''); 50 51 $this->set_attribute('class', 'templateslist'); 52 53 $this->define_columns($tablecolumns); 54 $this->define_headers($tableheaders); 55 $this->define_baseurl($baseurl); 56 $this->column_class('template', 'template'); 57 $this->column_class('action', 'action'); 58 59 $this->sortable(false); 60 } 61 62 /** 63 * Displays the table with the given set of templates 64 * @param array $templates 65 */ 66 public function display($templates) { 67 global $OUTPUT; 68 if (empty($templates)) { 69 echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'), 70 'generalbox boxaligncenter'); 71 return; 72 } 73 74 $this->setup(); 75 $strdeletefeedback = get_string('delete_template', 'feedback'); 76 77 foreach ($templates as $template) { 78 $data = array(); 79 $data[] = format_string($template->name); 80 $url = new moodle_url($this->baseurl, array('deletetempl' => $template->id, 'sesskey' => sesskey())); 81 82 $deleteaction = new confirm_action(get_string('confirmdeletetemplate', 'feedback')); 83 $data[] = $OUTPUT->action_icon($url, new pix_icon('t/delete', $strdeletefeedback), $deleteaction); 84 $this->add_data($data); 85 } 86 $this->finish_output(); 87 } 88} 89