]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Filters/HistoryList.php
838e979a001a6309fb451e127b41f8bb5c71b3ad
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * History 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 * History 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 HistoryList
extends Pagination
58 const ORDERBY_DATE
= 0;
60 const ORDERBY_USER
= 2;
61 const ORDERBY_ACTION
= 3;
64 private $start_date_filter = null;
65 private $end_date_filter = null;
66 private $user_filter = 0;
67 private $action_filter = null;
69 protected $list_fields = array(
71 'raw_start_date_filter',
73 'raw_end_date_filter',
81 public function __construct()
87 * Returns the field we want to default set order to
89 * @return string field name
91 protected function getDefaultOrder()
93 return self
::ORDERBY_DATE
;
97 * Return the default direction for ordering
99 * @return string ASC or DESC
101 protected function getDefaultDirection()
103 return self
::ORDER_DESC
;
107 * Reinit default parameters
111 public function reinit()
114 $this->start_date_filter
= null;
115 $this->end_date_filter
= null;
116 $this->user_filter
= 0;
117 $this->action_filter
= null;
121 * Global getter method
123 * @param string $name name of the property we want to retrive
125 * @return object the called property
127 public function __get($name)
130 '[HistoryList] Getting property `' . $name . '`',
134 if (in_array($name, $this->pagination_fields
)) {
135 return parent
::__get($name);
137 if (in_array($name, $this->list_fields
)) {
139 case 'raw_start_date_filter':
140 return $this->start_date_filter
;
142 case 'raw_end_date_filter':
143 return $this->end_date_filter
;
145 case 'start_date_filter':
146 case 'end_date_filter':
148 if ($this->$name !== null) {
149 $d = new \
DateTime($this->$name);
150 return $d->format(__("Y-m-d"));
152 } catch (\Exception
$e) {
153 //oops, we've got a bad date :/
155 'Bad date (' . $this->$name . ') | ' .
167 '[HistoryList] Unable to get proprety `' .$name . '`',
175 * Global setter method
177 * @param string $name name of the property we want to assign a value to
178 * @param object $value a relevant value for the property
182 public function __set($name, $value)
184 if (in_array($name, $this->pagination_fields
)) {
185 parent
::__set($name, $value);
188 '[HistoryList] Setting property `' . $name . '`',
193 case 'start_date_filter':
194 case 'end_date_filter':
197 $y = \DateTime
::createFromFormat(__("Y"), $value);
201 if ($name === 'end_date_filter') {
210 $this->$name = $y->format('Y-m-d');
213 $ym = \DateTime
::createFromFormat(__("Y-m"), $value);
214 if ($y === false && $ym !== false) {
216 if ($name === 'end_date_filter') {
217 $day = $ym->format('t');
224 $this->$name = $ym->format('Y-m-d');
227 $d = \DateTime
::createFromFormat(__("Y-m-d"), $value);
228 if ($y === false && $ym === false && $d !== false) {
229 $this->$name = $d->format('Y-m-d');
232 if ($y === false && $ym === false && $d === false) {
240 if ($name === 'start_date_filter') {
241 $field = _T("start date filter");
243 if ($name === 'end_date_filter') {
244 $field = _T("end date filter");
247 throw new \
Exception(
249 array('%field', '%format'),
252 implode(', ', $formats)
254 _T("Unknown date format for %field.<br/>Know formats are: %formats")
261 } catch (\Exception
$e) {
263 'Wrong date format. field: ' . $key .
264 ', value: ' . $value . ', expected fmt: ' .
265 __("Y-m-d") . ' | ' . $e->getMessage(),
272 $this->$name = $value;