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 declare(strict_types=1); 18 19 namespace core_reportbuilder\output; 20 21 use core\output\inplace_editable; 22 use core_external\external_api; 23 use core_reportbuilder\permission; 24 use core_reportbuilder\local\models\schedule; 25 26 /** 27 * Schedule name editable component 28 * 29 * @package core_reportbuilder 30 * @copyright 2021 Paul Holden <paulh@moodle.com> 31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 32 */ 33 class schedule_name_editable extends inplace_editable { 34 35 /** 36 * Class constructor 37 * 38 * @param int $scheduleid 39 * @param schedule|null $schedule 40 */ 41 public function __construct(int $scheduleid, ?schedule $schedule = null) { 42 if ($schedule === null) { 43 $schedule = new schedule($scheduleid); 44 } 45 46 $report = $schedule->get_report(); 47 $editable = permission::can_edit_report($report); 48 49 $displayvalue = $schedule->get_formatted_name($report->get_context()); 50 51 parent::__construct('core_reportbuilder', 'schedulename', $schedule->get('id'), $editable, $displayvalue, 52 $schedule->get('name'), get_string('editschedulename', 'core_reportbuilder')); 53 } 54 55 /** 56 * Update schedule persistent and return self, called from inplace_editable callback 57 * 58 * @param int $scheduleid 59 * @param string $value 60 * @return self 61 */ 62 public static function update(int $scheduleid, string $value): self { 63 $schedule = new schedule($scheduleid); 64 65 $report = $schedule->get_report(); 66 67 external_api::validate_context($report->get_context()); 68 permission::require_can_edit_report($report); 69 70 $value = trim(clean_param($value, PARAM_TEXT)); 71 if ($value !== '') { 72 $schedule 73 ->set('name', $value) 74 ->update(); 75 } 76 77 return new self(0, $schedule); 78 } 79 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body