]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Filters/HistoryList.php
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * History lists filters and paginator
10 * Copyright © 2016-2023 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-2023 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 * History lists filters and paginator
46 * @name ContributionsList
50 * @author Johan Cwiklinski <johan@x-tnd.be>
51 * @copyright 2016-2023 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
55 * @property ?string $start_date_filter
56 * @property ?string $raw_start_date_filter
57 * @property ?string $end_date_filter
58 * @property ?string $raw_end_date_filter
59 * @property integer $user_filter
60 * @property ?string $action_filter
63 class HistoryList
extends Pagination
65 public const ORDERBY_DATE
= 0;
66 public const ORDERBY_IP
= 1;
67 public const ORDERBY_USER
= 2;
68 public const ORDERBY_ACTION
= 3;
71 private $start_date_filter = null;
72 private $end_date_filter = null;
73 private $user_filter = 0;
74 private $action_filter = null;
76 protected $list_fields = array(
78 'raw_start_date_filter',
80 'raw_end_date_filter',
88 public function __construct()
94 * Returns the field we want to default set order to
98 protected function getDefaultOrder()
100 return self
::ORDERBY_DATE
;
104 * Return the default direction for ordering
106 * @return string ASC or DESC
108 protected function getDefaultDirection()
110 return self
::ORDER_DESC
;
114 * Reinit default parameters
118 public function reinit()
121 $this->start_date_filter
= null;
122 $this->end_date_filter
= null;
123 $this->user_filter
= 0;
124 $this->action_filter
= null;
128 * Global getter method
130 * @param string $name name of the property we want to retrive
132 * @return mixed the called property
134 public function __get($name)
137 '[HistoryList] Getting property `' . $name . '`',
141 if (in_array($name, $this->pagination_fields
)) {
142 return parent
::__get($name);
144 if (in_array($name, $this->list_fields
)) {
146 case 'raw_start_date_filter':
147 return $this->start_date_filter
;
149 case 'raw_end_date_filter':
150 return $this->end_date_filter
;
152 case 'start_date_filter':
153 case 'end_date_filter':
155 if ($this->$name !== null) {
156 $d = new \
DateTime($this->$name);
157 return $d->format(__("Y-m-d"));
159 } catch (Throwable
$e) {
160 //oops, we've got a bad date :/
162 'Bad date (' . $this->$name . ') | ' .
174 '[HistoryList] Unable to get proprety `' . $name . '`',
182 * Global isset method
183 * Required for twig to access properties via __get
185 * @param string $name name of the property we want to retrive
189 public function __isset($name)
191 if (in_array($name, $this->pagination_fields
)) {
193 } elseif (in_array($name, $this->list_fields
)) {
201 * Global setter method
203 * @param string $name name of the property we want to assign a value to
204 * @param object $value a relevant value for the property
208 public function __set($name, $value)
210 if (in_array($name, $this->pagination_fields
)) {
211 parent
::__set($name, $value);
214 '[HistoryList] Setting property `' . $name . '`',
219 case 'start_date_filter':
220 case 'end_date_filter':
223 $y = \DateTime
::createFromFormat(__("Y"), $value);
227 if ($name === 'end_date_filter') {
236 $this->$name = $y->format('Y-m-d');
239 $ym = \DateTime
::createFromFormat(__("Y-m"), $value);
240 if ($y === false && $ym !== false) {
242 if ($name === 'end_date_filter') {
243 $day = $ym->format('t');
250 $this->$name = $ym->format('Y-m-d');
253 $d = \DateTime
::createFromFormat(__("Y-m-d"), $value);
254 if ($y === false && $ym === false && $d !== false) {
255 $this->$name = $d->format('Y-m-d');
258 if ($y === false && $ym === false && $d === false) {
266 if ($name === 'start_date_filter') {
267 $field = _T("start date filter");
269 if ($name === 'end_date_filter') {
270 $field = _T("end date filter");
273 throw new \
Exception(
275 array('%field', '%formats'),
278 implode(', ', $formats)
280 _T("Unknown date format for %field.<br/>Know formats are: %formats")
287 } catch (Throwable
$e) {
289 'Wrong date format. field: ' . $name .
290 ', value: ' . $value . ', expected fmt: ' .
291 __("Y-m-d") . ' | ' . $e->getMessage(),
298 $this->$name = $value;