]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Filters/ContributionsList.php
8068bf59047d6a7b29bca5a27596e248e6e2a116
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Contributions 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 * Contributions lists filters and paginator
46 * @name ContributionsList
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 ContributionsList
extends Pagination
59 const ORDERBY_DATE
= 0;
60 const ORDERBY_BEGIN_DATE
= 1;
61 const ORDERBY_END_DATE
= 2;
62 const ORDERBY_MEMBER
= 3;
63 const ORDERBY_TYPE
= 4;
64 const ORDERBY_AMOUNT
= 5;
65 const ORDERBY_DURATION
= 6;
66 const ORDERBY_PAYMENT_TYPE
= 7;
70 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 if ($this->$name !== null) {
158 $d = new \
DateTime($this->$name);
159 return $d->format(__("Y-m-d"));
161 } catch (\Exception
$e) {
162 //oops, we've got a bad date :/
164 'Bad date (' . $this->$name . ') | ' .
171 case 'rstart_date_filter':
172 case 'rend_date_filter':
173 //same as above, but raw format
174 $rname = substr($name, 1);
175 return $this->$rname;
181 '[ContributionsList] Unable to get proprety `' .$name . '`',
189 * Global setter method
191 * @param string $name name of the property we want to assign a value to
192 * @param object $value a relevant value for the property
196 public function __set($name, $value)
198 if (in_array($name, $this->pagination_fields
)) {
199 parent
::__set($name, $value);
202 '[ContributionsList] Setting property `' . $name . '`',
207 case 'start_date_filter':
208 case 'end_date_filter':
211 $y = \DateTime
::createFromFormat(__("Y"), $value);
215 if ($name === 'end_date_filter') {
224 $this->$name = $y->format('Y-m-d');
227 $ym = \DateTime
::createFromFormat(__("Y-m"), $value);
228 if ($y === false && $ym !== false) {
230 if ($name === 'end_date_filter') {
231 $day = $ym->format('t');
238 $this->$name = $ym->format('Y-m-d');
241 $d = \DateTime
::createFromFormat(__("Y-m-d"), $value);
242 if ($y === false && $ym === false && $d !== false) {
243 $this->$name = $d->format('Y-m-d');
246 if ($y === false && $ym === false && $d === false) {
254 if ($name === 'start_date_filter') {
255 $field = _T("start date filter");
257 if ($name === 'end_date_filter') {
258 $field = _T("end date filter");
261 throw new \
Exception(
263 array('%field', '%format'),
266 implode(', ', $formats)
268 _T("Unknown date format for %field.<br/>Know formats are: %formats")
275 } catch (\Exception
$e) {
277 'Wrong date format. field: ' . $key .
278 ', value: ' . $value . ', expected fmt: ' .
279 __("Y-m-d") . ' | ' . $e->getMessage(),
286 $this->$name = $value;