3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
37 * Class is a pane in advanced search and the membership search page.
39 class CRM_Member_Form_Search
extends CRM_Core_Form_Search
{
42 * The params that are sent to the query.
46 protected $_queryParams;
49 * Are we restricting ourselves to a single contact.
53 protected $_single = FALSE;
56 * Are we restricting ourselves to a single contact.
60 protected $_limit = NULL;
63 * Prefix for the controller.
66 protected $_prefix = "member_";
69 * Declare entity reference fields as they will need to be converted to using 'IN'.
73 protected $entityReferenceFields = ['membership_type_id'];
76 * Processing needed for buildForm and later.
78 public function preProcess() {
79 $this->set('searchFormName', 'Search');
81 $this->_searchButtonName
= $this->getButtonName('refresh');
82 $this->_actionButtonName
= $this->getButtonName('next', 'action');
86 $this->loadStandardSearchOptionsFromUrl();
88 // get user submitted values
89 // get it from controller only if form has been submitted, else preProcess has set this
91 $this->_formValues
= $this->controller
->exportValues($this->_name
);
94 $this->_formValues
= $this->get('formValues');
99 $this->set('force', 0);
103 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
104 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
105 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
109 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, $this->entityReferenceFields
);
110 $selector = new CRM_Member_Selector_Search($this->_queryParams
,
118 if ($this->_context
== 'basic') {
119 $prefix = $this->_prefix
;
122 $this->assign("{$prefix}limit", $this->_limit
);
123 $this->assign("{$prefix}single", $this->_single
);
125 $controller = new CRM_Core_Selector_Controller($selector,
126 $this->get(CRM_Utils_Pager
::PAGE_ID
),
128 CRM_Core_Action
::VIEW
,
130 CRM_Core_Selector_Controller
::TRANSFER
,
134 $controller->setEmbedded(TRUE);
135 $controller->moveFromSessionToTemplate();
137 $this->assign('summary', $this->get('summary'));
141 * Build the form object.
143 public function buildQuickForm() {
144 parent
::buildQuickForm();
145 $this->addContactSearchFields();
147 CRM_Member_BAO_Query
::buildSearchForm($this);
149 $rows = $this->get('rows');
150 if (is_array($rows)) {
151 if (!$this->_single
) {
152 $this->addRowSelectors($rows);
155 $this->addTaskMenu(CRM_Member_Task
::permissionedTaskTitles(CRM_Core_Permission
::getPermission()));
161 * Get the label for the sortName field if email searching is on.
163 * (email searching is a setting under search preferences).
167 protected function getSortNameLabelWithEmail() {
168 return ts('Member Name or Email');
172 * Get the label for the sortName field if email searching is off.
174 * (email searching is a setting under search preferences).
178 protected function getSortNameLabelWithOutEmail() {
179 return ts('Member Name');
183 * Get the label for the tag field.
185 * We do this in a function so the 'ts' wraps the whole string to allow
186 * better translation.
190 protected function getTagLabel() {
191 return ts('Member Tag(s)');
195 * Get the label for the group field.
199 protected function getGroupLabel() {
200 return ts('Member Group(s)');
204 * Get the label for the group field.
208 protected function getContactTypeLabel() {
209 return ts('Member Contact Type');
213 * The post processing of the form gets done here.
215 * Key things done during post processing are
216 * - check for reset or next request. if present, skip post procesing.
217 * - now check if user requested running a saved search, if so, then
218 * the form values associated with the saved search are used for searching.
219 * - if user has done a submit with new values the regular post submissing is
221 * The processing consists of using a Selector / Controller framework for getting the
224 public function postProcess() {
231 $this->_formValues
= $this->controller
->exportValues($this->_name
);
233 $this->fixFormValues();
235 // We don't show test records in summaries or dashboards
236 if (empty($this->_formValues
['member_test']) && $this->_force
) {
237 $this->_formValues
["member_test"] = 0;
240 CRM_Core_BAO_CustomValue
::fixCustomFieldValue($this->_formValues
);
242 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, $this->entityReferenceFields
);
244 $this->set('formValues', $this->_formValues
);
245 $this->set('queryParams', $this->_queryParams
);
247 $buttonName = $this->controller
->getButtonName();
248 if ($buttonName == $this->_actionButtonName
) {
249 // check actionName and if next, then do not repeat a search, since we are going to the next page
251 // hack, make sure we reset the task values
252 $stateMachine = $this->controller
->getStateMachine();
253 $formName = $stateMachine->getTaskFormName();
254 $this->controller
->resetPage($formName);
259 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
260 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
261 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
265 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, $this->entityReferenceFields
);
267 $selector = new CRM_Member_Selector_Search($this->_queryParams
,
274 $selector->setKey($this->controller
->_key
);
277 if ($this->_context
== 'basic') {
278 $prefix = $this->_prefix
;
281 $controller = new CRM_Core_Selector_Controller($selector,
282 $this->get(CRM_Utils_Pager
::PAGE_ID
),
284 CRM_Core_Action
::VIEW
,
286 CRM_Core_Selector_Controller
::SESSION
,
289 $controller->setEmbedded(TRUE);
291 $query = &$selector->getQuery();
296 * Set default values.
298 * @todo - can this function override be removed?
302 public function setDefaultValues() {
303 return $this->_defaults
;
307 * If this search has been forced then see if there are any get values, and if so over-ride the post values.
309 * Note that this means that GET over-rides POST :) & that force with no parameters can be very destructive.
311 public function fixFormValues() {
312 if (!$this->_force
) {
316 $status = CRM_Utils_Request
::retrieve('status', 'String');
318 $status = explode(',', $status);
319 $this->_formValues
['membership_status_id'] = $this->_defaults
['membership_status_id'] = (array) $status;
322 $membershipType = CRM_Utils_Request
::retrieve('type', 'String');
324 if ($membershipType) {
325 $this->_formValues
['membership_type_id'] = [$membershipType];
326 $this->_defaults
['membership_type_id'] = [$membershipType];
329 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive');
332 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
334 $this->_formValues
['contact_id'] = $cid;
335 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
336 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
339 // also assign individual mode to the template
340 $this->_single
= TRUE;
344 $fromDate = CRM_Utils_Request
::retrieve('start', 'Date');
346 list($date) = CRM_Utils_Date
::setDateDefaults($fromDate);
347 $this->_formValues
['member_start_date_low'] = $this->_defaults
['member_start_date_low'] = $date;
350 $toDate = CRM_Utils_Request
::retrieve('end', 'Date');
352 list($date) = CRM_Utils_Date
::setDateDefaults($toDate);
353 $this->_formValues
['member_start_date_high'] = $this->_defaults
['member_start_date_high'] = $date;
355 $joinDate = CRM_Utils_Request
::retrieve('join', 'Date');
357 list($date) = CRM_Utils_Date
::setDateDefaults($joinDate);
358 $this->_formValues
['member_join_date_low'] = $this->_defaults
['member_join_date_low'] = $date;
361 $joinEndDate = CRM_Utils_Request
::retrieve('joinEnd', 'Date');
363 list($date) = CRM_Utils_Date
::setDateDefaults($joinEndDate);
364 $this->_formValues
['member_join_date_high'] = $this->_defaults
['member_join_date_high'] = $date;
367 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
371 //LCD also allow restrictions to membership owner via GET
372 $owner = CRM_Utils_Request
::retrieve('owner', 'String');
373 if (in_array($owner, ['0', '1'])) {
374 $this->_formValues
['member_is_primary'] = $this->_defaults
['member_is_primary'] = $owner;
379 * Return a descriptive name for the page, used in wizard header.
383 public function getTitle() {
384 return ts('Find Memberships');