]> git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Filters/MembersList.php
Reaplce all Zend_Db_Select and Zend_Db_Expr with their ZF2 equivalents
[galette.git] / galette / lib / Galette / Filters / MembersList.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Members list filters and paginator
7 *
8 * PHP version 5
9 *
10 * Copyright © 2009-2013 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
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.
18 *
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.
23 *
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/>.
26 *
27 * @category Filters
28 * @package Galette
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2009-2013 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 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since march, 3rd 2009
36 */
37
38 namespace Galette\Filters;
39
40 use Analog\Analog as Analog;
41 use Galette\Core\Pagination as Pagination;
42 use Galette\Entity\Group as Group;
43 use Galette\Repository\Members as Members;
44
45 /**
46 * Members list filters and paginator
47 *
48 * @name MembersList
49 * @category Filters
50 * @package Galette
51 *
52 * @author Johan Cwiklinski <johan@x-tnd.be>
53 * @copyright 2009-2013 The Galette Team
54 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
55 * @link http://galette.tuxfamily.org
56 */
57
58 class MembersList extends Pagination
59 {
60 //filters
61 private $_filter_str;
62 private $_field_filter;
63 private $_membership_filter;
64 private $_account_status_filter;
65 private $_email_filter;
66 private $_group_filter;
67
68 private $_selected;
69 private $_unreachable;
70
71 protected $query;
72
73 protected $memberslist_fields = array(
74 'filter_str',
75 'field_filter',
76 'membership_filter',
77 'account_status_filter',
78 'email_filter',
79 'group_filter',
80 'selected',
81 'unreachable',
82 'query'
83 );
84
85 /**
86 * Default constructor
87 */
88 public function __construct()
89 {
90 $this->reinit();
91 }
92
93 /**
94 * Returns the field we want to default set order to
95 *
96 * @return string field name
97 */
98 protected function getDefaultOrder()
99 {
100 return 'nom_adh';
101 }
102
103 /**
104 * Reinit default parameters
105 *
106 * @return void
107 */
108 public function reinit()
109 {
110 parent::reinit();
111 $this->_filter_str = null;
112 $this->_field_filter = null;
113 $this->_membership_filter = null;
114 $this->_account_status_filter = null;
115 $this->_email_filter = Members::FILTER_DC_EMAIL;
116 $this->_group_filter = null;
117 $this->_selected = array();
118 }
119
120 /**
121 * Global getter method
122 *
123 * @param string $name name of the property we want to retrive
124 *
125 * @return object the called property
126 */
127 public function __get($name)
128 {
129
130 Analog::log(
131 '[MembersList] Getting property `' . $name . '`',
132 Analog::DEBUG
133 );
134
135 if ( in_array($name, $this->pagination_fields) ) {
136 return parent::__get($name);
137 } else {
138 if (in_array($name, $this->memberslist_fields)) {
139 if ( $name === 'query' ) {
140 return $this->$name;
141 } else {
142 $name = '_' . $name;
143 return $this->$name;
144 }
145 } else {
146 Analog::log(
147 '[MembersList] Unable to get proprety `' .$name . '`',
148 Analog::WARNING
149 );
150 }
151 }
152 }
153
154 /**
155 * Global setter method
156 *
157 * @param string $name name of the property we want to assign a value to
158 * @param object $value a relevant value for the property
159 *
160 * @return void
161 */
162 public function __set($name, $value)
163 {
164
165 if ( in_array($name, $this->pagination_fields) ) {
166 parent::__set($name, $value);
167 } else {
168 Analog::log(
169 '[MembersList] Setting property `' . $name . '`',
170 Analog::DEBUG
171 );
172
173 switch($name) {
174 case 'selected':
175 case 'unreachable':
176 if (is_array($value)) {
177 $name = '_' . $name;
178 $this->$name = $value;
179 } else {
180 Analog::log(
181 '[MembersList] Value for property `' . $name .
182 '` should be an array (' . gettype($value) . ' given)',
183 Analog::WARNING
184 );
185 }
186 break;
187 case 'filter_str':
188 $name = '_' . $name;
189 $this->$name = $value;
190 break;
191 case 'field_filter':
192 case 'membership_filter':
193 case 'account_status_filter':
194 if ( is_numeric($value) ) {
195 $name = '_' . $name;
196 $this->$name = $value;
197 } else {
198 Analog::log(
199 '[MembersList] Value for property `' . $name .
200 '` should be an integer (' . gettype($value) . ' given)',
201 Analog::WARNING
202 );
203 }
204 break;
205 case 'email_filter':
206 switch ($value) {
207 case Members::FILTER_DC_EMAIL:
208 case Members::FILTER_W_EMAIL:
209 case Members::FILTER_WO_EMAIL:
210 $this->_email_filter = $value;
211 break;
212 default:
213 Analog::log(
214 '[MembersList] Value for email filter should be either ' .
215 Members::FILTER_DC_EMAIL . ', ' .
216 Members::FILTER_W_EMAIL . ' or ' .
217 Members::FILTER_WO_EMAIL . ' (' . $value . ' given)',
218 Analog::WARNING
219 );
220 break;
221 }
222 break;
223 case 'group_filter':
224 if ( is_numeric($value) ) {
225 //check group existence
226 $g = new Group();
227 $res = $g->load($value);
228 if ( $res === true ) {
229 $this->_group_filter = $value;
230 } else {
231 Analog::log(
232 'Group #' . $value . ' does not exists!',
233 Analog::WARNING
234 );
235 }
236 } else {
237 Analog::log(
238 '[MembersList] Value for group filter should be an '
239 .'integer (' . gettype($value) . ' given',
240 Analog::WARNING
241 );
242 }
243 break;
244 case 'query':
245 $this->$name = $value;
246 break;
247 default:
248 Analog::log(
249 '[MembersList] Unable to set proprety `' . $name . '`',
250 Analog::WARNING
251 );
252 break;
253 }
254 }
255 }
256
257 /**
258 * Add SQL limit
259 *
260 * @param Select $select Original select
261 *
262 * @return <type>
263 */
264 public function setLimit($select)
265 {
266 return $this->setLimits($select);
267 }
268
269 /**
270 * Set counter
271 *
272 * @param int $c Count
273 *
274 * @return void
275 */
276 public function setCounter($c)
277 {
278 $this->counter = (int)$c;
279 $this->countPages();
280 }
281
282 /**
283 * Set commons filters for templates
284 *
285 * @param Smarty $tpl Smarty template reference
286 *
287 * @return void
288 */
289 public function setTplCommonsFilters($tpl)
290 {
291 $tpl->assign(
292 'filter_field_options',
293 array(
294 Members::FILTER_NAME => _T("Name"),
295 Members::FILTER_COMPANY_NAME => _T("Company name"),
296 Members::FILTER_ADRESS => _T("Address"),
297 Members::FILTER_MAIL => _T("Email,URL,IM"),
298 Members::FILTER_JOB => _T("Job"),
299 Members::FILTER_INFOS => _T("Infos")
300 )
301 );
302
303 $tpl->assign(
304 'filter_membership_options',
305 array(
306 Members::MEMBERSHIP_ALL => _T("All members"),
307 Members::MEMBERSHIP_UP2DATE => _T("Up to date members"),
308 Members::MEMBERSHIP_NEARLY => _T("Close expiries"),
309 Members::MEMBERSHIP_LATE => _T("Latecomers"),
310 Members::MEMBERSHIP_NEVER => _T("Never contributed"),
311 Members::MEMBERSHIP_STAFF => _T("Staff members"),
312 Members::MEMBERSHIP_ADMIN => _T("Administrators"),
313 Members::MEMBERSHIP_NONE => _T("Non members")
314 )
315 );
316
317 $tpl->assign(
318 'filter_accounts_options',
319 array(
320 Members::ALL_ACCOUNTS => _T("All accounts"),
321 Members::ACTIVE_ACCOUNT => _T("Active accounts"),
322 Members::INACTIVE_ACCOUNT => _T("Inactive accounts")
323 )
324 );
325
326
327 }
328 }