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