See Release Notes
Long Term Support Release
Differences Between: [Versions 400 and 401] [Versions 401 and 402] [Versions 401 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 declare(strict_types=1); 18 19 namespace core_reportbuilder\output; 20 21 use core_external; 22 use html_writer; 23 use moodle_url; 24 use core\output\inplace_editable; 25 use core_reportbuilder\permission; 26 use core_reportbuilder\local\models\report; 27 28 defined('MOODLE_INTERNAL') || die; 29 30 global $CFG; 31 require_once("{$CFG->libdir}/external/externallib.php"); 32 33 /** 34 * Report name editable component 35 * 36 * @package core_reportbuilder 37 * @copyright 2021 Paul Holden <paulh@moodle.com> 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class report_name_editable extends inplace_editable { 41 42 /** 43 * Class constructor 44 * 45 * @param int $reportid 46 * @param report|null $report The report persistent, note that in addition to id/name properties being present we also 47 * require the following to be correctly set in order to perform permission checks: contextid/type/usercreated 48 */ 49 public function __construct(int $reportid, ?report $report = null) { 50 if ($report === null) { 51 $report = new report($reportid); 52 } 53 54 $editable = permission::can_edit_report($report); 55 56 $url = $editable 57 ? new moodle_url('/reportbuilder/edit.php', ['id' => $report->get('id')]) 58 : new moodle_url('/reportbuilder/view.php', ['id' => $report->get('id')]); 59 60 $displayvalue = html_writer::link($url, $report->get_formatted_name()); 61 62 parent::__construct('core_reportbuilder', 'reportname', $report->get('id'), $editable, $displayvalue, $report->get('name'), 63 get_string('editreportname', 'core_reportbuilder')); 64 } 65 66 /** 67 * Update report persistent and return self, called from inplace_editable callback 68 * 69 * @param int $reportid 70 * @param string $value 71 * @return self 72 */ 73 public static function update(int $reportid, string $value): self { 74 $report = new report($reportid); 75 76 core_external::validate_context($report->get_context()); 77 permission::require_can_edit_report($report); 78 79 $value = trim(clean_param($value, PARAM_TEXT)); 80 if ($value !== '') { 81 $report 82 ->set('name', $value) 83 ->update(); 84 } 85 86 return new self(0, $report); 87 } 88 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body