]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Filters/TransactionsList.php
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): mixed
112 if (in_array($name, $this->pagination_fields
)) {
113 return parent
::__get($name);
115 if (in_array($name, $this->list_fields
) ||
in_array($name, $this->virtuals_list_fields
)) {
117 case 'start_date_filter':
118 case 'end_date_filter':
119 if ($this->$name === null) {
123 $d = \DateTime
::createFromFormat(__("Y-m-d"), $this->$name);
125 //try with non localized date
126 $d = \DateTime
::createFromFormat("Y-m-d", $this->$name);
128 throw new \
Exception('Incorrect format');
131 return $d->format(__("Y-m-d"));
132 } catch (Throwable
$e) {
133 //oops, we've got a bad date :/
135 'Bad date (' . $this->$name . ') | ' .
141 case 'rstart_date_filter':
142 case 'rend_date_filter':
143 //same as above, but raw format
144 $rname = substr($name, 1);
145 return $this->$rname;
152 throw new \
RuntimeException(
154 'Unable to get property "%s::%s"!',
162 * Global isset method
163 * Required for twig to access properties via __get
165 * @param string $name name of the property we want to retrieve
169 public function __isset(string $name): bool
171 if (in_array($name, $this->pagination_fields
)) {
173 } elseif (in_array($name, $this->list_fields
) ||
in_array($name, $this->virtuals_list_fields
)) {
181 * Global setter method
183 * @param string $name name of the property we want to assign a value to
184 * @param mixed $value a relevant value for the property
188 public function __set(string $name, mixed $value): void
190 if (in_array($name, $this->pagination_fields
)) {
191 parent
::__set($name, $value);
194 '[TransactionsList] Setting property `' . $name . '`',
199 case 'start_date_filter':
200 case 'end_date_filter':
203 $y = \DateTime
::createFromFormat(__("Y"), $value);
207 if ($name === 'end_date_filter') {
212 (int)$y->format('Y'),
216 $this->$name = $y->format('Y-m-d');
219 $ym = \DateTime
::createFromFormat(__("Y-m"), $value);
220 if ($y === false && $ym !== false) {
222 if ($name === 'end_date_filter') {
223 $day = (int)$ym->format('t');
226 (int)$ym->format('Y'),
227 (int)$ym->format('m'),
230 $this->$name = $ym->format('Y-m-d');
233 $d = \DateTime
::createFromFormat(__("Y-m-d"), $value);
234 if ($y === false && $ym === false && $d !== false) {
235 $this->$name = $d->format('Y-m-d');
238 if ($y === false && $ym === false && $d === false) {
246 if ($name === 'start_date_filter') {
247 $field = _T("start date filter");
249 if ($name === 'end_date_filter') {
250 $field = _T("end date filter");
253 throw new \
Exception(
255 //TRANS: %1$s is field name, %2$s is list of known date formats
256 _T('Unknown date format for %1$s.<br/>Know formats are: %2$s'),
258 implode(', ', $formats)
265 } catch (Throwable
$e) {
267 'Wrong date format. field: ' . $name .
268 ', value: ' . $value . ', expected fmt: ' .
269 __("Y-m-d") . ' | ' . $e->getMessage(),
276 $this->$name = $value;