3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Base Search / View form for *all* listing of multiple
22 class CRM_Contact_Form_Search
extends CRM_Core_Form_Search
{
25 * list of valid contexts.
29 public static $_validContext = NULL;
32 * List of values used when we want to display other objects.
36 public static $_modeValues = NULL;
43 protected $_contextMenu;
46 * The groupId retrieved from the GET vars.
53 * The Group ID belonging to Add Member to group ID.
54 * retrieved from the GET vars
61 * The saved search ID retrieved from the GET vars.
73 public $_groupElement;
84 * The params used for search.
91 * The return properties used for search.
95 protected $_returnProperties;
98 * The sort by character.
102 protected $_sortByCharacter;
105 * The profile group id used for display.
109 protected $_ufGroupID;
112 * Csv - common search values
116 public static $csv = ['contact_type', 'group', 'tag'];
119 * How to display the results. Should we display as contributons, members, cases etc.
123 protected $_componentMode;
126 * What operator should we use, AND or OR.
130 protected $_operator;
132 protected $_modeValue;
135 * Declare entity reference fields as they will need to be converted to using 'IN'.
139 protected $entityReferenceFields = ['event_id', 'membership_type_id'];
142 * Name of the selector to use.
145 public static $_selectorName = 'CRM_Contact_Selector';
146 protected $_customSearchID = NULL;
147 protected $_customSearchClass = NULL;
149 protected $_openedPanes = [];
152 * Explicitly declare the entity api name.
154 public function getDefaultEntity() {
159 * Define the set of valid contexts that the search form operates on.
162 * the valid context set and the titles
164 public static function &validContext() {
165 if (!(self
::$_validContext)) {
166 self
::$_validContext = [
167 'smog' => 'Show members of group',
168 'amtg' => 'Add members to group',
169 'basic' => 'Basic Search',
170 'search' => 'Search',
171 'builder' => 'Search Builder',
172 'advanced' => 'Advanced Search',
173 'custom' => 'Custom Search',
176 return self
::$_validContext;
184 public static function isSearchContext($context) {
185 $searchContext = CRM_Utils_Array
::value($context, self
::validContext());
186 return $searchContext ?
TRUE : FALSE;
189 public static function setModeValues() {
190 self
::$_modeValues = [
191 CRM_Contact_BAO_Query
::MODE_CONTACTS
=> [
192 'selectorName' => self
::$_selectorName,
193 'selectorLabel' => ts('Contacts'),
194 'taskFile' => 'CRM/Contact/Form/Search/ResultTasks.tpl',
195 'taskContext' => NULL,
196 'resultFile' => 'CRM/Contact/Form/Selector.tpl',
197 'resultContext' => NULL,
198 'taskClassName' => 'CRM_Contact_Task',
201 CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
=> [
202 'selectorName' => 'CRM_Contribute_Selector_Search',
203 'selectorLabel' => ts('Contributions'),
204 'taskFile' => 'CRM/common/searchResultTasks.tpl',
205 'taskContext' => 'Contribution',
206 'resultFile' => 'CRM/Contribute/Form/Selector.tpl',
207 'resultContext' => 'Search',
208 'taskClassName' => 'CRM_Contribute_Task',
209 'component' => 'CiviContribute',
211 CRM_Contact_BAO_Query
::MODE_EVENT
=> [
212 'selectorName' => 'CRM_Event_Selector_Search',
213 'selectorLabel' => ts('Event Participants'),
214 'taskFile' => 'CRM/common/searchResultTasks.tpl',
215 'taskContext' => NULL,
216 'resultFile' => 'CRM/Event/Form/Selector.tpl',
217 'resultContext' => 'Search',
218 'taskClassName' => 'CRM_Event_Task',
219 'component' => 'CiviEvent',
221 CRM_Contact_BAO_Query
::MODE_ACTIVITY
=> [
222 'selectorName' => 'CRM_Activity_Selector_Search',
223 'selectorLabel' => ts('Activities'),
224 'taskFile' => 'CRM/common/searchResultTasks.tpl',
225 'taskContext' => NULL,
226 'resultFile' => 'CRM/Activity/Form/Selector.tpl',
227 'resultContext' => 'Search',
228 'taskClassName' => 'CRM_Activity_Task',
229 'component' => 'activity',
231 CRM_Contact_BAO_Query
::MODE_MEMBER
=> [
232 'selectorName' => 'CRM_Member_Selector_Search',
233 'selectorLabel' => ts('Memberships'),
234 'taskFile' => "CRM/common/searchResultTasks.tpl",
235 'taskContext' => NULL,
236 'resultFile' => 'CRM/Member/Form/Selector.tpl',
237 'resultContext' => 'Search',
238 'taskClassName' => 'CRM_Member_Task',
239 'component' => 'CiviMember',
241 CRM_Contact_BAO_Query
::MODE_CASE
=> [
242 'selectorName' => 'CRM_Case_Selector_Search',
243 'selectorLabel' => ts('Cases'),
244 'taskFile' => "CRM/common/searchResultTasks.tpl",
245 'taskContext' => NULL,
246 'resultFile' => 'CRM/Case/Form/Selector.tpl',
247 'resultContext' => 'Search',
248 'taskClassName' => 'CRM_Case_Task',
249 'component' => 'CiviCase',
251 CRM_Contact_BAO_Query
::MODE_CONTACTSRELATED
=> [
252 'selectorName' => self
::$_selectorName,
253 'selectorLabel' => ts('Related Contacts'),
254 'taskFile' => 'CRM/Contact/Form/Search/ResultTasks.tpl',
255 'taskContext' => NULL,
256 'resultFile' => 'CRM/Contact/Form/Selector.tpl',
257 'resultContext' => NULL,
258 'taskClassName' => 'CRM_Contact_Task',
259 'component' => 'related_contact',
261 CRM_Contact_BAO_Query
::MODE_MAILING
=> [
262 'selectorName' => 'CRM_Mailing_Selector_Search',
263 'selectorLabel' => ts('Mailings'),
264 'taskFile' => "CRM/common/searchResultTasks.tpl",
265 'taskContext' => NULL,
266 'resultFile' => 'CRM/Mailing/Form/Selector.tpl',
267 'resultContext' => 'Search',
268 'taskClassName' => 'CRM_Mailing_Task',
269 'component' => 'CiviMail',
275 * Get the metadata for the query mode (this includes task class names)
280 * @throws \CRM_Core_Exception
282 public static function getModeValue($mode = CRM_Contact_BAO_Query
::MODE_CONTACTS
) {
283 $searchPane = CRM_Utils_Request
::retrieve('searchPane', 'String');
284 if (!empty($searchPane)) {
285 $mode = array_search($searchPane, self
::getModeToComponentMapping());
288 self
::setModeValues();
289 // Note $mode might === FALSE because array_search above failed, e.g. for searchPane='location'
290 if (empty(self
::$_modeValues[$mode])) {
291 $mode = CRM_Contact_BAO_Query
::MODE_CONTACTS
;
294 return self
::$_modeValues[$mode];
298 * Get a mapping of modes to components.
300 * This will map the integers to the components. Contact has an empty component
301 * an pseudo-components exist for activity & related_contact.
305 public static function getModeToComponentMapping() {
307 self
::setModeValues();
309 foreach (self
::$_modeValues as $id => $metadata) {
310 $mapping[$id] = $metadata['component'];
318 public static function getModeSelect() {
319 self
::setModeValues();
321 $enabledComponents = CRM_Core_Component
::getEnabledComponents();
322 $componentModes = [];
323 foreach (self
::$_modeValues as $id => & $value) {
324 if (strpos($value['component'], 'Civi') !== FALSE
325 && !array_key_exists($value['component'], $enabledComponents)
329 $componentModes[$id] = $value['selectorLabel'];
332 // unset disabled components
333 if (!array_key_exists('CiviMail', $enabledComponents)) {
334 unset($componentModes[CRM_Contact_BAO_Query
::MODE_MAILING
]);
337 // unset contributions or participants if user does not have permission on them
338 if (!CRM_Core_Permission
::access('CiviContribute')) {
339 unset($componentModes[CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
]);
342 if (!CRM_Core_Permission
::access('CiviEvent')) {
343 unset($componentModes[CRM_Contact_BAO_Query
::MODE_EVENT
]);
346 if (!CRM_Core_Permission
::access('CiviMember')) {
347 unset($componentModes[CRM_Contact_BAO_Query
::MODE_MEMBER
]);
350 if (!CRM_Core_Permission
::check('view all activities')) {
351 unset($componentModes[CRM_Contact_BAO_Query
::MODE_ACTIVITY
]);
354 return $componentModes;
358 * Builds the list of tasks or actions that a searcher can perform on a result set.
362 public function buildTaskList() {
363 // amtg = 'Add members to group'
364 if ($this->_context
!== 'amtg') {
365 $taskParams['deletedContacts'] = FALSE;
366 if ($this->_componentMode
== CRM_Contact_BAO_Query
::MODE_CONTACTS ||
$this->_componentMode
== CRM_Contact_BAO_Query
::MODE_CONTACTSRELATED
) {
367 $taskParams['deletedContacts'] = CRM_Utils_Array
::value('deleted_contacts', $this->_formValues
);
369 $className = $this->_modeValue
['taskClassName'];
370 $taskParams['ssID'] = isset($this->_ssID
) ?
$this->_ssID
: NULL;
371 $this->_taskList +
= $className::permissionedTaskTitles(CRM_Core_Permission
::getPermission(), $taskParams);
374 return $this->_taskList
;
378 * Build the common elements between the search/advanced form.
380 public function buildQuickForm() {
381 parent
::buildQuickForm();
383 // some tasks.. what do we want to do with the selected contacts ?
384 $this->_taskList
= $this->buildTaskList();
386 if (isset($this->_ssID
)) {
388 = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID
, 'search_custom_id');
390 $savedSearchValues = [
391 'id' => $this->_ssID
,
392 'name' => CRM_Contact_BAO_SavedSearch
::getName($this->_ssID
, 'title'),
393 'search_custom_id' => $search_custom_id,
395 $this->assign_by_ref('savedSearch', $savedSearchValues);
396 $this->assign('ssID', $this->_ssID
);
399 if ($this->_context
=== 'smog') {
400 // CRM-11788, we might want to do this for all of search where force=1
401 $formQFKey = CRM_Utils_Array
::value('qfKey', $this->_formValues
);
402 $getQFKey = CRM_Utils_Array
::value('qfKey', $_GET);
403 $postQFKey = CRM_Utils_Array
::value('qfKey', $_POST);
404 if ($formQFKey && empty($getQFKey) && empty($postQFKey)) {
405 $url = CRM_Utils_System
::makeURL('qfKey') . $formQFKey;
406 CRM_Utils_System
::redirect($url);
408 $permissionForGroup = FALSE;
410 if (!empty($this->_groupID
)) {
411 // check if user has permission to edit members of this group
412 $permission = CRM_Contact_BAO_Group
::checkPermission($this->_groupID
);
413 if ($permission && in_array(CRM_Core_Permission
::EDIT
, $permission)) {
414 $permissionForGroup = TRUE;
417 // check if _groupID exists, it might not if
418 // we are displaying a hidden group
419 if (!isset($this->_group
[$this->_groupID
])) {
420 $this->_group
[$this->_groupID
]
421 = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID
, 'title');
424 // set the group title
425 $groupValues = ['id' => $this->_groupID
, 'title' => $this->_group
[$this->_groupID
]];
426 $this->assign_by_ref('group', $groupValues);
428 // also set ssID if this is a saved search
429 $ssID = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID
, 'saved_search_id');
430 $this->assign('ssID', $ssID);
432 //get the saved search mapping id
434 $this->_ssID
= $ssID;
435 $ssMappingId = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id');
436 $this->assign('ssMappingID', $ssMappingId);
439 // Set dynamic page title for 'Show Members of Group'
440 CRM_Utils_System
::setTitle(ts('Contacts in Group: %1', [1 => $this->_group
[$this->_groupID
]]));
443 $group_contact_status = [];
444 foreach (CRM_Core_SelectValues
::groupContactStatus() as $k => $v) {
446 $group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v);
449 $this->addGroup($group_contact_status,
450 'group_contact_status', ts('Group Status')
453 $this->assign('permissionedForGroup', $permissionForGroup);
456 // add the go button for the action form, note it is of type 'next' rather than of type 'submit'
457 if ($this->_context
=== 'amtg') {
458 // check if _groupID exists, it might not if
459 // we are displaying a hidden group
460 if (!isset($this->_group
[$this->_amtgID
])) {
461 $this->assign('permissionedForGroup', FALSE);
462 $this->_group
[$this->_amtgID
]
463 = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_amtgID
, 'title');
466 // Set dynamic page title for 'Add Members Group'
467 CRM_Utils_System
::setTitle(ts('Add to Group: %1', [1 => $this->_group
[$this->_amtgID
]]));
468 // also set the group title and freeze the action task with Add Members to Group
469 $groupValues = ['id' => $this->_amtgID
, 'title' => $this->_group
[$this->_amtgID
]];
470 $this->assign_by_ref('group', $groupValues);
471 $this->add('submit', $this->_actionButtonName
, ts('Add Contacts to %1', [1 => $this->_group
[$this->_amtgID
]]),
473 'class' => 'crm-form-submit',
476 $this->add('hidden', 'task', CRM_Contact_Task
::GROUP_ADD
);
477 $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', ['checked' => 'checked']);
478 $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all');
479 $this->assign('ts_sel_id', $selectedRowsRadio->_attributes
['id']);
480 $this->assign('ts_all_id', $allRowsRadio->_attributes
['id']);
483 $selectedContactIds = [];
484 $qfKeyParam = CRM_Utils_Array
::value('qfKey', $this->_formValues
);
485 // We use ajax to handle selections only if the search results component_mode is set to "contacts"
486 if ($qfKeyParam && ($this->get('component_mode') <= CRM_Contact_BAO_Query
::MODE_CONTACTS ||
$this->get('component_mode') == CRM_Contact_BAO_Query
::MODE_CONTACTSRELATED
)) {
487 $this->addClass('crm-ajax-selection-form');
488 $qfKeyParam = "civicrm search {$qfKeyParam}";
489 $selectedContactIdsArr = Civi
::service('prevnext')->getSelection($qfKeyParam);
490 $selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]);
493 $this->assign_by_ref('selectedContactIds', $selectedContactIds);
495 $rows = $this->get('rows');
497 if (is_array($rows)) {
498 $this->addRowSelectors($rows);
504 * Processing needed for buildForm and later.
506 * @throws \CRM_Core_Exception
508 public function preProcess() {
509 // set the various class variables
511 $this->_group
= CRM_Core_PseudoConstant
::group();
513 $this->_tag
= CRM_Core_BAO_Tag
::getTags();
514 $this->_done
= FALSE;
517 * we allow the controller to set force/reset externally, useful when we are being
518 * driven by the wizard framework
521 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean');
523 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean');
524 $this->_groupID
= CRM_Utils_Request
::retrieve('gid', 'Positive', $this);
525 $this->_amtgID
= CRM_Utils_Request
::retrieve('amtgID', 'Positive', $this);
526 $this->_ssID
= CRM_Utils_Request
::retrieve('ssID', 'Positive', $this);
527 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter', 'String', $this);
528 $this->_ufGroupID
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
529 $this->_componentMode
= CRM_Utils_Request
::retrieve('component_mode', 'Positive', $this, FALSE, CRM_Contact_BAO_Query
::MODE_CONTACTS
, $_REQUEST);
530 $this->_operator
= CRM_Utils_Request
::retrieve('operator', 'String', $this, FALSE, CRM_Contact_BAO_Query
::SEARCH_OPERATOR_AND
, 'REQUEST');
533 * set the button names
535 $this->_actionButtonName
= $this->getButtonName('next', 'action');
537 $this->assign('actionButtonName', $this->_actionButtonName
);
539 // if we dont get this from the url, use default if one exsts
540 $config = CRM_Core_Config
::singleton();
541 if ($this->_ufGroupID
== NULL &&
542 $config->defaultSearchProfileID
!= NULL
544 $this->_ufGroupID
= $config->defaultSearchProfileID
;
547 // assign context to drive the template display, make sure context is valid
548 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this, FALSE, 'search');
549 if (!CRM_Utils_Array
::value($this->_context
, self
::validContext())) {
550 $this->_context
= 'search';
552 $this->set('context', $this->_context
);
553 $this->assign('context', $this->_context
);
555 $this->_modeValue
= self
::getModeValue($this->_componentMode
);
556 $this->assign($this->_modeValue
);
558 $this->set('selectorName', self
::$_selectorName);
560 // get user submitted values
561 // get it from controller only if form has been submitted, else preProcess has set this
562 // $this->controller->isModal( ) returns TRUE if page is
563 // valid, i.e all the validations are TRUE
565 if (!empty($_POST) && !$this->controller
->isModal()) {
566 $this->_formValues
= $this->controller
->exportValues($this->_name
);
568 $this->normalizeFormValues();
569 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, $this->entityReferenceFields
);
570 $this->_returnProperties
= &$this->returnProperties();
572 // also get the uf group id directly from the post value
573 $this->_ufGroupID
= CRM_Utils_Array
::value('uf_group_id', $_POST, $this->_ufGroupID
);
574 $this->_formValues
['uf_group_id'] = $this->_ufGroupID
;
575 $this->set('id', $this->_ufGroupID
);
577 // also get the object mode directly from the post value
578 $this->_componentMode
= CRM_Utils_Array
::value('component_mode', $_POST, $this->_componentMode
);
580 // also get the operator from the post value if set
581 $this->_operator
= CRM_Utils_Array
::value('operator', $_POST, $this->_operator
);
582 $this->_formValues
['operator'] = $this->_operator
;
583 $this->set('operator', $this->_operator
);
586 $this->_formValues
= $this->get('formValues');
587 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, $this->entityReferenceFields
);
588 $this->_returnProperties
= &$this->returnProperties();
589 if (!empty($this->_ufGroupID
)) {
590 $this->set('id', $this->_ufGroupID
);
594 if (empty($this->_formValues
)) {
595 //check if group is a smart group (fix for CRM-1255)
596 if ($this->_groupID
) {
597 if ($ssId = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID
, 'saved_search_id')) {
598 $this->_ssID
= $ssId;
603 if (isset($this->_ssID
) && $this->_context
!== 'smog') {
604 // we only retrieve the saved search values if out current values are null
605 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
608 if (CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID
, 'mapping_id')) {
609 $this->_params
= CRM_Contact_BAO_SavedSearch
::getSearchParams($this->_ssID
);
612 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
614 $this->_returnProperties
= &$this->returnProperties();
617 if (isset($this->_ufGroupID
)) {
618 // also set the uf group id if not already present
619 $this->_formValues
['uf_group_id'] = $this->_ufGroupID
;
621 if (isset($this->_componentMode
)) {
622 $this->_formValues
['component_mode'] = $this->_componentMode
;
624 if (isset($this->_operator
)) {
625 $this->_formValues
['operator'] = $this->_operator
;
628 // FIXME: we should generalise in a way that components could inject url-filters
629 // just like they build their own form elements
632 'mailing_delivery_status',
633 'mailing_open_status',
634 'mailing_click_status',
635 'mailing_reply_status',
638 'mailing_unsubscribe',
641 'mailing_job_start_date_low',
642 'mailing_job_start_date_high',
643 'mailing_job_start_date_relative',
644 ] as $mailingFilter) {
646 if ($mailingFilter == 'mailing_id' &&
647 $filterVal = CRM_Utils_Request
::retrieve('mailing_id', 'Positive', $this)
649 $this->_formValues
[$mailingFilter] = [$filterVal];
651 elseif ($filterVal = CRM_Utils_Request
::retrieve($mailingFilter, $type, $this)) {
652 $this->_formValues
[$mailingFilter] = $filterVal;
655 $this->_openedPanes
['Mailings'] = 1;
656 $this->_formValues
['hidden_CiviMail'] = 1;
662 CRM_Utils_Array
::value('uf_group_id', $this->_formValues
)
664 $operator = CRM_Utils_Array
::value('operator', $this->_formValues
, CRM_Contact_BAO_Query
::SEARCH_OPERATOR_AND
);
665 $this->set('queryOperator', $operator);
666 if ($operator == CRM_Contact_BAO_Query
::SEARCH_OPERATOR_OR
) {
667 $this->assign('operator', ts('OR'));
670 $this->assign('operator', ts('AND'));
673 // show the context menu only when we’re not searching for deleted contacts; CRM-5673
674 if (empty($this->_formValues
['deleted_contacts'])) {
675 $menuItems = CRM_Contact_BAO_Contact
::contextMenu();
676 $primaryActions = CRM_Utils_Array
::value('primaryActions', $menuItems, []);
677 $this->_contextMenu
= CRM_Utils_Array
::value('moreActions', $menuItems, []);
678 $this->assign('contextMenu', $primaryActions +
$this->_contextMenu
);
681 if (!isset($this->_componentMode
)) {
682 $this->_componentMode
= CRM_Contact_BAO_Query
::MODE_CONTACTS
;
684 self
::$_selectorName = $this->_modeValue
['selectorName'];
685 self
::setModeValues();
688 if (strpos(self
::$_selectorName, 'CRM_Contact_Selector') !== FALSE) {
689 $selector = new self
::$_selectorName(
690 $this->_customSearchClass
,
693 $this->_returnProperties
,
702 $selector = new self
::$_selectorName(
710 $selector->setKey($this->controller
->_key
);
712 $controller = new CRM_Contact_Selector_Controller($selector,
713 $this->get(CRM_Utils_Pager
::PAGE_ID
),
714 $this->get(CRM_Utils_Sort
::SORT_ID
),
715 CRM_Core_Action
::VIEW
,
717 CRM_Core_Selector_Controller
::TRANSFER
719 $controller->setEmbedded(TRUE);
720 $controller->setDynamicAction($setDynamic);
723 $this->loadMetadata();
724 $this->postProcess();
727 * Note that we repeat this, since the search creates and stores
728 * values that potentially change the controller behavior. i.e. things
729 * like totalCount etc
731 $controller = new CRM_Contact_Selector_Controller($selector,
732 $this->get(CRM_Utils_Pager
::PAGE_ID
),
734 CRM_Core_Action
::VIEW
, $this, CRM_Core_Selector_Controller
::TRANSFER
736 $controller->setEmbedded(TRUE);
737 $controller->setDynamicAction($setDynamic);
740 $controller->moveFromSessionToTemplate();
744 * Common post processing.
746 public function postProcess() {
748 * sometime we do a postProcess early on, so we dont need to repeat it
749 * this will most likely introduce some more bugs :(
757 //for prev/next pagination
758 $crmPID = CRM_Utils_Request
::retrieve('crmPID', 'Integer');
760 //get the button name
761 $buttonName = $this->controller
->getButtonName();
763 if (isset($this->_ufGroupID
) && empty($this->_formValues
['uf_group_id'])) {
764 $this->_formValues
['uf_group_id'] = $this->_ufGroupID
;
767 if (isset($this->_componentMode
) && empty($this->_formValues
['component_mode'])) {
768 $this->_formValues
['component_mode'] = $this->_componentMode
;
771 if (isset($this->_operator
) && empty($this->_formValues
['operator'])) {
772 $this->_formValues
['operator'] = $this->_operator
;
775 if (empty($this->_formValues
['qfKey'])) {
776 $this->_formValues
['qfKey'] = $this->controller
->_key
;
779 if (!CRM_Core_Permission
::check('access deleted contacts')) {
780 unset($this->_formValues
['deleted_contacts']);
783 $this->set('type', $this->_action
);
784 $this->set('formValues', $this->_formValues
);
785 $this->set('queryParams', $this->_params
);
786 $this->set('returnProperties', $this->_returnProperties
);
788 if ($buttonName == $this->_actionButtonName
) {
789 // check actionName and if next, then do not repeat a search, since we are going to the next page
790 // hack, make sure we reset the task values
791 $stateMachine = $this->controller
->getStateMachine();
792 $formName = $stateMachine->getTaskFormName();
793 $this->controller
->resetPage($formName);
797 if (array_key_exists($this->getButtonName('refresh'), $_POST) ||
798 ($this->_force
&& !$crmPID)
800 //reset the cache table for new search
801 $cacheKey = "civicrm search {$this->controller->_key}";
802 Civi
::service('prevnext')->deleteItem(NULL, $cacheKey);
804 $output = CRM_Core_Selector_Controller
::SESSION
;
806 // create the selector, controller and run - store results in session
807 $searchChildGroups = TRUE;
808 if ($this->get('isAdvanced')) {
809 $searchChildGroups = FALSE;
814 if (strpos(self
::$_selectorName, 'CRM_Contact_Selector') !== FALSE) {
815 $selector = new self
::$_selectorName(
816 $this->_customSearchClass
,
819 $this->_returnProperties
,
829 $selector = new self
::$_selectorName(
840 $selector->setKey($this->controller
->_key
);
842 // added the sorting character to the form array
843 $config = CRM_Core_Config
::singleton();
844 // do this only for contact search
845 if ($setDynamic && $config->includeAlphabeticalPager
) {
846 // Don't recompute if we are just paging/sorting
847 if ($this->_reset ||
(empty($_GET['crmPID']) && empty($_GET['crmSID']) && !$this->_sortByCharacter
)) {
848 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($selector, $this->_sortByCharacter
);
849 $this->set('AToZBar', $aToZBar);
853 $controller = new CRM_Contact_Selector_Controller($selector,
854 $this->get(CRM_Utils_Pager
::PAGE_ID
),
856 CRM_Core_Action
::VIEW
,
860 $controller->setEmbedded(TRUE);
861 $controller->setDynamicAction($setDynamic);
869 public function &returnProperties() {
870 return CRM_Core_DAO
::$_nullObject;
874 * Return a descriptive name for the page, used in wizard header
878 public function getTitle() {
883 * Check Access for a component
884 * @param string $component
887 protected static function checkComponentAccess($component) {
888 $enabledComponents = CRM_Core_Component
::getEnabledComponents();
889 if (!array_key_exists($component, $enabledComponents)) {
892 return CRM_Core_Permission
::access($component);
896 * Load metadata for fields on the form.
898 * @throws \CiviCRM_API3_Exception
900 protected function loadMetadata() {
901 // can't by pass acls by passing search criteria in the url.
902 if (self
::checkComponentAccess('CiviContribute')) {
903 $this->addSearchFieldMetadata(['Contribution' => CRM_Contribute_BAO_Query
::getSearchFieldMetadata()]);
904 $this->addSearchFieldMetadata(['ContributionRecur' => CRM_Contribute_BAO_ContributionRecur
::getContributionRecurSearchFieldMetadata()]);
906 if (self
::checkComponentAccess('CiviPledge')) {
907 $this->addSearchFieldMetadata(['Pledge' => CRM_Pledge_BAO_Query
::getSearchFieldMetadata()]);
908 $this->addSearchFieldMetadata(['PledgePayment' => CRM_Pledge_BAO_Query
::getPledgePaymentSearchFieldMetadata()]);
910 if (self
::checkComponentAccess('CiviEvent')) {
911 $this->addSearchFieldMetadata(['Participant' => CRM_Event_BAO_Query
::getSearchFieldMetadata()]);
913 if (self
::checkComponentAccess('CiviMember')) {
914 $this->addSearchFieldMetadata(['Membership' => CRM_Member_BAO_Query
::getSearchFieldMetadata()]);
916 if (self
::checkComponentAccess('CiviGrant')) {
917 $this->addSearchFieldMetadata(['Grant' => CRM_Grant_BAO_Query
::getSearchFieldMetadata()]);
919 if (self
::checkComponentAccess('CiviCase')) {
920 $this->addSearchFieldMetadata(['Case' => CRM_Case_BAO_Query
::getSearchFieldMetadata()]);