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 namespace mod_feedback\output; 18 19 use confirm_action; 20 use context_system; 21 use moodle_url; 22 use action_link; 23 24 /** 25 * Class actionbar - Display the action bar 26 * 27 * @package mod_feedback 28 * @copyright 2021 Peter Dias 29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 30 */ 31 class edit_template_action_bar extends base_action_bar { 32 /** @var int $templateid The template that is being edited/used */ 33 private $templateid; 34 /** @var string $mode The type of view we are dealing with */ 35 private $mode; 36 37 /** 38 * edit_template_action_bar constructor. 39 * @param int $cmid 40 * @param int $templateid 41 * @param string $mode 42 */ 43 public function __construct(int $cmid, int $templateid, string $mode) { 44 parent::__construct($cmid); 45 $this->templateid = $templateid; 46 $this->mode = $mode; 47 } 48 49 /** 50 * Return the items to be used in the tertiary nav 51 * 52 * @return array 53 */ 54 public function get_items(): array { 55 global $DB; 56 $additionalparams = ($this->mode ? ['mode' => $this->mode] : []); 57 $templateurl = new moodle_url('/mod/feedback/manage_templates.php', $this->urlparams + $additionalparams); 58 $items['left'][]['actionlink'] = new action_link($templateurl, get_string('back'), null, ['class' => 'btn btn-secondary']); 59 60 if (has_capability('mod/feedback:edititems', $this->context)) { 61 $items['usetemplate'] = $this->urlparams + [ 62 'templateid' => $this->templateid 63 ]; 64 } 65 66 $template = $DB->get_record('feedback_template', array('id' => $this->templateid), '*', MUST_EXIST); 67 $systemcontext = context_system::instance(); 68 $showdelete = has_capability('mod/feedback:deletetemplate', $this->context); 69 if ($template->ispublic) { 70 $showdelete = has_capability('mod/feedback:createpublictemplate', $systemcontext) && 71 has_capability('mod/feedback:deletetemplate', $systemcontext); 72 } 73 74 if ($showdelete) { 75 $params = $this->urlparams + $additionalparams + [ 76 'deletetemplate' => $this->templateid, 77 'sesskey' => sesskey() 78 ]; 79 $deleteurl = new moodle_url('/mod/feedback/manage_templates.php', $params); 80 $deleteaction = new confirm_action(get_string('confirmdeletetemplate', 'feedback')); 81 $items['export'] = new action_link($deleteurl, get_string('delete'), $deleteaction, ['class' => 'btn btn-secondary']); 82 } 83 84 return $items; 85 } 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body