3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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.
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;
69 * Prefix for the controller.
71 protected $_prefix = "member_";
74 * Processing needed for buildForm and later.
78 public function preProcess() {
79 $this->set('searchFormName', 'Search');
82 * set the button names
84 $this->_searchButtonName
= $this->getButtonName('refresh');
85 $this->_actionButtonName
= $this->getButtonName('next', 'action');
89 $this->defaults
= array();
92 * we allow the controller to set force/reset externally, useful when we are being
93 * driven by the wizard framework
96 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
97 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
98 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
99 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
101 $this->assign("context", $this->_context
);
103 // get user submitted values
104 // get it from controller only if form has been submitted, else preProcess has set this
105 if (!empty($_POST)) {
106 $this->_formValues
= $this->controller
->exportValues($this->_name
);
109 $this->_formValues
= $this->get('formValues');
113 $this->postProcess();
114 $this->set('force', 0);
118 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
119 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
120 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
124 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
125 $selector = new CRM_Member_Selector_Search($this->_queryParams
,
133 if ($this->_context
== 'basic') {
134 $prefix = $this->_prefix
;
137 $this->assign("{$prefix}limit", $this->_limit
);
138 $this->assign("{$prefix}single", $this->_single
);
140 $controller = new CRM_Core_Selector_Controller($selector,
141 $this->get(CRM_Utils_Pager
::PAGE_ID
),
143 CRM_Core_Action
::VIEW
,
145 CRM_Core_Selector_Controller
::TRANSFER
,
149 $controller->setEmbedded(TRUE);
150 $controller->moveFromSessionToTemplate();
152 $this->assign('summary', $this->get('summary'));
156 * Build the form object.
161 public function buildQuickForm() {
162 parent
::buildQuickForm();
163 $this->addElement('text', 'sort_name', ts('Member Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
165 CRM_Member_BAO_Query
::buildSearchForm($this);
167 $rows = $this->get('rows');
168 if (is_array($rows)) {
169 if (!$this->_single
) {
170 $this->addRowSelectors($rows);
173 $permission = CRM_Core_Permission
::getPermission();
175 $this->addTaskMenu(CRM_Member_Task
::permissionedTaskTitles($permission));
181 * The post processing of the form gets done here.
183 * Key things done during post processing are
184 * - check for reset or next request. if present, skip post procesing.
185 * - now check if user requested running a saved search, if so, then
186 * the form values associated with the saved search are used for searching.
187 * - if user has done a submit with new values the regular post submissing is
189 * The processing consists of using a Selector / Controller framework for getting the
196 public function postProcess() {
203 $this->_formValues
= $this->controller
->exportValues($this->_name
);
205 $this->fixFormValues();
207 // We don't show test records in summaries or dashboards
208 if (empty($this->_formValues
['member_test']) && $this->_force
) {
209 $this->_formValues
["member_test"] = 0;
212 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
214 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
216 $this->set('formValues', $this->_formValues
);
217 $this->set('queryParams', $this->_queryParams
);
219 $buttonName = $this->controller
->getButtonName();
220 if ($buttonName == $this->_actionButtonName
) {
221 // check actionName and if next, then do not repeat a search, since we are going to the next page
223 // hack, make sure we reset the task values
224 $stateMachine = $this->controller
->getStateMachine();
225 $formName = $stateMachine->getTaskFormName();
226 $this->controller
->resetPage($formName);
231 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
232 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
233 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
237 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
239 $selector = new CRM_Member_Selector_Search($this->_queryParams
,
246 $selector->setKey($this->controller
->_key
);
249 if ($this->_context
== 'basic') {
250 $prefix = $this->_prefix
;
253 $controller = new CRM_Core_Selector_Controller($selector,
254 $this->get(CRM_Utils_Pager
::PAGE_ID
),
256 CRM_Core_Action
::VIEW
,
258 CRM_Core_Selector_Controller
::SESSION
,
261 $controller->setEmbedded(TRUE);
263 $query = &$selector->getQuery();
267 public function setDefaultValues() {
268 return $this->_defaults
;
271 public function fixFormValues() {
272 // if this search has been forced
273 // then see if there are any get values, and if so over-ride the post values
274 // note that this means that GET over-rides POST :)
276 if (!$this->_force
) {
280 $status = CRM_Utils_Request
::retrieve('status', 'String',
281 CRM_Core_DAO
::$_nullObject
284 $status = explode(',', $status);
285 $tempStatus = array();
286 foreach ($status as $value) {
287 $tempStatus[$value] = 1;
289 $this->_formValues
['member_status_id'] = $tempStatus;
290 $this->_defaults
['member_status_id'] = $tempStatus;
293 $membershipType = CRM_Utils_Request
::retrieve('type', 'String',
294 CRM_Core_DAO
::$_nullObject
297 if ($membershipType) {
298 $this->_formValues
['member_membership_type_id'] = array($membershipType => 1);
299 $this->_defaults
['member_membership_type_id'] = array($membershipType => 1);
302 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive',
303 CRM_Core_DAO
::$_nullObject
307 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
309 $this->_formValues
['contact_id'] = $cid;
310 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
311 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
314 // also assign individual mode to the template
315 $this->_single
= TRUE;
319 $fromDate = CRM_Utils_Request
::retrieve('start', 'Date',
320 CRM_Core_DAO
::$_nullObject
323 list($date) = CRM_Utils_Date
::setDateDefaults($fromDate);
324 $this->_formValues
['member_start_date_low'] = $this->_defaults
['member_start_date_low'] = $date;
327 $toDate = CRM_Utils_Request
::retrieve('end', 'Date',
328 CRM_Core_DAO
::$_nullObject
331 list($date) = CRM_Utils_Date
::setDateDefaults($toDate);
332 $this->_formValues
['member_start_date_high'] = $this->_defaults
['member_start_date_high'] = $date;
334 $joinDate = CRM_Utils_Request
::retrieve('join', 'Date',
335 CRM_Core_DAO
::$_nullObject
338 list($date) = CRM_Utils_Date
::setDateDefaults($joinDate);
339 $this->_formValues
['member_join_date_low'] = $this->_defaults
['member_join_date_low'] = $date;
342 $joinEndDate = CRM_Utils_Request
::retrieve('joinEnd', 'Date',
343 CRM_Core_DAO
::$_nullObject
346 list($date) = CRM_Utils_Date
::setDateDefaults($joinEndDate);
347 $this->_formValues
['member_join_date_high'] = $this->_defaults
['member_join_date_high'] = $date;
350 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
354 //LCD also allow restrictions to membership owner via GET
355 $owner = CRM_Utils_Request
::retrieve('owner', 'String', CRM_Core_DAO
::$_nullObject);
357 $this->_formValues
['member_is_primary'] = $this->_defaults
['member_is_primary'] = 2;
362 * Return a descriptive name for the page, used in wizard header
366 public function getTitle() {
367 return ts('Find Memberships');