]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Filters/ContributionsList.php
b2e9ef2c84b528644342881218ac870daade8d1a
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Contributions lists filters and paginator
10 * Copyright © 2016-2021 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-202 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 * Contributions lists filters and paginator
46 * @name ContributionsList
50 * @author Johan Cwiklinski <johan@x-tnd.be>
51 * @copyright 2016-2021 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
56 class ContributionsList
extends Pagination
58 public const ORDERBY_DATE
= 0;
59 public const ORDERBY_BEGIN_DATE
= 1;
60 public const ORDERBY_END_DATE
= 2;
61 public const ORDERBY_MEMBER
= 3;
62 public const ORDERBY_TYPE
= 4;
63 public const ORDERBY_AMOUNT
= 5;
64 public const ORDERBY_DURATION
= 6;
65 public const ORDERBY_PAYMENT_TYPE
= 7;
66 public const ORDERBY_ID
= 8;
68 public const DATE_BEGIN
= 0;
69 public const DATE_END
= 1;
70 public const DATE_RECORD
= 2;
73 private $date_field = null;
74 private $start_date_filter = null;
75 private $end_date_filter = null;
76 private $payment_type_filter = null;
77 private $filtre_cotis_adh = null;
78 private $filtre_transactions = null;
80 private $from_transaction = false;
81 private $max_amount = null;
83 protected $list_fields = array(
88 'payment_type_filter',
89 'filtre_transactions',
94 protected $virtuals_list_fields = array(
100 * Default constructor
102 public function __construct()
108 * Returns the field we want to default set order to
110 * @return string field name
112 protected function getDefaultOrder()
114 return self
::ORDERBY_BEGIN_DATE
;
118 * Reinit default parameters
122 public function reinit()
125 $this->date_field
= self
::DATE_BEGIN
;
126 $this->start_date_filter
= null;
127 $this->end_date_filter
= null;
128 $this->payment_type_filter
= null;
129 $this->filtre_transactions
= null;
130 $this->filtre_cotis_adh
= null;
131 $this->from_transaction
= false;
132 $this->max_amount
= null;
136 * Global getter method
138 * @param string $name name of the property we want to retrive
140 * @return object the called property
142 public function __get($name)
145 '[ContributionsList] Getting property `' . $name . '`',
149 if (in_array($name, $this->pagination_fields
)) {
150 return parent
::__get($name);
152 if (in_array($name, $this->list_fields
) ||
in_array($name, $this->virtuals_list_fields
)) {
154 case 'start_date_filter':
155 case 'end_date_filter':
157 $d = \DateTime
::createFromFormat(__("Y-m-d"), $this->$name);
159 //try with non localized date
160 $d = \DateTime
::createFromFormat("Y-m-d", $this->$name);
162 throw new \
Exception('Incorrect format');
165 return $d->format(__("Y-m-d"));
166 } catch (Throwable
$e) {
167 //oops, we've got a bad date :/
169 'Bad date (' . $this->$name . ') | ' .
176 case 'rstart_date_filter':
177 case 'rend_date_filter':
178 //same as above, but raw format
179 $rname = substr($name, 1);
180 return $this->$rname;
186 '[ContributionsList] Unable to get proprety `' . $name . '`',
194 * Global setter method
196 * @param string $name name of the property we want to assign a value to
197 * @param object $value a relevant value for the property
201 public function __set($name, $value)
203 if (in_array($name, $this->pagination_fields
)) {
204 parent
::__set($name, $value);
207 '[ContributionsList] Setting property `' . $name . '`',
212 case 'start_date_filter':
213 case 'end_date_filter':
216 $y = \DateTime
::createFromFormat(__("Y"), $value);
220 if ($name === 'end_date_filter') {
229 $this->$name = $y->format('Y-m-d');
232 $ym = \DateTime
::createFromFormat(__("Y-m"), $value);
233 if ($y === false && $ym !== false) {
235 if ($name === 'end_date_filter') {
236 $day = $ym->format('t');
243 $this->$name = $ym->format('Y-m-d');
246 $d = \DateTime
::createFromFormat(__("Y-m-d"), $value);
247 if ($y === false && $ym === false && $d !== false) {
248 $this->$name = $d->format('Y-m-d');
251 if ($y === false && $ym === false && $d === false) {
259 if ($name === 'start_date_filter') {
260 $field = _T("start date filter");
262 if ($name === 'end_date_filter') {
263 $field = _T("end date filter");
266 throw new \
Exception(
268 array('%field', '%format'),
271 implode(', ', $formats)
273 _T("Unknown date format for %field.<br/>Know formats are: %formats")
280 } catch (Throwable
$e) {
282 'Wrong date format. field: ' . $key .
283 ', value: ' . $value . ', expected fmt: ' .
284 __("Y-m-d") . ' | ' . $e->getMessage(),
291 $this->$name = $value;