3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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.
50 protected $_queryParams;
53 * Are we restricting ourselves to a single contact.
57 protected $_single = FALSE;
60 * Are we restricting ourselves to a single contact.
64 protected $_limit = NULL;
67 * Prefix for the controller.
69 protected $_prefix = "member_";
72 * Processing needed for buildForm and later.
76 public function preProcess() {
77 $this->set('searchFormName', 'Search');
80 * set the button names
82 $this->_searchButtonName
= $this->getButtonName('refresh');
83 $this->_actionButtonName
= $this->getButtonName('next', 'action');
87 $this->defaults
= array();
90 * we allow the controller to set force/reset externally, useful when we are being
91 * driven by the wizard framework
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);
97 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
99 $this->assign("context", $this->_context
);
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
);
107 $this->_formValues
= $this->get('formValues');
111 $this->postProcess();
112 $this->set('force', 0);
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
)
122 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
123 $selector = new CRM_Member_Selector_Search($this->_queryParams
,
131 if ($this->_context
== 'basic') {
132 $prefix = $this->_prefix
;
135 $this->assign("{$prefix}limit", $this->_limit
);
136 $this->assign("{$prefix}single", $this->_single
);
138 $controller = new CRM_Core_Selector_Controller($selector,
139 $this->get(CRM_Utils_Pager
::PAGE_ID
),
141 CRM_Core_Action
::VIEW
,
143 CRM_Core_Selector_Controller
::TRANSFER
,
147 $controller->setEmbedded(TRUE);
148 $controller->moveFromSessionToTemplate();
150 $this->assign('summary', $this->get('summary'));
154 * Build the form object.
159 public function buildQuickForm() {
160 parent
::buildQuickForm();
161 $this->addElement('text', 'sort_name', ts('Member Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
163 CRM_Member_BAO_Query
::buildSearchForm($this);
165 $rows = $this->get('rows');
166 if (is_array($rows)) {
167 if (!$this->_single
) {
168 $this->addRowSelectors($rows);
171 $permission = CRM_Core_Permission
::getPermission();
173 $this->addTaskMenu(CRM_Member_Task
::permissionedTaskTitles($permission));
179 * The post processing of the form gets done here.
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
187 * The processing consists of using a Selector / Controller framework for getting the
194 public function postProcess() {
201 $this->_formValues
= $this->controller
->exportValues($this->_name
);
203 $this->fixFormValues();
205 // We don't show test records in summaries or dashboards
206 if (empty($this->_formValues
['member_test']) && $this->_force
) {
207 $this->_formValues
["member_test"] = 0;
210 $specialParams = array(
211 'membership_status_id',
212 'membership_type_id',
214 foreach ($specialParams as $element) {
215 $value = CRM_Utils_Array
::value($element, $this->_formValues
);
216 if (!empty($value) && is_array($value)) {
217 $this->_formValues
[$element] = array('IN' => $value);
221 CRM_Core_BAO_CustomValue
::fixCustomFieldValue($this->_formValues
);
223 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
225 $this->set('formValues', $this->_formValues
);
226 $this->set('queryParams', $this->_queryParams
);
228 $buttonName = $this->controller
->getButtonName();
229 if ($buttonName == $this->_actionButtonName
) {
230 // check actionName and if next, then do not repeat a search, since we are going to the next page
232 // hack, make sure we reset the task values
233 $stateMachine = $this->controller
->getStateMachine();
234 $formName = $stateMachine->getTaskFormName();
235 $this->controller
->resetPage($formName);
240 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
241 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
242 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
246 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
248 $selector = new CRM_Member_Selector_Search($this->_queryParams
,
255 $selector->setKey($this->controller
->_key
);
258 if ($this->_context
== 'basic') {
259 $prefix = $this->_prefix
;
262 $controller = new CRM_Core_Selector_Controller($selector,
263 $this->get(CRM_Utils_Pager
::PAGE_ID
),
265 CRM_Core_Action
::VIEW
,
267 CRM_Core_Selector_Controller
::SESSION
,
270 $controller->setEmbedded(TRUE);
272 $query = &$selector->getQuery();
276 public function setDefaultValues() {
277 return $this->_defaults
;
280 public function fixFormValues() {
281 // if this search has been forced
282 // then see if there are any get values, and if so over-ride the post values
283 // note that this means that GET over-rides POST :)
285 if (!$this->_force
) {
289 $status = CRM_Utils_Request
::retrieve('status', 'String',
290 CRM_Core_DAO
::$_nullObject
293 $status = explode(',', $status);
294 $this->_formValues
['status_id'] = $this->_defaults
['status_id'] = (array) $status;
297 $membershipType = CRM_Utils_Request
::retrieve('type', 'String',
298 CRM_Core_DAO
::$_nullObject
301 if ($membershipType) {
302 $this->_formValues
['membership_type_id'] = array($membershipType);
303 $this->_defaults
['membership_type_id'] = array($membershipType);
306 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive',
307 CRM_Core_DAO
::$_nullObject
311 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
313 $this->_formValues
['contact_id'] = $cid;
314 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
315 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
318 // also assign individual mode to the template
319 $this->_single
= TRUE;
323 $fromDate = CRM_Utils_Request
::retrieve('start', 'Date',
324 CRM_Core_DAO
::$_nullObject
327 list($date) = CRM_Utils_Date
::setDateDefaults($fromDate);
328 $this->_formValues
['member_start_date_low'] = $this->_defaults
['member_start_date_low'] = $date;
331 $toDate = CRM_Utils_Request
::retrieve('end', 'Date',
332 CRM_Core_DAO
::$_nullObject
335 list($date) = CRM_Utils_Date
::setDateDefaults($toDate);
336 $this->_formValues
['member_start_date_high'] = $this->_defaults
['member_start_date_high'] = $date;
338 $joinDate = CRM_Utils_Request
::retrieve('join', 'Date',
339 CRM_Core_DAO
::$_nullObject
342 list($date) = CRM_Utils_Date
::setDateDefaults($joinDate);
343 $this->_formValues
['member_join_date_low'] = $this->_defaults
['member_join_date_low'] = $date;
346 $joinEndDate = CRM_Utils_Request
::retrieve('joinEnd', 'Date',
347 CRM_Core_DAO
::$_nullObject
350 list($date) = CRM_Utils_Date
::setDateDefaults($joinEndDate);
351 $this->_formValues
['member_join_date_high'] = $this->_defaults
['member_join_date_high'] = $date;
354 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
358 //LCD also allow restrictions to membership owner via GET
359 $owner = CRM_Utils_Request
::retrieve('owner', 'String', CRM_Core_DAO
::$_nullObject);
361 $this->_formValues
['member_is_primary'] = $this->_defaults
['member_is_primary'] = 2;
366 * Return a descriptive name for the page, used in wizard header
370 public function getTitle() {
371 return ts('Find Memberships');