]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Filters/ScheduledPaymentsList.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 * Contributions 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 $date_field
36 * @property ?integer $payment_type_filter
37 * @property integer|false $from_contribution
38 * @property string $rstart_date_filter
39 * @property string $rend_date_filter
40 * @property array $selected
43 class ScheduledPaymentsList
extends Pagination
45 public const ORDERBY_DATE
= 0;
46 public const ORDERBY_MEMBER
= 1;
47 public const ORDERBY_SCHEDULED_DATE
= 2;
48 public const ORDERBY_CONTRIBUTION
= 3;
49 public const ORDERBY_AMOUNT
= 5;
50 public const ORDERBY_PAYMENT_TYPE
= 7;
51 public const ORDERBY_ID
= 8;
53 public const DATE_RECORD
= 0;
55 public const DATE_SCHEDULED
= 1;
58 private ?
int $date_field = null;
59 private ?
string $start_date_filter = null;
60 private ?
string $end_date_filter = null;
61 private ?
int $payment_type_filter = null;
62 private int|
false $from_contribution = false;
65 /** @var array<int> */
66 private array $selected = [];
68 /** @var array<string> */
69 protected array $list_fields = array(
73 'payment_type_filter',
78 /** @var array<string> */
79 protected array $virtuals_list_fields = array(
87 public function __construct()
93 * Returns the field we want to default set order to
97 protected function getDefaultOrder(): int|
string
99 return self
::ORDERBY_SCHEDULED_DATE
;
103 * Reinit default parameters
105 * @param boolean $ajax Called form an ajax query
109 public function reinit(bool $ajax = false): void
112 $this->date_field
= self
::DATE_SCHEDULED
;
113 $this->start_date_filter
= null;
114 $this->end_date_filter
= null;
115 $this->payment_type_filter
= null;
116 $this->selected
= [];
118 if ($ajax === false) {
119 $this->from_contribution
= false;
124 * Global getter method
126 * @param string $name name of the property we want to retrieve
128 * @return mixed the called property
130 public function __get(string $name): mixed
132 if (in_array($name, $this->pagination_fields
)) {
133 return parent
::__get($name);
135 if (in_array($name, $this->list_fields
) ||
in_array($name, $this->virtuals_list_fields
)) {
137 case 'start_date_filter':
138 case 'end_date_filter':
139 if ($this->$name === null) {
143 $d = \DateTime
::createFromFormat(__("Y-m-d"), $this->$name);
145 //try with non localized date
146 $d = \DateTime
::createFromFormat("Y-m-d", $this->$name);
148 throw new \
Exception('Incorrect format');
151 return $d->format(__("Y-m-d"));
152 } catch (Throwable
$e) {
153 //oops, we've got a bad date :/
155 'Bad date (' . $this->$name . ') | ' .
161 case 'rstart_date_filter':
162 case 'rend_date_filter':
163 //same as above, but raw format
164 $rname = substr($name, 1);
165 return $this->$rname;
172 throw new \
RuntimeException(
174 'Unable to get property "%s::%s"!',
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(string $name): bool
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(string $name, mixed $value): void
210 if (in_array($name, $this->pagination_fields
)) {
211 parent
::__set($name, $value);
214 case 'start_date_filter':
215 case 'end_date_filter':
218 $y = \DateTime
::createFromFormat(__("Y"), $value);
222 if ($name === 'end_date_filter') {
227 (int)$y->format('Y'),
231 $this->$name = $y->format('Y-m-d');
234 $ym = \DateTime
::createFromFormat(__("Y-m"), $value);
235 if ($y === false && $ym !== false) {
237 if ($name === 'end_date_filter') {
238 $day = (int)$ym->format('t');
241 (int)$ym->format('Y'),
242 (int)$ym->format('m'),
245 $this->$name = $ym->format('Y-m-d');
248 $d = \DateTime
::createFromFormat(__("Y-m-d"), $value);
249 if ($y === false && $ym === false && $d !== false) {
250 $this->$name = $d->format('Y-m-d');
253 if ($y === false && $ym === false && $d === false) {
261 if ($name === 'start_date_filter') {
262 $field = _T("start date filter");
264 if ($name === 'end_date_filter') {
265 $field = _T("end date filter");
268 throw new \
Exception(
270 //TRANS: %1$s is field name, %2$s is list of known date formats
271 _T('Unknown date format for %1$s.<br/>Know formats are: %2$s'),
273 implode(', ', $formats)
280 } catch (Throwable
$e) {
282 'Wrong date format. field: ' . $name .
283 ', value: ' . $value . ', expected fmt: ' .
284 __("Y-m-d") . ' | ' . $e->getMessage(),
291 $this->$name = $value;