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 // Note $mode might === FALSE because array_search above failed, e.g. for searchPane='location'
306 if (empty(self
::$_modeValues[$mode])) {
307 $mode = CRM_Contact_BAO_Query
::MODE_CONTACTS
;
310 return self
::$_modeValues[$mode];
314 * Get a mapping of modes to components.
316 * This will map the integers to the components. Contact has an empty component
317 * an pseudo-components exist for activity & related_contact.
321 public static function getModeToComponentMapping() {
323 self
::setModeValues();
325 foreach (self
::$_modeValues as $id => $metadata) {
326 $mapping[$id] = $metadata['component'];
334 public static function getModeSelect() {
335 self
::setModeValues();
337 $enabledComponents = CRM_Core_Component
::getEnabledComponents();
338 $componentModes = [];
339 foreach (self
::$_modeValues as $id => & $value) {
340 if (strpos($value['component'], 'Civi') !== FALSE
341 && !array_key_exists($value['component'], $enabledComponents)
345 $componentModes[$id] = $value['selectorLabel'];
348 // unset disabled components
349 if (!array_key_exists('CiviMail', $enabledComponents)) {
350 unset($componentModes[CRM_Contact_BAO_Query
::MODE_MAILING
]);
353 // unset contributions or participants if user does not have permission on them
354 if (!CRM_Core_Permission
::access('CiviContribute')) {
355 unset($componentModes[CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
]);
358 if (!CRM_Core_Permission
::access('CiviEvent')) {
359 unset($componentModes[CRM_Contact_BAO_Query
::MODE_EVENT
]);
362 if (!CRM_Core_Permission
::access('CiviMember')) {
363 unset($componentModes[CRM_Contact_BAO_Query
::MODE_MEMBER
]);
366 if (!CRM_Core_Permission
::check('view all activities')) {
367 unset($componentModes[CRM_Contact_BAO_Query
::MODE_ACTIVITY
]);
370 return $componentModes;
374 * Builds the list of tasks or actions that a searcher can perform on a result set.
378 public function buildTaskList() {
379 // amtg = 'Add members to group'
380 if ($this->_context
!== 'amtg') {
381 $taskParams['deletedContacts'] = FALSE;
382 if ($this->_componentMode
== CRM_Contact_BAO_Query
::MODE_CONTACTS ||
$this->_componentMode
== CRM_Contact_BAO_Query
::MODE_CONTACTSRELATED
) {
383 $taskParams['deletedContacts'] = CRM_Utils_Array
::value('deleted_contacts', $this->_formValues
);
385 $className = $this->_modeValue
['taskClassName'];
386 $taskParams['ssID'] = isset($this->_ssID
) ?
$this->_ssID
: NULL;
387 $this->_taskList +
= $className::permissionedTaskTitles(CRM_Core_Permission
::getPermission(), $taskParams);
390 return $this->_taskList
;
394 * Build the common elements between the search/advanced form.
396 public function buildQuickForm() {
397 parent
::buildQuickForm();
399 // some tasks.. what do we want to do with the selected contacts ?
400 $this->_taskList
= $this->buildTaskList();
402 if (isset($this->_ssID
)) {
404 = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID
, 'search_custom_id');
406 $savedSearchValues = [
407 'id' => $this->_ssID
,
408 'name' => CRM_Contact_BAO_SavedSearch
::getName($this->_ssID
, 'title'),
409 'search_custom_id' => $search_custom_id,
411 $this->assign_by_ref('savedSearch', $savedSearchValues);
412 $this->assign('ssID', $this->_ssID
);
415 if ($this->_context
=== 'smog') {
416 // CRM-11788, we might want to do this for all of search where force=1
417 $formQFKey = CRM_Utils_Array
::value('qfKey', $this->_formValues
);
418 $getQFKey = CRM_Utils_Array
::value('qfKey', $_GET);
419 $postQFKey = CRM_Utils_Array
::value('qfKey', $_POST);
420 if ($formQFKey && empty($getQFKey) && empty($postQFKey)) {
421 $url = CRM_Utils_System
::makeURL('qfKey') . $formQFKey;
422 CRM_Utils_System
::redirect($url);
424 $permissionForGroup = FALSE;
426 if (!empty($this->_groupID
)) {
427 // check if user has permission to edit members of this group
428 $permission = CRM_Contact_BAO_Group
::checkPermission($this->_groupID
);
429 if ($permission && in_array(CRM_Core_Permission
::EDIT
, $permission)) {
430 $permissionForGroup = TRUE;
433 // check if _groupID exists, it might not if
434 // we are displaying a hidden group
435 if (!isset($this->_group
[$this->_groupID
])) {
436 $this->_group
[$this->_groupID
]
437 = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID
, 'title');
440 // set the group title
441 $groupValues = ['id' => $this->_groupID
, 'title' => $this->_group
[$this->_groupID
]];
442 $this->assign_by_ref('group', $groupValues);
444 // also set ssID if this is a saved search
445 $ssID = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID
, 'saved_search_id');
446 $this->assign('ssID', $ssID);
448 //get the saved search mapping id
450 $this->_ssID
= $ssID;
451 $ssMappingId = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id');
452 $this->assign('ssMappingID', $ssMappingId);
455 // Set dynamic page title for 'Show Members of Group'
456 CRM_Utils_System
::setTitle(ts('Contacts in Group: %1', [1 => $this->_group
[$this->_groupID
]]));
459 $group_contact_status = [];
460 foreach (CRM_Core_SelectValues
::groupContactStatus() as $k => $v) {
462 $group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v);
465 $this->addGroup($group_contact_status,
466 'group_contact_status', ts('Group Status')
469 $this->assign('permissionedForGroup', $permissionForGroup);
472 // add the go button for the action form, note it is of type 'next' rather than of type 'submit'
473 if ($this->_context
=== 'amtg') {
474 // check if _groupID exists, it might not if
475 // we are displaying a hidden group
476 if (!isset($this->_group
[$this->_amtgID
])) {
477 $this->assign('permissionedForGroup', FALSE);
478 $this->_group
[$this->_amtgID
]
479 = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_amtgID
, 'title');
482 // Set dynamic page title for 'Add Members Group'
483 CRM_Utils_System
::setTitle(ts('Add to Group: %1', [1 => $this->_group
[$this->_amtgID
]]));
484 // also set the group title and freeze the action task with Add Members to Group
485 $groupValues = ['id' => $this->_amtgID
, 'title' => $this->_group
[$this->_amtgID
]];
486 $this->assign_by_ref('group', $groupValues);
487 $this->add('submit', $this->_actionButtonName
, ts('Add Contacts to %1', [1 => $this->_group
[$this->_amtgID
]]),
489 'class' => 'crm-form-submit',
492 $this->add('hidden', 'task', CRM_Contact_Task
::GROUP_ADD
);
493 $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', ['checked' => 'checked']);
494 $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all');
495 $this->assign('ts_sel_id', $selectedRowsRadio->_attributes
['id']);
496 $this->assign('ts_all_id', $allRowsRadio->_attributes
['id']);
499 $selectedContactIds = [];
500 $qfKeyParam = CRM_Utils_Array
::value('qfKey', $this->_formValues
);
501 // We use ajax to handle selections only if the search results component_mode is set to "contacts"
502 if ($qfKeyParam && ($this->get('component_mode') <= CRM_Contact_BAO_Query
::MODE_CONTACTS ||
$this->get('component_mode') == CRM_Contact_BAO_Query
::MODE_CONTACTSRELATED
)) {
503 $this->addClass('crm-ajax-selection-form');
504 $qfKeyParam = "civicrm search {$qfKeyParam}";
505 $selectedContactIdsArr = Civi
::service('prevnext')->getSelection($qfKeyParam);
506 $selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]);
509 $this->assign_by_ref('selectedContactIds', $selectedContactIds);
511 $rows = $this->get('rows');
513 if (is_array($rows)) {
514 $this->addRowSelectors($rows);
520 * Processing needed for buildForm and later.
522 public function preProcess() {
523 // set the various class variables
525 $this->_group
= CRM_Core_PseudoConstant
::group();
527 $this->_tag
= CRM_Core_BAO_Tag
::getTags();
528 $this->_done
= FALSE;
531 * we allow the controller to set force/reset externally, useful when we are being
532 * driven by the wizard framework
535 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean');
537 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean');
538 $this->_groupID
= CRM_Utils_Request
::retrieve('gid', 'Positive', $this);
539 $this->_amtgID
= CRM_Utils_Request
::retrieve('amtgID', 'Positive', $this);
540 $this->_ssID
= CRM_Utils_Request
::retrieve('ssID', 'Positive', $this);
541 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter', 'String', $this);
542 $this->_ufGroupID
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
543 $this->_componentMode
= CRM_Utils_Request
::retrieve('component_mode', 'Positive', $this, FALSE, CRM_Contact_BAO_Query
::MODE_CONTACTS
, $_REQUEST);
544 $this->_operator
= CRM_Utils_Request
::retrieve('operator', 'String', $this, FALSE, CRM_Contact_BAO_Query
::SEARCH_OPERATOR_AND
, 'REQUEST');
547 * set the button names
549 $this->_searchButtonName
= $this->getButtonName('refresh');
550 $this->_actionButtonName
= $this->getButtonName('next', 'action');
552 $this->assign('actionButtonName', $this->_actionButtonName
);
554 // if we dont get this from the url, use default if one exsts
555 $config = CRM_Core_Config
::singleton();
556 if ($this->_ufGroupID
== NULL &&
557 $config->defaultSearchProfileID
!= NULL
559 $this->_ufGroupID
= $config->defaultSearchProfileID
;
562 // assign context to drive the template display, make sure context is valid
563 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this, FALSE, 'search');
564 if (!CRM_Utils_Array
::value($this->_context
, self
::validContext())) {
565 $this->_context
= 'search';
567 $this->set('context', $this->_context
);
568 $this->assign('context', $this->_context
);
570 $this->_modeValue
= self
::getModeValue($this->_componentMode
);
571 $this->assign($this->_modeValue
);
573 $this->set('selectorName', self
::$_selectorName);
575 // get user submitted values
576 // get it from controller only if form has been submitted, else preProcess has set this
577 // $this->controller->isModal( ) returns TRUE if page is
578 // valid, i.e all the validations are TRUE
580 if (!empty($_POST) && !$this->controller
->isModal()) {
581 $this->_formValues
= $this->controller
->exportValues($this->_name
);
583 $this->normalizeFormValues();
584 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, $this->entityReferenceFields
);
585 $this->_returnProperties
= &$this->returnProperties();
587 // also get the uf group id directly from the post value
588 $this->_ufGroupID
= CRM_Utils_Array
::value('uf_group_id', $_POST, $this->_ufGroupID
);
589 $this->_formValues
['uf_group_id'] = $this->_ufGroupID
;
590 $this->set('id', $this->_ufGroupID
);
592 // also get the object mode directly from the post value
593 $this->_componentMode
= CRM_Utils_Array
::value('component_mode', $_POST, $this->_componentMode
);
595 // also get the operator from the post value if set
596 $this->_operator
= CRM_Utils_Array
::value('operator', $_POST, $this->_operator
);
597 $this->_formValues
['operator'] = $this->_operator
;
598 $this->set('operator', $this->_operator
);
601 $this->_formValues
= $this->get('formValues');
602 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, $this->entityReferenceFields
);
603 $this->_returnProperties
= &$this->returnProperties();
604 if (!empty($this->_ufGroupID
)) {
605 $this->set('id', $this->_ufGroupID
);
609 if (empty($this->_formValues
)) {
610 //check if group is a smart group (fix for CRM-1255)
611 if ($this->_groupID
) {
612 if ($ssId = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID
, 'saved_search_id')) {
613 $this->_ssID
= $ssId;
618 if (isset($this->_ssID
) && $this->_context
!= 'smog') {
619 // we only retrieve the saved search values if out current values are null
620 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
623 if (CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID
, 'mapping_id')) {
624 $this->_params
= CRM_Contact_BAO_SavedSearch
::getSearchParams($this->_ssID
);
627 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
629 $this->_returnProperties
= &$this->returnProperties();
632 if (isset($this->_ufGroupID
)) {
633 // also set the uf group id if not already present
634 $this->_formValues
['uf_group_id'] = $this->_ufGroupID
;
636 if (isset($this->_componentMode
)) {
637 $this->_formValues
['component_mode'] = $this->_componentMode
;
639 if (isset($this->_operator
)) {
640 $this->_formValues
['operator'] = $this->_operator
;
643 // FIXME: we should generalise in a way that components could inject url-filters
644 // just like they build their own form elements
647 'mailing_delivery_status',
648 'mailing_open_status',
649 'mailing_click_status',
650 'mailing_reply_status',
653 'mailing_unsubscribe',
656 'mailing_job_start_date_low',
657 'mailing_job_start_date_high',
658 'mailing_job_start_date_relative',
659 ] as $mailingFilter) {
661 if ($mailingFilter == 'mailing_id' &&
662 $filterVal = CRM_Utils_Request
::retrieve('mailing_id', 'Positive', $this)
664 $this->_formValues
[$mailingFilter] = [$filterVal];
666 elseif ($filterVal = CRM_Utils_Request
::retrieve($mailingFilter, $type, $this)) {
667 $this->_formValues
[$mailingFilter] = $filterVal;
670 $this->_openedPanes
['Mailings'] = 1;
671 $this->_formValues
['hidden_CiviMail'] = 1;
677 CRM_Utils_Array
::value('uf_group_id', $this->_formValues
)
679 $operator = CRM_Utils_Array
::value('operator', $this->_formValues
, CRM_Contact_BAO_Query
::SEARCH_OPERATOR_AND
);
680 $this->set('queryOperator', $operator);
681 if ($operator == CRM_Contact_BAO_Query
::SEARCH_OPERATOR_OR
) {
682 $this->assign('operator', ts('OR'));
685 $this->assign('operator', ts('AND'));
688 // show the context menu only when we’re not searching for deleted contacts; CRM-5673
689 if (empty($this->_formValues
['deleted_contacts'])) {
690 $menuItems = CRM_Contact_BAO_Contact
::contextMenu();
691 $primaryActions = CRM_Utils_Array
::value('primaryActions', $menuItems, []);
692 $this->_contextMenu
= CRM_Utils_Array
::value('moreActions', $menuItems, []);
693 $this->assign('contextMenu', $primaryActions +
$this->_contextMenu
);
696 if (!isset($this->_componentMode
)) {
697 $this->_componentMode
= CRM_Contact_BAO_Query
::MODE_CONTACTS
;
699 self
::$_selectorName = $this->_modeValue
['selectorName'];
700 self
::setModeValues();
703 if (strpos(self
::$_selectorName, 'CRM_Contact_Selector') !== FALSE) {
704 $selector = new self
::$_selectorName(
705 $this->_customSearchClass
,
708 $this->_returnProperties
,
717 $selector = new self
::$_selectorName(
725 $selector->setKey($this->controller
->_key
);
727 $controller = new CRM_Contact_Selector_Controller($selector,
728 $this->get(CRM_Utils_Pager
::PAGE_ID
),
729 $this->get(CRM_Utils_Sort
::SORT_ID
),
730 CRM_Core_Action
::VIEW
,
732 CRM_Core_Selector_Controller
::TRANSFER
734 $controller->setEmbedded(TRUE);
735 $controller->setDynamicAction($setDynamic);
738 $this->loadMetadata();
739 $this->postProcess();
742 * Note that we repeat this, since the search creates and stores
743 * values that potentially change the controller behavior. i.e. things
744 * like totalCount etc
747 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
748 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
749 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
752 $controller = new CRM_Contact_Selector_Controller($selector,
753 $this->get(CRM_Utils_Pager
::PAGE_ID
),
755 CRM_Core_Action
::VIEW
, $this, CRM_Core_Selector_Controller
::TRANSFER
757 $controller->setEmbedded(TRUE);
758 $controller->setDynamicAction($setDynamic);
761 $controller->moveFromSessionToTemplate();
765 * Common post processing.
767 public function postProcess() {
769 * sometime we do a postProcess early on, so we dont need to repeat it
770 * this will most likely introduce some more bugs :(
778 //for prev/next pagination
779 $crmPID = CRM_Utils_Request
::retrieve('crmPID', 'Integer');
781 //get the button name
782 $buttonName = $this->controller
->getButtonName();
784 if (isset($this->_ufGroupID
) && empty($this->_formValues
['uf_group_id'])) {
785 $this->_formValues
['uf_group_id'] = $this->_ufGroupID
;
788 if (isset($this->_componentMode
) && empty($this->_formValues
['component_mode'])) {
789 $this->_formValues
['component_mode'] = $this->_componentMode
;
792 if (isset($this->_operator
) && empty($this->_formValues
['operator'])) {
793 $this->_formValues
['operator'] = $this->_operator
;
796 if (empty($this->_formValues
['qfKey'])) {
797 $this->_formValues
['qfKey'] = $this->controller
->_key
;
800 if (!CRM_Core_Permission
::check('access deleted contacts')) {
801 unset($this->_formValues
['deleted_contacts']);
804 $this->set('type', $this->_action
);
805 $this->set('formValues', $this->_formValues
);
806 $this->set('queryParams', $this->_params
);
807 $this->set('returnProperties', $this->_returnProperties
);
809 if ($buttonName == $this->_actionButtonName
) {
810 // check actionName and if next, then do not repeat a search, since we are going to the next page
811 // hack, make sure we reset the task values
812 $stateMachine = $this->controller
->getStateMachine();
813 $formName = $stateMachine->getTaskFormName();
814 $this->controller
->resetPage($formName);
818 if (array_key_exists($this->_searchButtonName
, $_POST) ||
819 ($this->_force
&& !$crmPID)
821 //reset the cache table for new search
822 $cacheKey = "civicrm search {$this->controller->_key}";
823 Civi
::service('prevnext')->deleteItem(NULL, $cacheKey);
825 $output = CRM_Core_Selector_Controller
::SESSION
;
827 // create the selector, controller and run - store results in session
828 $searchChildGroups = TRUE;
829 if ($this->get('isAdvanced')) {
830 $searchChildGroups = FALSE;
835 if (strpos(self
::$_selectorName, 'CRM_Contact_Selector') !== FALSE) {
836 $selector = new self
::$_selectorName(
837 $this->_customSearchClass
,
840 $this->_returnProperties
,
850 $selector = new self
::$_selectorName(
861 $selector->setKey($this->controller
->_key
);
863 // added the sorting character to the form array
864 $config = CRM_Core_Config
::singleton();
865 // do this only for contact search
866 if ($setDynamic && $config->includeAlphabeticalPager
) {
867 // Don't recompute if we are just paging/sorting
868 if ($this->_reset ||
(empty($_GET['crmPID']) && empty($_GET['crmSID']) && !$this->_sortByCharacter
)) {
869 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($selector, $this->_sortByCharacter
);
870 $this->set('AToZBar', $aToZBar);
875 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
876 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
877 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
880 $controller = new CRM_Contact_Selector_Controller($selector,
881 $this->get(CRM_Utils_Pager
::PAGE_ID
),
883 CRM_Core_Action
::VIEW
,
887 $controller->setEmbedded(TRUE);
888 $controller->setDynamicAction($setDynamic);
896 public function &returnProperties() {
897 return CRM_Core_DAO
::$_nullObject;
901 * Return a descriptive name for the page, used in wizard header
905 public function getTitle() {
910 * Load metadata for fields on the form.
912 * @throws \CiviCRM_API3_Exception
914 protected function loadMetadata() {
915 // @todo - check what happens if the person does not have 'access civicontribute' - make sure they
916 // can't by pass acls by passing search criteria in the url.
917 $this->addSearchFieldMetadata(['Contribution' => CRM_Contribute_BAO_Query
::getSearchFieldMetadata()]);
918 $this->addSearchFieldMetadata(['ContributionRecur' => CRM_Contribute_BAO_ContributionRecur
::getContributionRecurSearchFieldMetadata()]);