3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Mailiungs 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
38 namespace Galette\Filters
;
41 use Galette\Core\Pagination
;
42 use Galette\Core\MailingHistory
;
45 * Mailings history lists filters and paginator
47 * @name ContributionsList
51 * @author Johan Cwiklinski <johan@x-tnd.be>
52 * @copyright 2016 The Galette Team
53 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
54 * @link http://galette.tuxfamily.org
57 class MailingsList
extends Pagination
59 const ORDERBY_DATE
= 0;
60 const ORDERBY_SENDER
= 1;
61 const ORDERBY_SUBJECT
= 2;
62 const ORDERBY_SENT
= 3;
65 private $start_date_filter = null;
66 private $end_date_filter = null;
67 private $sender_filter = 0;
68 private $sent_filter = MailingHistory
::FILTER_DC_SENT
;
69 private $subject_filter = null;
71 protected $list_fields = array(
73 'raw_start_date_filter',
75 'raw_end_date_filter',
84 public function __construct()
90 * Returns the field we want to default set order to
92 * @return string field name
94 protected function getDefaultOrder()
96 return self
::ORDERBY_DATE
;
100 * Reinit default parameters
104 public function reinit()
107 $this->start_date_filter
= null;
108 $this->end_date_filter
= null;
109 $this->sender_filter
= 0;
110 $this->sent_filter
= MailingHistory
::FILTER_DC_SENT
;
111 $this->subject_filter
= null;
115 * Global getter method
117 * @param string $name name of the property we want to retrive
119 * @return object the called property
121 public function __get($name)
124 '[MailingsList] Getting property `' . $name . '`',
128 if (in_array($name, $this->pagination_fields
)) {
129 return parent
::__get($name);
131 if (in_array($name, $this->list_fields
)) {
133 case 'raw_start_date_filter':
134 return $this->start_date_filter
;
136 case 'raw_end_date_filter':
137 return $this->end_date_filter
;
139 case 'start_date_filter':
140 case 'end_date_filter':
142 if ($this->$name !== null) {
143 $d = new \
DateTime($this->$name);
144 return $d->format(__("Y-m-d"));
146 } catch (\Exception
$e) {
147 //oops, we've got a bad date :/
149 'Bad date (' . $this->$name . ') | ' .
161 '[MailingsList] Unable to get proprety `' . $name . '`',
169 * Global setter method
171 * @param string $name name of the property we want to assign a value to
172 * @param object $value a relevant value for the property
176 public function __set($name, $value)
178 if (in_array($name, $this->pagination_fields
)) {
179 parent
::__set($name, $value);
182 '[MailingsList] Setting property `' . $name . '`',
187 case 'start_date_filter':
188 case 'end_date_filter':
191 $y = \DateTime
::createFromFormat(__("Y"), $value);
195 if ($name === 'end_date_filter') {
204 $this->$name = $y->format('Y-m-d');
207 $ym = \DateTime
::createFromFormat(__("Y-m"), $value);
208 if ($y === false && $ym !== false) {
210 if ($name === 'end_date_filter') {
211 $day = $ym->format('t');
218 $this->$name = $ym->format('Y-m-d');
221 $d = \DateTime
::createFromFormat(__("Y-m-d"), $value);
222 if ($y === false && $ym === false && $d !== false) {
223 $this->$name = $d->format('Y-m-d');
226 if ($y === false && $ym === false && $d === false) {
234 if ($name === 'start_date_filter') {
235 $field = _T("start date filter");
237 if ($name === 'end_date_filter') {
238 $field = _T("end date filter");
241 throw new \
Exception(
243 array('%field', '%format'),
246 implode(', ', $formats)
248 _T("Unknown date format for %field.<br/>Know formats are: %formats")
255 } catch (\Exception
$e) {
257 'Wrong date format. field: ' . $key .
258 ', value: ' . $value . ', expected fmt: ' .
259 __("Y-m-d") . ' | ' . $e->getMessage(),
266 $this->$name = $value;