Differences Between: [Versions 400 and 402] [Versions 401 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 * Output the action buttons 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 core\output\notification; 28 use moodle_url; 29 use templatable; 30 use renderable; 31 use single_button; 32 33 /** 34 * Output the action buttons for this activity. 35 * 36 * @package mod_lesson 37 * @copyright 2021 Adrian Greeve <adrian@moodle.com> 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class edit_action_buttons implements templatable, renderable { 41 42 /** @var \lesson The lesson object. */ 43 protected $lesson; 44 /** @var int The currently viewed lesson page id. */ 45 protected $currentpage; 46 47 /** 48 * Constructor for this object. 49 * 50 * @param \lesson $lesson The lesson object. 51 * @param int|null $currentpage The current lesson page that is being viewed 52 */ 53 public function __construct(\lesson $lesson, ?int $currentpage = null) { 54 $this->lesson = $lesson; 55 $this->currentpage = $currentpage; 56 } 57 58 /** 59 * Sets the current page being viewed. 60 * 61 * @param int|null $page 62 */ 63 public function set_currentpage(?int $page) { 64 $this->currentpage = $page; 65 } 66 67 /** 68 * Data for use with a template. 69 * 70 * @param \renderer_base $output Renderer information. 71 * @return array Said data. 72 */ 73 public function export_for_template(\renderer_base $output) { 74 global $PAGE; 75 76 $data = []; 77 78 // A shortcut to edit the lesson's question page. 79 if (has_capability('mod/lesson:edit', $this->lesson->context) && 80 !empty($this->currentpage) && $this->currentpage != LESSON_EOL) { 81 $url = new moodle_url('/mod/lesson/editpage.php', [ 82 'id' => $this->lesson->get_cm()->id, 83 'pageid' => $this->currentpage, 84 'edit' => 1, 85 'returnto' => $PAGE->url->out_as_local_url(false) 86 ]); 87 $editcontent = new single_button($url, get_string('editpagecontent', 'lesson')); 88 $data['editcontents']['button'] = $editcontent->export_for_template($output); 89 } 90 91 if ($this->lesson->can_manage()) { 92 $url = new moodle_url('/mod/lesson/edit.php', ['id' => $this->lesson->get_cm()->id]); 93 $editbutton = new single_button($url, get_string('editlesson', 'mod_lesson'), 'get', single_button::BUTTON_PRIMARY); 94 $url = new moodle_url('/mod/lesson/essay.php', ['id' => $this->lesson->get_cm()->id]); 95 $essaybutton = new single_button($url, get_string('manualgrading', 'mod_lesson'), 'get'); 96 $data += [ 97 'edit' => [ 98 'button' => $editbutton->export_for_template($output), 99 ], 100 'gradeessays' => [ 101 'button' => $essaybutton->export_for_template($output), 102 ] 103 ]; 104 } 105 106 // Standard notification to indicate the lesson is being previewed. 107 if ($data) { 108 $message = new notification(get_string('lessonbeingpreviewed', 'mod_lesson'), notification::NOTIFY_INFO); 109 $data['notification'] = $message->export_for_template($output); 110 } 111 return $data; 112 } 113 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body