]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Filters/TransactionsList.php
2c24384cc9233e2ab9452295fd5ea44092a6881d
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Transactions lists filters and paginator
10 * Copyright © 2016-2023 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2016-2023 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @link http://galette.tuxfamily.org
34 * @since june, 12th 2016
37 namespace Galette\Filters
;
41 use Galette\Core\Pagination
;
44 * Transactions lists filters and paginator
46 * @name TransactionsList
50 * @author Johan Cwiklinski <johan@x-tnd.be>
51 * @copyright 2016-2023 The Galette Team
52 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
53 * @link http://galette.tuxfamily.org
55 * @property ?string $start_date_filter
56 * @property ?string $end_date_filter
57 * @property ?integer $filtre_cotis_adh
58 * @property boolean $filtre_cotis_children
59 * @property string $rstart_date_filter
60 * @property string $rend_date_filter
63 class TransactionsList
extends Pagination
65 public const ORDERBY_DATE
= 0;
66 public const ORDERBY_MEMBER
= 3;
67 public const ORDERBY_AMOUNT
= 5;
68 public const ORDERBY_ID
= 8;
71 private $start_date_filter;
72 private $end_date_filter;
73 private $filtre_cotis_adh;
74 private $filtre_cotis_children = false;
76 protected $list_fields = array(
80 'filtre_cotis_children'
83 protected $virtuals_list_fields = array(
91 public function __construct()
97 * Returns the field we want to default set order to
101 protected function getDefaultOrder()
103 return self
::ORDERBY_DATE
;
107 * Reinit default parameters
111 public function reinit()
114 $this->start_date_filter
= null;
115 $this->end_date_filter
= null;
116 $this->filtre_cotis_adh
= null;
117 $this->filtre_cotis_children
= false;
121 * Global getter method
123 * @param string $name name of the property we want to retrieve
125 * @return mixed the called property
127 public function __get($name)
130 '[TransactionsList] Getting property `' . $name . '`',
134 if (in_array($name, $this->pagination_fields
)) {
135 return parent
::__get($name);
137 if (in_array($name, $this->list_fields
) ||
in_array($name, $this->virtuals_list_fields
)) {
139 case 'start_date_filter':
140 case 'end_date_filter':
141 if ($this->$name === null) {
145 $d = \DateTime
::createFromFormat(__("Y-m-d"), $this->$name);
147 //try with non localized date
148 $d = \DateTime
::createFromFormat("Y-m-d", $this->$name);
150 throw new \
Exception('Incorrect format');
153 return $d->format(__("Y-m-d"));
154 } catch (Throwable
$e) {
155 //oops, we've got a bad date :/
157 'Bad date (' . $this->$name . ') | ' .
164 case 'rstart_date_filter':
165 case 'rend_date_filter':
166 //same as above, but raw format
167 $rname = substr($name, 1);
168 return $this->$rname;
174 '[TransactionsList] Unable to get property `' . $name . '`',
182 * Global isset method
183 * Required for twig to access properties via __get
185 * @param string $name name of the property we want to retrieve
189 public function __isset($name)
191 if (in_array($name, $this->pagination_fields
)) {
193 } elseif (in_array($name, $this->list_fields
) ||
in_array($name, $this->virtuals_list_fields
)) {
201 * Global setter method
203 * @param string $name name of the property we want to assign a value to
204 * @param mixed $value a relevant value for the property
208 public function __set($name, $value)
210 if (in_array($name, $this->pagination_fields
)) {
211 parent
::__set($name, $value);
214 '[TransactionsList] Setting property `' . $name . '`',
219 case 'start_date_filter':
220 case 'end_date_filter':
223 $y = \DateTime
::createFromFormat(__("Y"), $value);
227 if ($name === 'end_date_filter') {
236 $this->$name = $y->format('Y-m-d');
239 $ym = \DateTime
::createFromFormat(__("Y-m"), $value);
240 if ($y === false && $ym !== false) {
242 if ($name === 'end_date_filter') {
243 $day = $ym->format('t');
250 $this->$name = $ym->format('Y-m-d');
253 $d = \DateTime
::createFromFormat(__("Y-m-d"), $value);
254 if ($y === false && $ym === false && $d !== false) {
255 $this->$name = $d->format('Y-m-d');
258 if ($y === false && $ym === false && $d === false) {
266 if ($name === 'start_date_filter') {
267 $field = _T("start date filter");
269 if ($name === 'end_date_filter') {
270 $field = _T("end date filter");
273 throw new \
Exception(
275 array('%field', '%formats'),
278 implode(', ', $formats)
280 _T("Unknown date format for %field.<br/>Know formats are: %formats")
287 } catch (Throwable
$e) {
289 'Wrong date format. field: ' . $name .
290 ', value: ' . $value . ', expected fmt: ' .
291 __("Y-m-d") . ' | ' . $e->getMessage(),
298 $this->$name = $value;