3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
41 * This file is for civimember search
43 class CRM_Member_Form_Search
extends CRM_Core_Form_Search
{
46 * the params that are sent to the query
51 protected $_queryParams;
54 * are we restricting ourselves to a single contact
59 protected $_single = FALSE;
62 * are we restricting ourselves to a single contact
67 protected $_limit = NULL;
72 * prefix for the controller
75 protected $_prefix = "member_";
78 * processing needed for buildForm and later
83 function preProcess() {
84 $this->set('searchFormName', 'Search');
87 * set the button names
89 $this->_searchButtonName
= $this->getButtonName('refresh');
90 $this->_actionButtonName
= $this->getButtonName('next', 'action');
94 $this->defaults
= array();
97 * we allow the controller to set force/reset externally, useful when we are being
98 * driven by the wizard framework
101 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
102 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
103 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
104 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
106 $this->assign("context", $this->_context
);
108 // get user submitted values
109 // get it from controller only if form has been submitted, else preProcess has set this
110 if (!empty($_POST)) {
111 $this->_formValues
= $this->controller
->exportValues($this->_name
);
114 $this->_formValues
= $this->get('formValues');
118 $this->postProcess();
119 $this->set('force', 0);
123 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
124 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
125 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
129 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
130 $selector = new CRM_Member_Selector_Search($this->_queryParams
,
138 if ($this->_context
== 'basic') {
139 $prefix = $this->_prefix
;
142 $this->assign("{$prefix}limit", $this->_limit
);
143 $this->assign("{$prefix}single", $this->_single
);
145 $controller = new CRM_Core_Selector_Controller($selector,
146 $this->get(CRM_Utils_Pager
::PAGE_ID
),
148 CRM_Core_Action
::VIEW
,
150 CRM_Core_Selector_Controller
::TRANSFER
,
154 $controller->setEmbedded(TRUE);
155 $controller->moveFromSessionToTemplate();
157 $this->assign('summary', $this->get('summary'));
161 * Build the form object
167 function buildQuickForm() {
168 parent
::buildQuickForm();
169 $this->addElement('text', 'sort_name', ts('Member Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
171 CRM_Member_BAO_Query
::buildSearchForm($this);
173 $rows = $this->get('rows');
174 if (is_array($rows)) {
175 if (!$this->_single
) {
176 $this->addRowSelectors($rows);
179 $permission = CRM_Core_Permission
::getPermission();
181 $this->addTaskMenu(CRM_Member_Task
::permissionedTaskTitles($permission));
187 * The post processing of the form gets done here.
189 * Key things done during post processing are
190 * - check for reset or next request. if present, skip post procesing.
191 * - now check if user requested running a saved search, if so, then
192 * the form values associated with the saved search are used for searching.
193 * - if user has done a submit with new values the regular post submissing is
195 * The processing consists of using a Selector / Controller framework for getting the
203 function postProcess() {
210 $this->_formValues
= $this->controller
->exportValues($this->_name
);
212 $this->fixFormValues();
214 // We don't show test records in summaries or dashboards
215 if (empty($this->_formValues
['member_test']) && $this->_force
) {
216 $this->_formValues
["member_test"] = 0;
219 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
221 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
223 $this->set('formValues', $this->_formValues
);
224 $this->set('queryParams', $this->_queryParams
);
226 $buttonName = $this->controller
->getButtonName();
227 if ($buttonName == $this->_actionButtonName
) {
228 // check actionName and if next, then do not repeat a search, since we are going to the next page
230 // hack, make sure we reset the task values
231 $stateMachine = $this->controller
->getStateMachine();
232 $formName = $stateMachine->getTaskFormName();
233 $this->controller
->resetPage($formName);
238 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
239 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
240 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
244 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
246 $selector = new CRM_Member_Selector_Search($this->_queryParams
,
253 $selector->setKey($this->controller
->_key
);
256 if ($this->_context
== 'basic') {
257 $prefix = $this->_prefix
;
260 $controller = new CRM_Core_Selector_Controller($selector,
261 $this->get(CRM_Utils_Pager
::PAGE_ID
),
263 CRM_Core_Action
::VIEW
,
265 CRM_Core_Selector_Controller
::SESSION
,
268 $controller->setEmbedded(TRUE);
270 $query = &$selector->getQuery();
274 function setDefaultValues() {
275 return $this->_defaults
;
278 function fixFormValues() {
279 // if this search has been forced
280 // then see if there are any get values, and if so over-ride the post values
281 // note that this means that GET over-rides POST :)
283 if (!$this->_force
) {
287 $status = CRM_Utils_Request
::retrieve('status', 'String',
288 CRM_Core_DAO
::$_nullObject
291 $status = explode(',', $status);
292 $tempStatus = array();
293 foreach ($status as $value) {
294 $tempStatus[$value] = 1;
296 $this->_formValues
['member_status_id'] = $tempStatus;
297 $this->_defaults
['member_status_id'] = $tempStatus;
300 $membershipType = CRM_Utils_Request
::retrieve('type', 'String',
301 CRM_Core_DAO
::$_nullObject
304 if ($membershipType) {
305 $this->_formValues
['member_membership_type_id'] = array($membershipType => 1);
306 $this->_defaults
['member_membership_type_id'] = array($membershipType => 1);
310 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive',
311 CRM_Core_DAO
::$_nullObject
315 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
317 $this->_formValues
['contact_id'] = $cid;
318 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
319 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
322 // also assign individual mode to the template
323 $this->_single
= TRUE;
327 $fromDate = CRM_Utils_Request
::retrieve('start', 'Date',
328 CRM_Core_DAO
::$_nullObject
331 list($date) = CRM_Utils_Date
::setDateDefaults($fromDate);
332 $this->_formValues
['member_start_date_low'] = $this->_defaults
['member_start_date_low'] = $date;
335 $toDate = CRM_Utils_Request
::retrieve('end', 'Date',
336 CRM_Core_DAO
::$_nullObject
339 list($date) = CRM_Utils_Date
::setDateDefaults($toDate);
340 $this->_formValues
['member_start_date_high'] = $this->_defaults
['member_start_date_high'] = $date;
342 $joinDate = CRM_Utils_Request
::retrieve('join', 'Date',
343 CRM_Core_DAO
::$_nullObject
346 list($date) = CRM_Utils_Date
::setDateDefaults($joinDate);
347 $this->_formValues
['member_join_date_low'] = $this->_defaults
['member_join_date_low'] = $date;
350 $joinEndDate = CRM_Utils_Request
::retrieve('joinEnd', 'Date',
351 CRM_Core_DAO
::$_nullObject
354 list($date) = CRM_Utils_Date
::setDateDefaults($joinEndDate);
355 $this->_formValues
['member_join_date_high'] = $this->_defaults
['member_join_date_high'] = $date;
358 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
362 //LCD also allow restrictions to membership owner via GET
363 $owner = CRM_Utils_Request
::retrieve('owner', 'String', CRM_Core_DAO
::$_nullObject);
365 $this->_formValues
['member_is_primary'] = $this->_defaults
['member_is_primary'] = 2;
370 * Return a descriptive name for the page, used in wizard header
375 public function getTitle() {
376 return ts('Find Memberships');