See Release Notes
Long Term Support Release
Differences Between: [Versions 400 and 401]
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 $selectmenu = new \url_select($menu, $this->currenturl->out(false), null, 'mod_lesson_override_select'); 73 $selectmenu->label = get_string('manageoverrides', 'mod_lesson'); 74 $selectmenu->labelattributes = ['class' => 'sr-only']; 75 return $selectmenu; 76 } 77 78 /** 79 * Data for use with a template. 80 * 81 * @param \renderer_base $output renderer base output. 82 * @return array Said data. 83 */ 84 public function export_for_template(\renderer_base $output): array { 85 global $PAGE; 86 87 $type = $this->currenturl->get_param('mode'); 88 if ($type == 'user') { 89 $text = get_string('addnewuseroverride', 'mod_lesson'); 90 } else { 91 $text = get_string('addnewgroupoverride', 'mod_lesson'); 92 } 93 $action = ($type == 'user') ? 'adduser' : 'addgroup'; 94 $urlselect = $this->create_override_select_menu(); 95 $data = [ 96 'urlselect' => $urlselect->export_for_template($output) 97 ]; 98 if ($this->canoverride) { 99 $data['addoverride'] = [ 100 'text' => $text, 101 'link' => (new moodle_url('/mod/lesson/overrideedit.php', [ 102 'cmid' => $this->currenturl->get_param('cmid'), 103 'action' => $action 104 ]))->out(false) 105 ]; 106 } 107 $data['heading'] = get_string($type == 'user' ? 'useroverrides' : 'groupoverrides', 'mod_lesson'); 108 $data['headinglevel'] = $PAGE->activityheader->get_heading_level(); 109 return $data; 110 } 111 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body