]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Filters/TransactionsList.php
477a87d8fab4ac0a44ef9d5d6818aaf1707c9e01
4 * Copyright © 2003-2024 The Galette Team
6 * This file is part of Galette (https://galette.eu).
8 * Galette is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * Galette is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
22 namespace Galette\Filters
;
26 use Galette\Core\Pagination
;
29 * Transactions lists filters and paginator
31 * @author Johan Cwiklinski <johan@x-tnd.be>
33 * @property ?string $start_date_filter
34 * @property ?string $end_date_filter
35 * @property ?integer $filtre_cotis_adh
36 * @property integer|false $filtre_cotis_children
37 * @property string $rstart_date_filter
38 * @property string $rend_date_filter
39 * @property ?integer $max_amount
42 class TransactionsList
extends Pagination
44 public const ORDERBY_DATE
= 0;
45 public const ORDERBY_MEMBER
= 3;
46 public const ORDERBY_AMOUNT
= 5;
47 public const ORDERBY_PAYMENT_TYPE
= 7;
48 public const ORDERBY_ID
= 8;
51 private ?
string $start_date_filter = null;
52 private ?
string $end_date_filter = null;
53 private ?
int $filtre_cotis_adh = null;
54 private int|
false $filtre_cotis_children = false;
55 private ?
int $max_amount = null;
57 /** @var array<string> */
58 protected array $list_fields = array(
62 'filtre_cotis_children'
65 /** @var array<string> */
66 protected array $virtuals_list_fields = array(
74 public function __construct()
80 * Returns the field we want to default set order to
84 protected function getDefaultOrder(): int|
string
86 return self
::ORDERBY_DATE
;
90 * Reinit default parameters
94 public function reinit(): void
97 $this->start_date_filter
= null;
98 $this->end_date_filter
= null;
99 $this->filtre_cotis_adh
= null;
100 $this->filtre_cotis_children
= false;
104 * Global getter method
106 * @param string $name name of the property we want to retrieve
108 * @return mixed the called property
110 public function __get(string $name)
113 '[TransactionsList] Getting property `' . $name . '`',
117 if (in_array($name, $this->pagination_fields
)) {
118 return parent
::__get($name);
120 if (in_array($name, $this->list_fields
) ||
in_array($name, $this->virtuals_list_fields
)) {
122 case 'start_date_filter':
123 case 'end_date_filter':
124 if ($this->$name === null) {
128 $d = \DateTime
::createFromFormat(__("Y-m-d"), $this->$name);
130 //try with non localized date
131 $d = \DateTime
::createFromFormat("Y-m-d", $this->$name);
133 throw new \
Exception('Incorrect format');
136 return $d->format(__("Y-m-d"));
137 } catch (Throwable
$e) {
138 //oops, we've got a bad date :/
140 'Bad date (' . $this->$name . ') | ' .
146 case 'rstart_date_filter':
147 case 'rend_date_filter':
148 //same as above, but raw format
149 $rname = substr($name, 1);
150 return $this->$rname;
156 '[TransactionsList] Unable to get property `' . $name . '`',
164 * Global isset method
165 * Required for twig to access properties via __get
167 * @param string $name name of the property we want to retrieve
171 public function __isset(string $name): bool
173 if (in_array($name, $this->pagination_fields
)) {
175 } elseif (in_array($name, $this->list_fields
) ||
in_array($name, $this->virtuals_list_fields
)) {
183 * Global setter method
185 * @param string $name name of the property we want to assign a value to
186 * @param mixed $value a relevant value for the property
190 public function __set(string $name, $value): void
192 if (in_array($name, $this->pagination_fields
)) {
193 parent
::__set($name, $value);
196 '[TransactionsList] Setting property `' . $name . '`',
201 case 'start_date_filter':
202 case 'end_date_filter':
205 $y = \DateTime
::createFromFormat(__("Y"), $value);
209 if ($name === 'end_date_filter') {
214 (int)$y->format('Y'),
218 $this->$name = $y->format('Y-m-d');
221 $ym = \DateTime
::createFromFormat(__("Y-m"), $value);
222 if ($y === false && $ym !== false) {
224 if ($name === 'end_date_filter') {
225 $day = (int)$ym->format('t');
228 (int)$ym->format('Y'),
229 (int)$ym->format('m'),
232 $this->$name = $ym->format('Y-m-d');
235 $d = \DateTime
::createFromFormat(__("Y-m-d"), $value);
236 if ($y === false && $ym === false && $d !== false) {
237 $this->$name = $d->format('Y-m-d');
240 if ($y === false && $ym === false && $d === false) {
248 if ($name === 'start_date_filter') {
249 $field = _T("start date filter");
251 if ($name === 'end_date_filter') {
252 $field = _T("end date filter");
255 throw new \
Exception(
257 //TRANS: %1$s is field name, %2$s is list of known date formats
258 _T('Unknown date format for %1$s.<br/>Know formats are: %2$s'),
260 implode(', ', $formats)
267 } catch (Throwable
$e) {
269 'Wrong date format. field: ' . $name .
270 ', value: ' . $value . ', expected fmt: ' .
271 __("Y-m-d") . ' | ' . $e->getMessage(),
278 $this->$name = $value;