]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Filters/TransactionsList.php
c7ef3eadaf26ab9eb044ad39768af3b9fd3b11c3
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Transactions lists filters and paginator
10 * Copyright © 2016 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 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
34 * @link http://galette.tuxfamily.org
35 * @since june, 12th 2016
38 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 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 TransactionsList
extends Pagination
59 public const ORDERBY_DATE
= 0;
60 public const ORDERBY_MEMBER
= 3;
61 public const ORDERBY_AMOUNT
= 5;
64 private $start_date_filter;
65 private $end_date_filter;
66 private $filtre_cotis_adh;
68 protected $list_fields = array(
74 protected $virtuals_list_fields = array(
82 public function __construct()
88 * Returns the field we want to default set order to
90 * @return string field name
92 protected function getDefaultOrder()
94 return self
::ORDERBY_DATE
;
98 * Reinit default parameters
102 public function reinit()
105 $this->start_date_filter
= null;
106 $this->end_date_filter
= null;
107 $this->filtre_cotis_adh
= null;
111 * Global getter method
113 * @param string $name name of the property we want to retrive
115 * @return object the called property
117 public function __get($name)
120 '[TransactionsList] Getting property `' . $name . '`',
124 if (in_array($name, $this->pagination_fields
)) {
125 return parent
::__get($name);
127 if (in_array($name, $this->list_fields
) ||
in_array($name, $this->virtuals_list_fields
)) {
129 case 'start_date_filter':
130 case 'end_date_filter':
132 if ($this->$name !== null) {
133 $d = new \
DateTime($this->$name);
134 return $d->format(__("Y-m-d"));
136 } catch (\Exception
$e) {
137 //oops, we've got a bad date :/
139 'Bad date (' . $this->$name . ') | ' .
146 case 'rstart_date_filter':
147 case 'rend_date_filter':
148 //same as above, but raw format
149 $rname = substr($name, 1);
150 return $this->$rname;
156 '[TransactionsList] Unable to get proprety `' . $name . '`',
164 * Global setter method
166 * @param string $name name of the property we want to assign a value to
167 * @param mixed $value a relevant value for the property
171 public function __set($name, $value)
173 if (in_array($name, $this->pagination_fields
)) {
174 parent
::__set($name, $value);
177 '[TransactionsList] Setting property `' . $name . '`',
182 case 'start_date_filter':
183 case 'end_date_filter':
186 $y = \DateTime
::createFromFormat(__("Y"), $value);
190 if ($name === 'end_date_filter') {
199 $this->$name = $y->format('Y-m-d');
202 $ym = \DateTime
::createFromFormat(__("Y-m"), $value);
203 if ($y === false && $ym !== false) {
205 if ($name === 'end_date_filter') {
206 $day = $ym->format('t');
213 $this->$name = $ym->format('Y-m-d');
216 $d = \DateTime
::createFromFormat(__("Y-m-d"), $value);
217 if ($y === false && $ym === false && $d !== false) {
218 $this->$name = $d->format('Y-m-d');
221 if ($y === false && $ym === false && $d === false) {
229 if ($name === 'start_date_filter') {
230 $field = _T("start date filter");
232 if ($name === 'end_date_filter') {
233 $field = _T("end date filter");
236 throw new \
Exception(
238 array('%field', '%format'),
241 implode(', ', $formats)
243 _T("Unknown date format for %field.<br/>Know formats are: %formats")
250 } catch (\Exception
$e) {
252 'Wrong date format. field: ' . $name .
253 ', value: ' . $value . ', expected fmt: ' .
254 __("Y-m-d") . ' | ' . $e->getMessage(),
261 $this->$name = $value;