Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]
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 * Output the override action menu for this activity. 19 * 20 * @package mod_lesson 21 * @copyright 2021 Adrian Greeve <adrian@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace mod_lesson\output; 26 27 use moodle_url; 28 use templatable; 29 use renderable; 30 31 /** 32 * Output the override action menu for this activity. 33 * 34 * @package mod_lesson 35 * @copyright 2021 Adrian Greeve <adrian@moodle.com> 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class override_action_menu implements templatable, renderable { 39 40 /** @var int The course module ID. */ 41 protected $cmid; 42 /** @var moodle_url The current url for the page. */ 43 protected $currenturl; 44 /** @var bool Whether can add user or group override (depending on the override type). */ 45 protected $canoverride; 46 47 /** 48 * Constructor for this object. 49 * 50 * @param int $cmid The course module ID. 51 * @param moodle_url $currenturl The current url for the page. 52 * @param bool $canoverride Whether can add user or group override (depending on the override type). 53 */ 54 public function __construct(int $cmid, moodle_url $currenturl, bool $canoverride = false) { 55 $this->cmid = $cmid; 56 $this->currenturl = $currenturl; 57 $this->canoverride = $canoverride; 58 } 59 60 /** 61 * Creates a select menu for the override options. 62 * 63 * @return \url_select The override select. 64 */ 65 protected function create_override_select_menu(): \url_select { 66 $userlink = new moodle_url('/mod/lesson/overrides.php', ['cmid' => $this->cmid, 'mode' => 'user']); 67 $grouplink = new moodle_url('/mod/lesson/overrides.php', ['cmid' => $this->cmid, 'mode' => 'group']); 68 $menu = [ 69 $userlink->out(false) => get_string('useroverrides', 'mod_lesson'), 70 $grouplink->out(false) => get_string('groupoverrides', 'mod_lesson'), 71 ]; 72 return new \url_select($menu, $this->currenturl->out(false), null, 'mod_lesson_override_select'); 73 } 74 75 /** 76 * Data for use with a template. 77 * 78 * @param \renderer_base $output renderer base output. 79 * @return array Said data. 80 */ 81 public function export_for_template(\renderer_base $output): array { 82 $type = $this->currenturl->get_param('mode'); 83 if ($type == 'user') { 84 $text = get_string('addnewuseroverride', 'mod_lesson'); 85 } else { 86 $text = get_string('addnewgroupoverride', 'mod_lesson'); 87 } 88 $action = ($type == 'user') ? 'adduser' : 'addgroup'; 89 $urlselect = $this->create_override_select_menu(); 90 $data = [ 91 'urlselect' => $urlselect->export_for_template($output) 92 ]; 93 if ($this->canoverride) { 94 $data['addoverride'] = [ 95 'text' => $text, 96 'link' => (new moodle_url('/mod/lesson/overrideedit.php', [ 97 'cmid' => $this->currenturl->get_param('cmid'), 98 'action' => $action 99 ]))->out(false) 100 ]; 101 } 102 $data['heading'] = get_string($type == 'user' ? 'useroverrides' : 'groupoverrides', 'mod_lesson'); 103 return $data; 104 } 105 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body