add status preference dao to ignore list
[civicrm-core.git] / CRM / Member / Form / Search.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * Files required
38 */
39
40/**
41 * This file is for civimember search
42 */
3efb5b86 43class CRM_Member_Form_Search extends CRM_Core_Form_Search {
6a488035 44
6a488035 45 /**
fe482240 46 * The params that are sent to the query.
6a488035
TO
47 *
48 * @var array
6a488035
TO
49 */
50 protected $_queryParams;
51
6a488035 52 /**
fe482240 53 * Are we restricting ourselves to a single contact.
6a488035 54 *
6a488035
TO
55 * @var boolean
56 */
57 protected $_single = FALSE;
58
59 /**
fe482240 60 * Are we restricting ourselves to a single contact.
6a488035 61 *
6a488035
TO
62 * @var boolean
63 */
64 protected $_limit = NULL;
65
6a488035 66 /**
fe482240 67 * Prefix for the controller.
6a488035
TO
68 */
69 protected $_prefix = "member_";
70
71 /**
fe482240 72 * Processing needed for buildForm and later.
6a488035
TO
73 *
74 * @return void
03e04002 75 */
00be9182 76 public function preProcess() {
6a488035
TO
77 $this->set('searchFormName', 'Search');
78
79 /**
80 * set the button names
81 */
82 $this->_searchButtonName = $this->getButtonName('refresh');
6a488035
TO
83 $this->_actionButtonName = $this->getButtonName('next', 'action');
84
85 $this->_done = FALSE;
86
87 $this->defaults = array();
88
03e04002 89 /*
d424ffde
CW
90 * we allow the controller to set force/reset externally, useful when we are being
91 * driven by the wizard framework
92 */
6a488035 93
353ffa53
TO
94 $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject);
95 $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE);
96 $this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this);
6a488035
TO
97 $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search');
98
99 $this->assign("context", $this->_context);
100
101 // get user submitted values
102 // get it from controller only if form has been submitted, else preProcess has set this
103 if (!empty($_POST)) {
104 $this->_formValues = $this->controller->exportValues($this->_name);
105 }
106 else {
107 $this->_formValues = $this->get('formValues');
108 }
109
110 if ($this->_force) {
111 $this->postProcess();
112 $this->set('force', 0);
113 }
114
115 $sortID = NULL;
116 if ($this->get(CRM_Utils_Sort::SORT_ID)) {
117 $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
118 $this->get(CRM_Utils_Sort::SORT_DIRECTION)
119 );
120 }
121
122 $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
123 $selector = new CRM_Member_Selector_Search($this->_queryParams,
124 $this->_action,
125 NULL,
126 $this->_single,
127 $this->_limit,
128 $this->_context
129 );
130 $prefix = NULL;
131 if ($this->_context == 'basic') {
132 $prefix = $this->_prefix;
133 }
134
135 $this->assign("{$prefix}limit", $this->_limit);
136 $this->assign("{$prefix}single", $this->_single);
137
138 $controller = new CRM_Core_Selector_Controller($selector,
139 $this->get(CRM_Utils_Pager::PAGE_ID),
140 $sortID,
141 CRM_Core_Action::VIEW,
142 $this,
143 CRM_Core_Selector_Controller::TRANSFER,
144 $prefix
145 );
146
147 $controller->setEmbedded(TRUE);
148 $controller->moveFromSessionToTemplate();
149
150 $this->assign('summary', $this->get('summary'));
151 }
152
153 /**
fe482240 154 * Build the form object.
6a488035 155 *
6a488035
TO
156 *
157 * @return void
158 */
00be9182 159 public function buildQuickForm() {
3efb5b86 160 parent::buildQuickForm();
6a488035
TO
161 $this->addElement('text', 'sort_name', ts('Member Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
162
163 CRM_Member_BAO_Query::buildSearchForm($this);
164
6a488035
TO
165 $rows = $this->get('rows');
166 if (is_array($rows)) {
167 if (!$this->_single) {
8d36b801 168 $this->addRowSelectors($rows);
6a488035
TO
169 }
170
6a488035
TO
171 $permission = CRM_Core_Permission::getPermission();
172
34197a55 173 $this->addTaskMenu(CRM_Member_Task::permissionedTaskTitles($permission));
6a488035
TO
174 }
175
6a488035
TO
176 }
177
178 /**
179 * The post processing of the form gets done here.
180 *
181 * Key things done during post processing are
182 * - check for reset or next request. if present, skip post procesing.
183 * - now check if user requested running a saved search, if so, then
184 * the form values associated with the saved search are used for searching.
185 * - if user has done a submit with new values the regular post submissing is
186 * done.
187 * The processing consists of using a Selector / Controller framework for getting the
188 * search results.
189 *
190 * @param
191 *
192 * @return void
6a488035 193 */
00be9182 194 public function postProcess() {
6a488035
TO
195 if ($this->_done) {
196 return;
197 }
198
199 $this->_done = TRUE;
200
201 $this->_formValues = $this->controller->exportValues($this->_name);
202
203 $this->fixFormValues();
204
d43b88cc
CW
205 // We don't show test records in summaries or dashboards
206 if (empty($this->_formValues['member_test']) && $this->_force) {
6a488035
TO
207 $this->_formValues["member_test"] = 0;
208 }
209
c94d39fd 210 CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);
6a488035
TO
211
212 $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
213
214 $this->set('formValues', $this->_formValues);
215 $this->set('queryParams', $this->_queryParams);
216
217 $buttonName = $this->controller->getButtonName();
e341bbee 218 if ($buttonName == $this->_actionButtonName) {
6a488035
TO
219 // check actionName and if next, then do not repeat a search, since we are going to the next page
220
221 // hack, make sure we reset the task values
95ea77ec 222 $stateMachine = $this->controller->getStateMachine();
6a488035
TO
223 $formName = $stateMachine->getTaskFormName();
224 $this->controller->resetPage($formName);
225 return;
226 }
227
228 $sortID = NULL;
229 if ($this->get(CRM_Utils_Sort::SORT_ID)) {
230 $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
231 $this->get(CRM_Utils_Sort::SORT_DIRECTION)
232 );
233 }
234
235 $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
236
237 $selector = new CRM_Member_Selector_Search($this->_queryParams,
238 $this->_action,
239 NULL,
240 $this->_single,
241 $this->_limit,
242 $this->_context
243 );
244 $selector->setKey($this->controller->_key);
245
246 $prefix = NULL;
247 if ($this->_context == 'basic') {
248 $prefix = $this->_prefix;
249 }
250
251 $controller = new CRM_Core_Selector_Controller($selector,
252 $this->get(CRM_Utils_Pager::PAGE_ID),
253 $sortID,
254 CRM_Core_Action::VIEW,
255 $this,
256 CRM_Core_Selector_Controller::SESSION,
257 $prefix
258 );
259 $controller->setEmbedded(TRUE);
260
261 $query = &$selector->getQuery();
262 $controller->run();
263 }
264
00be9182 265 public function setDefaultValues() {
6a488035
TO
266 return $this->_defaults;
267 }
268
00be9182 269 public function fixFormValues() {
6a488035
TO
270 // if this search has been forced
271 // then see if there are any get values, and if so over-ride the post values
272 // note that this means that GET over-rides POST :)
273
274 if (!$this->_force) {
275 return;
276 }
277
278 $status = CRM_Utils_Request::retrieve('status', 'String',
279 CRM_Core_DAO::$_nullObject
280 );
281 if ($status) {
282 $status = explode(',', $status);
0a74debb 283 $this->_formValues['status_id'] = $this->_defaults['status_id'] = (array) $status;
6a488035
TO
284 }
285
286 $membershipType = CRM_Utils_Request::retrieve('type', 'String',
287 CRM_Core_DAO::$_nullObject
288 );
289
290 if ($membershipType) {
0a74debb 291 $this->_formValues['membership_type_id'] = array($membershipType);
292 $this->_defaults['membership_type_id'] = array($membershipType);
6a488035
TO
293 }
294
6a488035
TO
295 $cid = CRM_Utils_Request::retrieve('cid', 'Positive',
296 CRM_Core_DAO::$_nullObject
297 );
298
299 if ($cid) {
300 $cid = CRM_Utils_Type::escape($cid, 'Integer');
301 if ($cid > 0) {
302 $this->_formValues['contact_id'] = $cid;
303 list($display, $image) = CRM_Contact_BAO_Contact::getDisplayAndImage($cid);
304 $this->_defaults['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid,
305 'sort_name'
306 );
307 // also assign individual mode to the template
308 $this->_single = TRUE;
309 }
310 }
311
312 $fromDate = CRM_Utils_Request::retrieve('start', 'Date',
313 CRM_Core_DAO::$_nullObject
314 );
315 if ($fromDate) {
316 list($date) = CRM_Utils_Date::setDateDefaults($fromDate);
317 $this->_formValues['member_start_date_low'] = $this->_defaults['member_start_date_low'] = $date;
318 }
319
320 $toDate = CRM_Utils_Request::retrieve('end', 'Date',
321 CRM_Core_DAO::$_nullObject
322 );
323 if ($toDate) {
324 list($date) = CRM_Utils_Date::setDateDefaults($toDate);
325 $this->_formValues['member_start_date_high'] = $this->_defaults['member_start_date_high'] = $date;
326 }
327 $joinDate = CRM_Utils_Request::retrieve('join', 'Date',
328 CRM_Core_DAO::$_nullObject
329 );
330 if ($joinDate) {
331 list($date) = CRM_Utils_Date::setDateDefaults($joinDate);
332 $this->_formValues['member_join_date_low'] = $this->_defaults['member_join_date_low'] = $date;
333 }
334
335 $joinEndDate = CRM_Utils_Request::retrieve('joinEnd', 'Date',
336 CRM_Core_DAO::$_nullObject
337 );
338 if ($joinEndDate) {
339 list($date) = CRM_Utils_Date::setDateDefaults($joinEndDate);
340 $this->_formValues['member_join_date_high'] = $this->_defaults['member_join_date_high'] = $date;
341 }
342
343 $this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive',
344 $this
345 );
346
347 //LCD also allow restrictions to membership owner via GET
348 $owner = CRM_Utils_Request::retrieve('owner', 'String', CRM_Core_DAO::$_nullObject);
349 if ($owner) {
350 $this->_formValues['member_is_primary'] = $this->_defaults['member_is_primary'] = 2;
351 }
352 }
353
354 /**
355 * Return a descriptive name for the page, used in wizard header
356 *
357 * @return string
6a488035
TO
358 */
359 public function getTitle() {
360 return ts('Find Memberships');
361 }
96025800 362
6a488035 363}