|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of Galette Helloasso plugin (https://galette-community.github.io/plugin-helloasso). |
| 5 | + * SPDX-FileCopyrightText: Copyright © 2025-2026 The Galette Team |
| 6 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 7 | + */ |
| 8 | + |
| 9 | +declare(strict_types=1); |
| 10 | + |
| 11 | +namespace GaletteHelloasso\Filters; |
| 12 | + |
| 13 | +use Galette\Filters\HistoryList; |
| 14 | +use Analog\Analog; |
| 15 | + |
| 16 | +/** |
| 17 | + * Helloasso History lists filters and paginator |
| 18 | + * |
| 19 | + * @author Johan Cwiklinski <johan@x-tnd.be> |
| 20 | + * @author Guillaume AGNIERAY <dev@agnieray.net> |
| 21 | + * |
| 22 | + * @property ?string $payment_filter |
| 23 | + * @property ?string $payer_filter |
| 24 | + * @property ?string $reason_filter |
| 25 | + * @property ?string $method_filter |
| 26 | + */ |
| 27 | + |
| 28 | +class HelloassoHistoryList extends HistoryList |
| 29 | +{ |
| 30 | + public const int ORDERBY_DATE = 0; |
| 31 | + public const int ORDERBY_PAYMENT = 1; |
| 32 | + public const int ORDERBY_PAYER = 2; |
| 33 | + public const int ORDERBY_MEMBER = 3; |
| 34 | + public const int ORDERBY_REASON = 4; |
| 35 | + public const int ORDERBY_AMOUNT = 5; |
| 36 | + public const int ORDERBY_METHOD = 6; |
| 37 | + public const int ORDERBY_STATE = 7; |
| 38 | + |
| 39 | + //filters |
| 40 | + private ?string $payment_filter = null; |
| 41 | + private ?string $payer_filter = null; |
| 42 | + private ?string $reason_filter = null; |
| 43 | + private ?string $method_filter = null; |
| 44 | + |
| 45 | + /** @var array<string> */ |
| 46 | + protected array $list_fields = [ |
| 47 | + 'start_date_filter', |
| 48 | + 'raw_start_date_filter', |
| 49 | + 'end_date_filter', |
| 50 | + 'raw_end_date_filter', |
| 51 | + 'payment_filter', |
| 52 | + 'payer_filter', |
| 53 | + 'reason_filter', |
| 54 | + 'method_filter' |
| 55 | + ]; |
| 56 | + |
| 57 | + /** |
| 58 | + * Default constructor |
| 59 | + */ |
| 60 | + public function __construct() |
| 61 | + { |
| 62 | + $this->reinit(); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Reinit default parameters |
| 67 | + */ |
| 68 | + public function reinit(): void |
| 69 | + { |
| 70 | + parent::reinit(); |
| 71 | + $this->payment_filter = null; |
| 72 | + $this->payer_filter = null; |
| 73 | + $this->reason_filter = null; |
| 74 | + $this->method_filter = null; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Global getter method |
| 79 | + * |
| 80 | + * @param string $name name of the property we want to retrieve |
| 81 | + * |
| 82 | + * @return mixed the called property |
| 83 | + */ |
| 84 | + public function __get(string $name): mixed |
| 85 | + { |
| 86 | + if (in_array($name, $this->pagination_fields)) { |
| 87 | + return parent::__get($name); |
| 88 | + } elseif (in_array($name, $this->list_fields)) { |
| 89 | + return match ($name) { |
| 90 | + 'raw_start_date_filter' => $this->getDate('start_date_filter', true, false), |
| 91 | + 'raw_end_date_filter' => $this->getDate('end_date_filter', true, false), |
| 92 | + 'start_date_filter', 'end_date_filter' => $this->getDate($name), |
| 93 | + default => $this->$name, |
| 94 | + }; |
| 95 | + } |
| 96 | + |
| 97 | + throw new \RuntimeException( |
| 98 | + sprintf( |
| 99 | + 'Unable to get property "%s::%s"!', |
| 100 | + static::class, |
| 101 | + $name |
| 102 | + ) |
| 103 | + ); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Global isset method |
| 108 | + * Required for twig to access properties via __get |
| 109 | + * |
| 110 | + * @param string $name name of the property we want to retrieve |
| 111 | + */ |
| 112 | + public function __isset(string $name): bool |
| 113 | + { |
| 114 | + return parent::__isset($name); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Global setter method |
| 119 | + * |
| 120 | + * @param string $name name of the property we want to assign a value to |
| 121 | + * @param mixed $value a relevant value for the property |
| 122 | + */ |
| 123 | + public function __set(string $name, mixed $value): void |
| 124 | + { |
| 125 | + if (in_array($name, $this->pagination_fields)) { |
| 126 | + parent::__set($name, $value); |
| 127 | + } else { |
| 128 | + Analog::log( |
| 129 | + '[' . static::class . '] Setting property `' . $name . '`', |
| 130 | + Analog::DEBUG |
| 131 | + ); |
| 132 | + |
| 133 | + switch ($name) { |
| 134 | + case 'start_date_filter': |
| 135 | + case 'end_date_filter': |
| 136 | + $this->setFilterDate($name, $value, $name === 'start_date_filter'); |
| 137 | + break; |
| 138 | + default: |
| 139 | + $this->$name = $value; |
| 140 | + break; |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | +} |
0 commit comments