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
35 * Base Search / View form for *all* listing of multiple
38 class CRM_Contact_Form_Search
extends CRM_Core_Form_Search
{
41 * list of valid contexts.
45 public static $_validContext = NULL;
48 * List of values used when we want to display other objects.
52 public static $_modeValues = NULL;
59 protected $_contextMenu;
62 * The groupId retrieved from the GET vars.
69 * The Group ID belonging to Add Member to group ID.
70 * retrieved from the GET vars
77 * The saved search ID retrieved from the GET vars.
89 public $_groupElement;
100 * The params used for search.
107 * The return properties used for search.
111 protected $_returnProperties;
114 * The sort by character.
118 protected $_sortByCharacter;
121 * The profile group id used for display.
125 protected $_ufGroupID;
128 * Csv - common search values
132 public static $csv = ['contact_type', 'group', 'tag'];
135 * How to display the results. Should we display as contributons, members, cases etc.
139 protected $_componentMode;
142 * What operator should we use, AND or OR.
146 protected $_operator;
148 protected $_modeValue;
151 * Declare entity reference fields as they will need to be converted to using 'IN'.
155 protected $entityReferenceFields = ['event_id', 'membership_type_id'];
158 * Name of the selector to use.
161 public static $_selectorName = 'CRM_Contact_Selector';
162 protected $_customSearchID = NULL;
163 protected $_customSearchClass = NULL;
165 protected $_openedPanes = [];
168 * Explicitly declare the entity api name.
170 public function getDefaultEntity() {
175 * Define the set of valid contexts that the search form operates on.
178 * the valid context set and the titles
180 public static function &validContext() {
181 if (!(self
::$_validContext)) {
182 self
::$_validContext = [
183 'smog' => 'Show members of group',
184 'amtg' => 'Add members to group',
185 'basic' => 'Basic Search',
186 'search' => 'Search',
187 'builder' => 'Search Builder',
188 'advanced' => 'Advanced Search',
189 'custom' => 'Custom Search',
192 return self
::$_validContext;
200 public static function isSearchContext($context) {
201 $searchContext = CRM_Utils_Array
::value($context, self
::validContext());
202 return $searchContext ?
TRUE : FALSE;
205 public static function setModeValues() {
206 self
::$_modeValues = [
207 CRM_Contact_BAO_Query
::MODE_CONTACTS
=> [
208 'selectorName' => self
::$_selectorName,
209 'selectorLabel' => ts('Contacts'),
210 'taskFile' => 'CRM/Contact/Form/Search/ResultTasks.tpl',
211 'taskContext' => NULL,
212 'resultFile' => 'CRM/Contact/Form/Selector.tpl',
213 'resultContext' => NULL,
214 'taskClassName' => 'CRM_Contact_Task',
217 CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
=> [
218 'selectorName' => 'CRM_Contribute_Selector_Search',
219 'selectorLabel' => ts('Contributions'),
220 'taskFile' => 'CRM/common/searchResultTasks.tpl',
221 'taskContext' => 'Contribution',
222 'resultFile' => 'CRM/Contribute/Form/Selector.tpl',
223 'resultContext' => 'Search',
224 'taskClassName' => 'CRM_Contribute_Task',
225 'component' => 'CiviContribute',
227 CRM_Contact_BAO_Query
::MODE_EVENT
=> [
228 'selectorName' => 'CRM_Event_Selector_Search',
229 'selectorLabel' => ts('Event Participants'),
230 'taskFile' => 'CRM/common/searchResultTasks.tpl',
231 'taskContext' => NULL,
232 'resultFile' => 'CRM/Event/Form/Selector.tpl',
233 'resultContext' => 'Search',
234 'taskClassName' => 'CRM_Event_Task',
235 'component' => 'CiviEvent',
237 CRM_Contact_BAO_Query
::MODE_ACTIVITY
=> [
238 'selectorName' => 'CRM_Activity_Selector_Search',
239 'selectorLabel' => ts('Activities'),
240 'taskFile' => 'CRM/common/searchResultTasks.tpl',
241 'taskContext' => NULL,
242 'resultFile' => 'CRM/Activity/Form/Selector.tpl',
243 'resultContext' => 'Search',
244 'taskClassName' => 'CRM_Activity_Task',
245 'component' => 'activity',
247 CRM_Contact_BAO_Query
::MODE_MEMBER
=> [
248 'selectorName' => 'CRM_Member_Selector_Search',
249 'selectorLabel' => ts('Memberships'),
250 'taskFile' => "CRM/common/searchResultTasks.tpl",
251 'taskContext' => NULL,
252 'resultFile' => 'CRM/Member/Form/Selector.tpl',
253 'resultContext' => 'Search',
254 'taskClassName' => 'CRM_Member_Task',
255 'component' => 'CiviMember',
257 CRM_Contact_BAO_Query
::MODE_CASE
=> [
258 'selectorName' => 'CRM_Case_Selector_Search',
259 'selectorLabel' => ts('Cases'),
260 'taskFile' => "CRM/common/searchResultTasks.tpl",
261 'taskContext' => NULL,
262 'resultFile' => 'CRM/Case/Form/Selector.tpl',
263 'resultContext' => 'Search',
264 'taskClassName' => 'CRM_Case_Task',
265 'component' => 'CiviCase',
267 CRM_Contact_BAO_Query
::MODE_CONTACTSRELATED
=> [
268 'selectorName' => self
::$_selectorName,
269 'selectorLabel' => ts('Related Contacts'),
270 'taskFile' => 'CRM/Contact/Form/Search/ResultTasks.tpl',
271 'taskContext' => NULL,
272 'resultFile' => 'CRM/Contact/Form/Selector.tpl',
273 'resultContext' => NULL,
274 'taskClassName' => 'CRM_Contact_Task',
275 'component' => 'related_contact',
277 CRM_Contact_BAO_Query
::MODE_MAILING
=> [
278 'selectorName' => 'CRM_Mailing_Selector_Search',
279 'selectorLabel' => ts('Mailings'),
280 'taskFile' => "CRM/common/searchResultTasks.tpl",
281 'taskContext' => NULL,
282 'resultFile' => 'CRM/Mailing/Form/Selector.tpl',
283 'resultContext' => 'Search',
284 'taskClassName' => 'CRM_Mailing_Task',
285 'component' => 'CiviMail',
291 * Get the metadata for the query mode (this includes task class names)
296 * @throws \CRM_Core_Exception
298 public static function getModeValue($mode = CRM_Contact_BAO_Query
::MODE_CONTACTS
) {
299 $searchPane = CRM_Utils_Request
::retrieve('searchPane', 'String');
300 if (!empty($searchPane)) {
301 $mode = array_search($searchPane, self
::getModeToComponentMapping());
304 self
::setModeValues();
305 if (!array_key_exists($mode, self
::$_modeValues)) {
306 $mode = CRM_Contact_BAO_Query
::MODE_CONTACTS
;
309 return self
::$_modeValues[$mode];
313 * Get a mapping of modes to components.
315 * This will map the integers to the components. Contact has an empty component
316 * an pseudo-components exist for activity & related_contact.
320 public static function getModeToComponentMapping() {
322 self
::setModeValues();
324 foreach (self
::$_modeValues as $id => $metadata) {
325 $mapping[$id] = $metadata['component'];
333 public static function getModeSelect() {
334 self
::setModeValues();
336 $enabledComponents = CRM_Core_Component
::getEnabledComponents();
337 $componentModes = [];
338 foreach (self
::$_modeValues as $id => & $value) {
339 if (strpos($value['component'], 'Civi') !== FALSE
340 && !array_key_exists($value['component'], $enabledComponents)
344 $componentModes[$id] = $value['selectorLabel'];
347 // unset disabled components
348 if (!array_key_exists('CiviMail', $enabledComponents)) {
349 unset($componentModes[CRM_Contact_BAO_Query
::MODE_MAILING
]);
352 // unset contributions or participants if user does not have permission on them
353 if (!CRM_Core_Permission
::access('CiviContribute')) {
354 unset($componentModes[CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
]);
357 if (!CRM_Core_Permission
::access('CiviEvent')) {
358 unset($componentModes[CRM_Contact_BAO_Query
::MODE_EVENT
]);
361 if (!CRM_Core_Permission
::access('CiviMember')) {
362 unset($componentModes[CRM_Contact_BAO_Query
::MODE_MEMBER
]);
365 if (!CRM_Core_Permission
::check('view all activities')) {
366 unset($componentModes[CRM_Contact_BAO_Query
::MODE_ACTIVITY
]);
369 return $componentModes;
373 * Builds the list of tasks or actions that a searcher can perform on a result set.
377 public function buildTaskList() {
378 // amtg = 'Add members to group'
379 if ($this->_context
!== 'amtg') {
380 $taskParams['deletedContacts'] = FALSE;
381 if ($this->_componentMode
== CRM_Contact_BAO_Query
::MODE_CONTACTS ||
$this->_componentMode
== CRM_Contact_BAO_Query
::MODE_CONTACTSRELATED
) {
382 $taskParams['deletedContacts'] = CRM_Utils_Array
::value('deleted_contacts', $this->_formValues
);
384 $className = $this->_modeValue
['taskClassName'];
385 $taskParams['ssID'] = isset($this->_ssID
) ?
$this->_ssID
: NULL;
386 $this->_taskList +
= $className::permissionedTaskTitles(CRM_Core_Permission
::getPermission(), $taskParams);
389 return $this->_taskList
;
393 * Build the common elements between the search/advanced form.
395 public function buildQuickForm() {
396 parent
::buildQuickForm();
398 // some tasks.. what do we want to do with the selected contacts ?
399 $this->_taskList
= $this->buildTaskList();
401 if (isset($this->_ssID
)) {
403 = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID
, 'search_custom_id');
405 $savedSearchValues = [
406 'id' => $this->_ssID
,
407 'name' => CRM_Contact_BAO_SavedSearch
::getName($this->_ssID
, 'title'),
408 'search_custom_id' => $search_custom_id,
410 $this->assign_by_ref('savedSearch', $savedSearchValues);
411 $this->assign('ssID', $this->_ssID
);
414 if ($this->_context
=== 'smog') {
415 // CRM-11788, we might want to do this for all of search where force=1
416 $formQFKey = CRM_Utils_Array
::value('qfKey', $this->_formValues
);
417 $getQFKey = CRM_Utils_Array
::value('qfKey', $_GET);
418 $postQFKey = CRM_Utils_Array
::value('qfKey', $_POST);
419 if ($formQFKey && empty($getQFKey) && empty($postQFKey)) {
420 $url = CRM_Utils_System
::makeURL('qfKey') . $formQFKey;
421 CRM_Utils_System
::redirect($url);
423 $permissionForGroup = FALSE;
425 if (!empty($this->_groupID
)) {
426 // check if user has permission to edit members of this group
427 $permission = CRM_Contact_BAO_Group
::checkPermission($this->_groupID
);
428 if ($permission && in_array(CRM_Core_Permission
::EDIT
, $permission)) {
429 $permissionForGroup = TRUE;
432 // check if _groupID exists, it might not if
433 // we are displaying a hidden group
434 if (!isset($this->_group
[$this->_groupID
])) {
435 $this->_group
[$this->_groupID
]
436 = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID
, 'title');
439 // set the group title
440 $groupValues = ['id' => $this->_groupID
, 'title' => $this->_group
[$this->_groupID
]];
441 $this->assign_by_ref('group', $groupValues);
443 // also set ssID if this is a saved search
444 $ssID = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID
, 'saved_search_id');
445 $this->assign('ssID', $ssID);
447 //get the saved search mapping id
449 $this->_ssID
= $ssID;
450 $ssMappingId = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id');
451 $this->assign('ssMappingID', $ssMappingId);
454 // Set dynamic page title for 'Show Members of Group'
455 CRM_Utils_System
::setTitle(ts('Contacts in Group: %1', [1 => $this->_group
[$this->_groupID
]]));
458 $group_contact_status = [];
459 foreach (CRM_Core_SelectValues
::groupContactStatus() as $k => $v) {
461 $group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v);
464 $this->addGroup($group_contact_status,
465 'group_contact_status', ts('Group Status')
468 $this->assign('permissionedForGroup', $permissionForGroup);
471 // add the go button for the action form, note it is of type 'next' rather than of type 'submit'
472 if ($this->_context
=== 'amtg') {
473 // check if _groupID exists, it might not if
474 // we are displaying a hidden group
475 if (!isset($this->_group
[$this->_amtgID
])) {
476 $this->assign('permissionedForGroup', FALSE);
477 $this->_group
[$this->_amtgID
]
478 = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_amtgID
, 'title');
481 // Set dynamic page title for 'Add Members Group'
482 CRM_Utils_System
::setTitle(ts('Add to Group: %1', [1 => $this->_group
[$this->_amtgID
]]));
483 // also set the group title and freeze the action task with Add Members to Group
484 $groupValues = ['id' => $this->_amtgID
, 'title' => $this->_group
[$this->_amtgID
]];
485 $this->assign_by_ref('group', $groupValues);
486 $this->add('submit', $this->_actionButtonName
, ts('Add Contacts to %1', [1 => $this->_group
[$this->_amtgID
]]),
488 'class' => 'crm-form-submit',
491 $this->add('hidden', 'task', CRM_Contact_Task
::GROUP_ADD
);
492 $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', ['checked' => 'checked']);
493 $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all');
494 $this->assign('ts_sel_id', $selectedRowsRadio->_attributes
['id']);
495 $this->assign('ts_all_id', $allRowsRadio->_attributes
['id']);
498 $selectedContactIds = [];
499 $qfKeyParam = CRM_Utils_Array
::value('qfKey', $this->_formValues
);
500 // We use ajax to handle selections only if the search results component_mode is set to "contacts"
501 if ($qfKeyParam && ($this->get('component_mode') <= CRM_Contact_BAO_Query
::MODE_CONTACTS ||
$this->get('component_mode') == CRM_Contact_BAO_Query
::MODE_CONTACTSRELATED
)) {
502 $this->addClass('crm-ajax-selection-form');
503 $qfKeyParam = "civicrm search {$qfKeyParam}";
504 $selectedContactIdsArr = Civi
::service('prevnext')->getSelection($qfKeyParam);
505 $selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]);
508 $this->assign_by_ref('selectedContactIds', $selectedContactIds);
510 $rows = $this->get('rows');
512 if (is_array($rows)) {
513 $this->addRowSelectors($rows);
519 * Processing needed for buildForm and later.
521 public function preProcess() {
522 // set the various class variables
524 $this->_group
= CRM_Core_PseudoConstant
::group();
526 $this->_tag
= CRM_Core_BAO_Tag
::getTags();
527 $this->_done
= FALSE;
530 * we allow the controller to set force/reset externally, useful when we are being
531 * driven by the wizard framework
534 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean');
536 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean');
537 $this->_groupID
= CRM_Utils_Request
::retrieve('gid', 'Positive', $this);
538 $this->_amtgID
= CRM_Utils_Request
::retrieve('amtgID', 'Positive', $this);
539 $this->_ssID
= CRM_Utils_Request
::retrieve('ssID', 'Positive', $this);
540 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter', 'String', $this);
541 $this->_ufGroupID
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
542 $this->_componentMode
= CRM_Utils_Request
::retrieve('component_mode', 'Positive', $this, FALSE, CRM_Contact_BAO_Query
::MODE_CONTACTS
, $_REQUEST);
543 $this->_operator
= CRM_Utils_Request
::retrieve('operator', 'String', $this, FALSE, CRM_Contact_BAO_Query
::SEARCH_OPERATOR_AND
, 'REQUEST');
546 * set the button names
548 $this->_searchButtonName
= $this->getButtonName('refresh');
549 $this->_actionButtonName
= $this->getButtonName('next', 'action');
551 $this->assign('actionButtonName', $this->_actionButtonName
);
553 // if we dont get this from the url, use default if one exsts
554 $config = CRM_Core_Config
::singleton();
555 if ($this->_ufGroupID
== NULL &&
556 $config->defaultSearchProfileID
!= NULL
558 $this->_ufGroupID
= $config->defaultSearchProfileID
;
561 // assign context to drive the template display, make sure context is valid
562 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this, FALSE, 'search');
563 if (!CRM_Utils_Array
::value($this->_context
, self
::validContext())) {
564 $this->_context
= 'search';
566 $this->set('context', $this->_context
);
567 $this->assign('context', $this->_context
);
569 $this->_modeValue
= self
::getModeValue($this->_componentMode
);
570 $this->assign($this->_modeValue
);
572 $this->set('selectorName', self
::$_selectorName);
574 // get user submitted values
575 // get it from controller only if form has been submitted, else preProcess has set this
576 // $this->controller->isModal( ) returns TRUE if page is
577 // valid, i.e all the validations are TRUE
579 if (!empty($_POST) && !$this->controller
->isModal()) {
580 $this->_formValues
= $this->controller
->exportValues($this->_name
);
582 $this->normalizeFormValues();
583 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, $this->entityReferenceFields
);
584 $this->_returnProperties
= &$this->returnProperties();
586 // also get the uf group id directly from the post value
587 $this->_ufGroupID
= CRM_Utils_Array
::value('uf_group_id', $_POST, $this->_ufGroupID
);
588 $this->_formValues
['uf_group_id'] = $this->_ufGroupID
;
589 $this->set('id', $this->_ufGroupID
);
591 // also get the object mode directly from the post value
592 $this->_componentMode
= CRM_Utils_Array
::value('component_mode', $_POST, $this->_componentMode
);
594 // also get the operator from the post value if set
595 $this->_operator
= CRM_Utils_Array
::value('operator', $_POST, $this->_operator
);
596 $this->_formValues
['operator'] = $this->_operator
;
597 $this->set('operator', $this->_operator
);
600 $this->_formValues
= $this->get('formValues');
601 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, $this->entityReferenceFields
);
602 $this->_returnProperties
= &$this->returnProperties();
603 if (!empty($this->_ufGroupID
)) {
604 $this->set('id', $this->_ufGroupID
);
608 if (empty($this->_formValues
)) {
609 //check if group is a smart group (fix for CRM-1255)
610 if ($this->_groupID
) {
611 if ($ssId = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID
, 'saved_search_id')) {
612 $this->_ssID
= $ssId;
617 if (isset($this->_ssID
) && $this->_context
!= 'smog') {
618 // we only retrieve the saved search values if out current values are null
619 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
622 if (CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID
, 'mapping_id')) {
623 $this->_params
= CRM_Contact_BAO_SavedSearch
::getSearchParams($this->_ssID
);
626 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
628 $this->_returnProperties
= &$this->returnProperties();
631 if (isset($this->_ufGroupID
)) {
632 // also set the uf group id if not already present
633 $this->_formValues
['uf_group_id'] = $this->_ufGroupID
;
635 if (isset($this->_componentMode
)) {
636 $this->_formValues
['component_mode'] = $this->_componentMode
;
638 if (isset($this->_operator
)) {
639 $this->_formValues
['operator'] = $this->_operator
;
642 // FIXME: we should generalise in a way that components could inject url-filters
643 // just like they build their own form elements
646 'mailing_delivery_status',
647 'mailing_open_status',
648 'mailing_click_status',
649 'mailing_reply_status',
652 'mailing_unsubscribe',
655 ] as $mailingFilter) {
657 if ($mailingFilter == 'mailing_id' &&
658 $filterVal = CRM_Utils_Request
::retrieve('mailing_id', 'Positive', $this)
660 $this->_formValues
[$mailingFilter] = [$filterVal];
662 elseif ($filterVal = CRM_Utils_Request
::retrieve($mailingFilter, $type, $this)) {
663 $this->_formValues
[$mailingFilter] = $filterVal;
666 $this->_openedPanes
['Mailings'] = 1;
667 $this->_formValues
['hidden_CiviMail'] = 1;
673 CRM_Utils_Array
::value('uf_group_id', $this->_formValues
)
675 $operator = CRM_Utils_Array
::value('operator', $this->_formValues
, CRM_Contact_BAO_Query
::SEARCH_OPERATOR_AND
);
676 $this->set('queryOperator', $operator);
677 if ($operator == CRM_Contact_BAO_Query
::SEARCH_OPERATOR_OR
) {
678 $this->assign('operator', ts('OR'));
681 $this->assign('operator', ts('AND'));
684 // show the context menu only when we’re not searching for deleted contacts; CRM-5673
685 if (empty($this->_formValues
['deleted_contacts'])) {
686 $menuItems = CRM_Contact_BAO_Contact
::contextMenu();
687 $primaryActions = CRM_Utils_Array
::value('primaryActions', $menuItems, []);
688 $this->_contextMenu
= CRM_Utils_Array
::value('moreActions', $menuItems, []);
689 $this->assign('contextMenu', $primaryActions +
$this->_contextMenu
);
692 if (!isset($this->_componentMode
)) {
693 $this->_componentMode
= CRM_Contact_BAO_Query
::MODE_CONTACTS
;
695 self
::$_selectorName = $this->_modeValue
['selectorName'];
696 self
::setModeValues();
699 if (strpos(self
::$_selectorName, 'CRM_Contact_Selector') !== FALSE) {
700 $selector = new self
::$_selectorName(
701 $this->_customSearchClass
,
704 $this->_returnProperties
,
713 $selector = new self
::$_selectorName(
721 $selector->setKey($this->controller
->_key
);
723 $controller = new CRM_Contact_Selector_Controller($selector,
724 $this->get(CRM_Utils_Pager
::PAGE_ID
),
725 $this->get(CRM_Utils_Sort
::SORT_ID
),
726 CRM_Core_Action
::VIEW
,
728 CRM_Core_Selector_Controller
::TRANSFER
730 $controller->setEmbedded(TRUE);
731 $controller->setDynamicAction($setDynamic);
734 $this->loadMetadata();
735 $this->postProcess();
738 * Note that we repeat this, since the search creates and stores
739 * values that potentially change the controller behavior. i.e. things
740 * like totalCount etc
743 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
744 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
745 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
748 $controller = new CRM_Contact_Selector_Controller($selector,
749 $this->get(CRM_Utils_Pager
::PAGE_ID
),
751 CRM_Core_Action
::VIEW
, $this, CRM_Core_Selector_Controller
::TRANSFER
753 $controller->setEmbedded(TRUE);
754 $controller->setDynamicAction($setDynamic);
757 $controller->moveFromSessionToTemplate();
761 * Common post processing.
763 public function postProcess() {
765 * sometime we do a postProcess early on, so we dont need to repeat it
766 * this will most likely introduce some more bugs :(
774 //for prev/next pagination
775 $crmPID = CRM_Utils_Request
::retrieve('crmPID', 'Integer');
777 //get the button name
778 $buttonName = $this->controller
->getButtonName();
780 if (isset($this->_ufGroupID
) && empty($this->_formValues
['uf_group_id'])) {
781 $this->_formValues
['uf_group_id'] = $this->_ufGroupID
;
784 if (isset($this->_componentMode
) && empty($this->_formValues
['component_mode'])) {
785 $this->_formValues
['component_mode'] = $this->_componentMode
;
788 if (isset($this->_operator
) && empty($this->_formValues
['operator'])) {
789 $this->_formValues
['operator'] = $this->_operator
;
792 if (empty($this->_formValues
['qfKey'])) {
793 $this->_formValues
['qfKey'] = $this->controller
->_key
;
796 if (!CRM_Core_Permission
::check('access deleted contacts')) {
797 unset($this->_formValues
['deleted_contacts']);
800 $this->set('type', $this->_action
);
801 $this->set('formValues', $this->_formValues
);
802 $this->set('queryParams', $this->_params
);
803 $this->set('returnProperties', $this->_returnProperties
);
805 if ($buttonName == $this->_actionButtonName
) {
806 // check actionName and if next, then do not repeat a search, since we are going to the next page
807 // hack, make sure we reset the task values
808 $stateMachine = $this->controller
->getStateMachine();
809 $formName = $stateMachine->getTaskFormName();
810 $this->controller
->resetPage($formName);
814 if (array_key_exists($this->_searchButtonName
, $_POST) ||
815 ($this->_force
&& !$crmPID)
817 //reset the cache table for new search
818 $cacheKey = "civicrm search {$this->controller->_key}";
819 Civi
::service('prevnext')->deleteItem(NULL, $cacheKey);
821 $output = CRM_Core_Selector_Controller
::SESSION
;
823 // create the selector, controller and run - store results in session
824 $searchChildGroups = TRUE;
825 if ($this->get('isAdvanced')) {
826 $searchChildGroups = FALSE;
831 if (strpos(self
::$_selectorName, 'CRM_Contact_Selector') !== FALSE) {
832 $selector = new self
::$_selectorName(
833 $this->_customSearchClass
,
836 $this->_returnProperties
,
846 $selector = new self
::$_selectorName(
857 $selector->setKey($this->controller
->_key
);
859 // added the sorting character to the form array
860 $config = CRM_Core_Config
::singleton();
861 // do this only for contact search
862 if ($setDynamic && $config->includeAlphabeticalPager
) {
863 // Don't recompute if we are just paging/sorting
864 if ($this->_reset ||
(empty($_GET['crmPID']) && empty($_GET['crmSID']) && !$this->_sortByCharacter
)) {
865 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($selector, $this->_sortByCharacter
);
866 $this->set('AToZBar', $aToZBar);
871 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
872 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
873 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
876 $controller = new CRM_Contact_Selector_Controller($selector,
877 $this->get(CRM_Utils_Pager
::PAGE_ID
),
879 CRM_Core_Action
::VIEW
,
883 $controller->setEmbedded(TRUE);
884 $controller->setDynamicAction($setDynamic);
892 public function &returnProperties() {
893 return CRM_Core_DAO
::$_nullObject;
897 * Return a descriptive name for the page, used in wizard header
901 public function getTitle() {
906 * Load metadata for fields on the form.
908 * @throws \CiviCRM_API3_Exception
910 protected function loadMetadata() {
911 // @todo - check what happens if the person does not have 'access civicontribute' - make sure they
912 // can't by pass acls by passing search criteria in the url.
913 $this->addSearchFieldMetadata(['Contribution' => CRM_Contribute_BAO_Query
::getSearchFieldMetadata()]);
914 $this->addSearchFieldMetadata(['ContributionRecur' => CRM_Contribute_BAO_ContributionRecur
::getContributionRecurSearchFieldMetadata()]);