]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Filters/TransactionsList.php
cea4d8069a173c8e7f33883bbd84eae1d51810ff
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 retrive
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':
142 if ($this->$name !== null) {
143 $d = new \
DateTime($this->$name);
144 return $d->format(__("Y-m-d"));
146 } catch (Throwable
$e) {
147 //oops, we've got a bad date :/
149 'Bad date (' . $this->$name . ') | ' .
156 case 'rstart_date_filter':
157 case 'rend_date_filter':
158 //same as above, but raw format
159 $rname = substr($name, 1);
160 return $this->$rname;
166 '[TransactionsList] Unable to get property `' . $name . '`',
174 * Global isset method
175 * Required for twig to access properties via __get
177 * @param string $name name of the property we want to retrieve
181 public function __isset($name)
183 if (in_array($name, $this->pagination_fields
)) {
185 } elseif (in_array($name, $this->list_fields
) ||
in_array($name, $this->virtuals_list_fields
)) {
193 * Global setter method
195 * @param string $name name of the property we want to assign a value to
196 * @param mixed $value a relevant value for the property
200 public function __set($name, $value)
202 if (in_array($name, $this->pagination_fields
)) {
203 parent
::__set($name, $value);
206 '[TransactionsList] Setting property `' . $name . '`',
211 case 'start_date_filter':
212 case 'end_date_filter':
215 $y = \DateTime
::createFromFormat(__("Y"), $value);
219 if ($name === 'end_date_filter') {
228 $this->$name = $y->format('Y-m-d');
231 $ym = \DateTime
::createFromFormat(__("Y-m"), $value);
232 if ($y === false && $ym !== false) {
234 if ($name === 'end_date_filter') {
235 $day = $ym->format('t');
242 $this->$name = $ym->format('Y-m-d');
245 $d = \DateTime
::createFromFormat(__("Y-m-d"), $value);
246 if ($y === false && $ym === false && $d !== false) {
247 $this->$name = $d->format('Y-m-d');
250 if ($y === false && $ym === false && $d === false) {
258 if ($name === 'start_date_filter') {
259 $field = _T("start date filter");
261 if ($name === 'end_date_filter') {
262 $field = _T("end date filter");
265 throw new \
Exception(
267 array('%field', '%formats'),
270 implode(', ', $formats)
272 _T("Unknown date format for %field.<br/>Know formats are: %formats")
279 } catch (Throwable
$e) {
281 'Wrong date format. field: ' . $name .
282 ', value: ' . $value . ', expected fmt: ' .
283 __("Y-m-d") . ' | ' . $e->getMessage(),
290 $this->$name = $value;