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