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 * @var string how to display the results. Should we display as
136 * contributons, members, cases etc
138 protected $_componentMode;
141 * @var string what operator should we use, AND or OR
143 protected $_operator;
145 protected $_modeValue;
148 * Declare entity reference fields as they will need to be converted to using 'IN'.
152 protected $entityReferenceFields = ['event_id', 'membership_type_id'];
155 * Name of the selector to use.
158 public static $_selectorName = 'CRM_Contact_Selector';
159 protected $_customSearchID = NULL;
160 protected $_customSearchClass = NULL;
162 protected $_openedPanes = [];
165 * Explicitly declare the entity api name.
167 public function getDefaultEntity() {
172 * Define the set of valid contexts that the search form operates on.
175 * the valid context set and the titles
177 public static function &validContext() {
178 if (!(self
::$_validContext)) {
179 self
::$_validContext = [
180 'smog' => 'Show members of group',
181 'amtg' => 'Add members to group',
182 'basic' => 'Basic Search',
183 'search' => 'Search',
184 'builder' => 'Search Builder',
185 'advanced' => 'Advanced Search',
186 'custom' => 'Custom Search',
189 return self
::$_validContext;
197 public static function isSearchContext($context) {
198 $searchContext = CRM_Utils_Array
::value($context, self
::validContext());
199 return $searchContext ?
TRUE : FALSE;
202 public static function setModeValues() {
203 self
::$_modeValues = [
204 CRM_Contact_BAO_Query
::MODE_CONTACTS
=> [
205 'selectorName' => self
::$_selectorName,
206 'selectorLabel' => ts('Contacts'),
207 'taskFile' => 'CRM/Contact/Form/Search/ResultTasks.tpl',
208 'taskContext' => NULL,
209 'resultFile' => 'CRM/Contact/Form/Selector.tpl',
210 'resultContext' => NULL,
211 'taskClassName' => 'CRM_Contact_Task',
214 CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
=> [
215 'selectorName' => 'CRM_Contribute_Selector_Search',
216 'selectorLabel' => ts('Contributions'),
217 'taskFile' => 'CRM/common/searchResultTasks.tpl',
218 'taskContext' => 'Contribution',
219 'resultFile' => 'CRM/Contribute/Form/Selector.tpl',
220 'resultContext' => 'Search',
221 'taskClassName' => 'CRM_Contribute_Task',
222 'component' => 'CiviContribute',
224 CRM_Contact_BAO_Query
::MODE_EVENT
=> [
225 'selectorName' => 'CRM_Event_Selector_Search',
226 'selectorLabel' => ts('Event Participants'),
227 'taskFile' => 'CRM/common/searchResultTasks.tpl',
228 'taskContext' => NULL,
229 'resultFile' => 'CRM/Event/Form/Selector.tpl',
230 'resultContext' => 'Search',
231 'taskClassName' => 'CRM_Event_Task',
232 'component' => 'CiviEvent',
234 CRM_Contact_BAO_Query
::MODE_ACTIVITY
=> [
235 'selectorName' => 'CRM_Activity_Selector_Search',
236 'selectorLabel' => ts('Activities'),
237 'taskFile' => 'CRM/common/searchResultTasks.tpl',
238 'taskContext' => NULL,
239 'resultFile' => 'CRM/Activity/Form/Selector.tpl',
240 'resultContext' => 'Search',
241 'taskClassName' => 'CRM_Activity_Task',
242 'component' => 'activity',
244 CRM_Contact_BAO_Query
::MODE_MEMBER
=> [
245 'selectorName' => 'CRM_Member_Selector_Search',
246 'selectorLabel' => ts('Memberships'),
247 'taskFile' => "CRM/common/searchResultTasks.tpl",
248 'taskContext' => NULL,
249 'resultFile' => 'CRM/Member/Form/Selector.tpl',
250 'resultContext' => 'Search',
251 'taskClassName' => 'CRM_Member_Task',
252 'component' => 'CiviMember',
254 CRM_Contact_BAO_Query
::MODE_CASE
=> [
255 'selectorName' => 'CRM_Case_Selector_Search',
256 'selectorLabel' => ts('Cases'),
257 'taskFile' => "CRM/common/searchResultTasks.tpl",
258 'taskContext' => NULL,
259 'resultFile' => 'CRM/Case/Form/Selector.tpl',
260 'resultContext' => 'Search',
261 'taskClassName' => 'CRM_Case_Task',
262 'component' => 'CiviCase',
264 CRM_Contact_BAO_Query
::MODE_CONTACTSRELATED
=> [
265 'selectorName' => self
::$_selectorName,
266 'selectorLabel' => ts('Related Contacts'),
267 'taskFile' => 'CRM/Contact/Form/Search/ResultTasks.tpl',
268 'taskContext' => NULL,
269 'resultFile' => 'CRM/Contact/Form/Selector.tpl',
270 'resultContext' => NULL,
271 'taskClassName' => 'CRM_Contact_Task',
272 'component' => 'related_contact',
274 CRM_Contact_BAO_Query
::MODE_MAILING
=> [
275 'selectorName' => 'CRM_Mailing_Selector_Search',
276 'selectorLabel' => ts('Mailings'),
277 'taskFile' => "CRM/common/searchResultTasks.tpl",
278 'taskContext' => NULL,
279 'resultFile' => 'CRM/Mailing/Form/Selector.tpl',
280 'resultContext' => 'Search',
281 'taskClassName' => 'CRM_Mailing_Task',
282 'component' => 'CiviMail',
288 * Get the metadata for the query mode (this includes task class names)
293 * @throws \CRM_Core_Exception
295 public static function getModeValue($mode = CRM_Contact_BAO_Query
::MODE_CONTACTS
) {
296 $searchPane = CRM_Utils_Request
::retrieve('searchPane', 'String');
297 if (!empty($searchPane)) {
298 $mode = array_search($searchPane, self
::getModeToComponentMapping());
301 self
::setModeValues();
302 if (!array_key_exists($mode, self
::$_modeValues)) {
303 $mode = CRM_Contact_BAO_Query
::MODE_CONTACTS
;
306 return self
::$_modeValues[$mode];
310 * Get a mapping of modes to components.
312 * This will map the integers to the components. Contact has an empty component
313 * an pseudo-components exist for activity & related_contact.
317 public static function getModeToComponentMapping() {
319 self
::setModeValues();
321 foreach (self
::$_modeValues as $id => $metadata) {
322 $mapping[$id] = $metadata['component'];
330 public static function getModeSelect() {
331 self
::setModeValues();
333 $enabledComponents = CRM_Core_Component
::getEnabledComponents();
334 $componentModes = [];
335 foreach (self
::$_modeValues as $id => & $value) {
336 if (strpos($value['component'], 'Civi') !== FALSE
337 && !array_key_exists($value['component'], $enabledComponents)
341 $componentModes[$id] = $value['selectorLabel'];
344 // unset disabled components
345 if (!array_key_exists('CiviMail', $enabledComponents)) {
346 unset($componentModes[CRM_Contact_BAO_Query
::MODE_MAILING
]);
349 // unset contributions or participants if user does not have permission on them
350 if (!CRM_Core_Permission
::access('CiviContribute')) {
351 unset($componentModes[CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
]);
354 if (!CRM_Core_Permission
::access('CiviEvent')) {
355 unset($componentModes[CRM_Contact_BAO_Query
::MODE_EVENT
]);
358 if (!CRM_Core_Permission
::access('CiviMember')) {
359 unset($componentModes[CRM_Contact_BAO_Query
::MODE_MEMBER
]);
362 if (!CRM_Core_Permission
::check('view all activities')) {
363 unset($componentModes[CRM_Contact_BAO_Query
::MODE_ACTIVITY
]);
366 return $componentModes;
370 * Builds the list of tasks or actions that a searcher can perform on a result set.
374 public function buildTaskList() {
375 // amtg = 'Add members to group'
376 if ($this->_context
!== 'amtg') {
377 $taskParams['deletedContacts'] = FALSE;
378 if ($this->_componentMode
== CRM_Contact_BAO_Query
::MODE_CONTACTS ||
$this->_componentMode
== CRM_Contact_BAO_Query
::MODE_CONTACTSRELATED
) {
379 $taskParams['deletedContacts'] = CRM_Utils_Array
::value('deleted_contacts', $this->_formValues
);
381 $className = $this->_modeValue
['taskClassName'];
382 $taskParams['ssID'] = isset($this->_ssID
) ?
$this->_ssID
: NULL;
383 $this->_taskList +
= $className::permissionedTaskTitles(CRM_Core_Permission
::getPermission(), $taskParams);
386 return $this->_taskList
;
390 * Build the common elements between the search/advanced form.
392 public function buildQuickForm() {
393 parent
::buildQuickForm();
395 // some tasks.. what do we want to do with the selected contacts ?
396 $this->_taskList
= $this->buildTaskList();
398 if (isset($this->_ssID
)) {
400 = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID
, 'search_custom_id');
402 $savedSearchValues = [
403 'id' => $this->_ssID
,
404 'name' => CRM_Contact_BAO_SavedSearch
::getName($this->_ssID
, 'title'),
405 'search_custom_id' => $search_custom_id,
407 $this->assign_by_ref('savedSearch', $savedSearchValues);
408 $this->assign('ssID', $this->_ssID
);
411 if ($this->_context
=== 'smog') {
412 // CRM-11788, we might want to do this for all of search where force=1
413 $formQFKey = CRM_Utils_Array
::value('qfKey', $this->_formValues
);
414 $getQFKey = CRM_Utils_Array
::value('qfKey', $_GET);
415 $postQFKey = CRM_Utils_Array
::value('qfKey', $_POST);
416 if ($formQFKey && empty($getQFKey) && empty($postQFKey)) {
417 $url = CRM_Utils_System
::makeURL('qfKey') . $formQFKey;
418 CRM_Utils_System
::redirect($url);
420 $permissionForGroup = FALSE;
422 if (!empty($this->_groupID
)) {
423 // check if user has permission to edit members of this group
424 $permission = CRM_Contact_BAO_Group
::checkPermission($this->_groupID
);
425 if ($permission && in_array(CRM_Core_Permission
::EDIT
, $permission)) {
426 $permissionForGroup = TRUE;
429 // check if _groupID exists, it might not if
430 // we are displaying a hidden group
431 if (!isset($this->_group
[$this->_groupID
])) {
432 $this->_group
[$this->_groupID
]
433 = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID
, 'title');
436 // set the group title
437 $groupValues = ['id' => $this->_groupID
, 'title' => $this->_group
[$this->_groupID
]];
438 $this->assign_by_ref('group', $groupValues);
440 // also set ssID if this is a saved search
441 $ssID = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID
, 'saved_search_id');
442 $this->assign('ssID', $ssID);
444 //get the saved search mapping id
446 $this->_ssID
= $ssID;
447 $ssMappingId = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id');
448 $this->assign('ssMappingID', $ssMappingId);
451 // Set dynamic page title for 'Show Members of Group'
452 CRM_Utils_System
::setTitle(ts('Contacts in Group: %1', [1 => $this->_group
[$this->_groupID
]]));
455 $group_contact_status = [];
456 foreach (CRM_Core_SelectValues
::groupContactStatus() as $k => $v) {
458 $group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v);
461 $this->addGroup($group_contact_status,
462 'group_contact_status', ts('Group Status')
465 $this->assign('permissionedForGroup', $permissionForGroup);
468 // add the go button for the action form, note it is of type 'next' rather than of type 'submit'
469 if ($this->_context
=== 'amtg') {
470 // check if _groupID exists, it might not if
471 // we are displaying a hidden group
472 if (!isset($this->_group
[$this->_amtgID
])) {
473 $this->assign('permissionedForGroup', FALSE);
474 $this->_group
[$this->_amtgID
]
475 = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_amtgID
, 'title');
478 // Set dynamic page title for 'Add Members Group'
479 CRM_Utils_System
::setTitle(ts('Add to Group: %1', [1 => $this->_group
[$this->_amtgID
]]));
480 // also set the group title and freeze the action task with Add Members to Group
481 $groupValues = ['id' => $this->_amtgID
, 'title' => $this->_group
[$this->_amtgID
]];
482 $this->assign_by_ref('group', $groupValues);
483 $this->add('submit', $this->_actionButtonName
, ts('Add Contacts to %1', [1 => $this->_group
[$this->_amtgID
]]),
485 'class' => 'crm-form-submit',
488 $this->add('hidden', 'task', CRM_Contact_Task
::GROUP_ADD
);
489 $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', ['checked' => 'checked']);
490 $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all');
491 $this->assign('ts_sel_id', $selectedRowsRadio->_attributes
['id']);
492 $this->assign('ts_all_id', $allRowsRadio->_attributes
['id']);
495 $selectedContactIds = [];
496 $qfKeyParam = CRM_Utils_Array
::value('qfKey', $this->_formValues
);
497 // We use ajax to handle selections only if the search results component_mode is set to "contacts"
498 if ($qfKeyParam && ($this->get('component_mode') <= CRM_Contact_BAO_Query
::MODE_CONTACTS ||
$this->get('component_mode') == CRM_Contact_BAO_Query
::MODE_CONTACTSRELATED
)) {
499 $this->addClass('crm-ajax-selection-form');
500 $qfKeyParam = "civicrm search {$qfKeyParam}";
501 $selectedContactIdsArr = Civi
::service('prevnext')->getSelection($qfKeyParam);
502 $selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]);
505 $this->assign_by_ref('selectedContactIds', $selectedContactIds);
507 $rows = $this->get('rows');
509 if (is_array($rows)) {
510 $this->addRowSelectors($rows);
516 * Processing needed for buildForm and later.
518 public function preProcess() {
519 // set the various class variables
521 $this->_group
= CRM_Core_PseudoConstant
::group();
523 $this->_tag
= CRM_Core_BAO_Tag
::getTags();
524 $this->_done
= FALSE;
527 * we allow the controller to set force/reset externally, useful when we are being
528 * driven by the wizard framework
531 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean');
533 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean');
534 $this->_groupID
= CRM_Utils_Request
::retrieve('gid', 'Positive', $this);
535 $this->_amtgID
= CRM_Utils_Request
::retrieve('amtgID', 'Positive', $this);
536 $this->_ssID
= CRM_Utils_Request
::retrieve('ssID', 'Positive', $this);
537 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter', 'String', $this);
538 $this->_ufGroupID
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
539 $this->_componentMode
= CRM_Utils_Request
::retrieve('component_mode', 'Positive', $this, FALSE, CRM_Contact_BAO_Query
::MODE_CONTACTS
, $_REQUEST);
540 $this->_operator
= CRM_Utils_Request
::retrieve('operator', 'String', $this, FALSE, CRM_Contact_BAO_Query
::SEARCH_OPERATOR_AND
, 'REQUEST');
543 * set the button names
545 $this->_searchButtonName
= $this->getButtonName('refresh');
546 $this->_actionButtonName
= $this->getButtonName('next', 'action');
548 $this->assign('actionButtonName', $this->_actionButtonName
);
550 // if we dont get this from the url, use default if one exsts
551 $config = CRM_Core_Config
::singleton();
552 if ($this->_ufGroupID
== NULL &&
553 $config->defaultSearchProfileID
!= NULL
555 $this->_ufGroupID
= $config->defaultSearchProfileID
;
558 // assign context to drive the template display, make sure context is valid
559 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this, FALSE, 'search');
560 if (!CRM_Utils_Array
::value($this->_context
, self
::validContext())) {
561 $this->_context
= 'search';
563 $this->set('context', $this->_context
);
564 $this->assign('context', $this->_context
);
566 $this->_modeValue
= self
::getModeValue($this->_componentMode
);
567 $this->assign($this->_modeValue
);
569 $this->set('selectorName', self
::$_selectorName);
571 // get user submitted values
572 // get it from controller only if form has been submitted, else preProcess has set this
573 // $this->controller->isModal( ) returns TRUE if page is
574 // valid, i.e all the validations are TRUE
576 if (!empty($_POST) && !$this->controller
->isModal()) {
577 $this->_formValues
= $this->controller
->exportValues($this->_name
);
579 $this->normalizeFormValues();
580 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, $this->entityReferenceFields
);
581 $this->_returnProperties
= &$this->returnProperties();
583 // also get the uf group id directly from the post value
584 $this->_ufGroupID
= CRM_Utils_Array
::value('uf_group_id', $_POST, $this->_ufGroupID
);
585 $this->_formValues
['uf_group_id'] = $this->_ufGroupID
;
586 $this->set('id', $this->_ufGroupID
);
588 // also get the object mode directly from the post value
589 $this->_componentMode
= CRM_Utils_Array
::value('component_mode', $_POST, $this->_componentMode
);
591 // also get the operator from the post value if set
592 $this->_operator
= CRM_Utils_Array
::value('operator', $_POST, $this->_operator
);
593 $this->_formValues
['operator'] = $this->_operator
;
594 $this->set('operator', $this->_operator
);
597 $this->_formValues
= $this->get('formValues');
598 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
, 0, FALSE, NULL, $this->entityReferenceFields
);
599 $this->_returnProperties
= &$this->returnProperties();
600 if (!empty($this->_ufGroupID
)) {
601 $this->set('id', $this->_ufGroupID
);
605 if (empty($this->_formValues
)) {
606 //check if group is a smart group (fix for CRM-1255)
607 if ($this->_groupID
) {
608 if ($ssId = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID
, 'saved_search_id')) {
609 $this->_ssID
= $ssId;
614 if (isset($this->_ssID
) && $this->_context
!= 'smog') {
615 // we only retrieve the saved search values if out current values are null
616 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
619 if (CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID
, 'mapping_id')) {
620 $this->_params
= CRM_Contact_BAO_SavedSearch
::getSearchParams($this->_ssID
);
623 $this->_params
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
625 $this->_returnProperties
= &$this->returnProperties();
628 if (isset($this->_ufGroupID
)) {
629 // also set the uf group id if not already present
630 $this->_formValues
['uf_group_id'] = $this->_ufGroupID
;
632 if (isset($this->_componentMode
)) {
633 $this->_formValues
['component_mode'] = $this->_componentMode
;
635 if (isset($this->_operator
)) {
636 $this->_formValues
['operator'] = $this->_operator
;
639 // FIXME: we should generalise in a way that components could inject url-filters
640 // just like they build their own form elements
643 'mailing_delivery_status',
644 'mailing_open_status',
645 'mailing_click_status',
646 'mailing_reply_status',
649 'mailing_unsubscribe',
652 ] as $mailingFilter) {
654 if ($mailingFilter == 'mailing_id' &&
655 $filterVal = CRM_Utils_Request
::retrieve('mailing_id', 'Positive', $this)
657 $this->_formValues
[$mailingFilter] = [$filterVal];
659 elseif ($filterVal = CRM_Utils_Request
::retrieve($mailingFilter, $type, $this)) {
660 $this->_formValues
[$mailingFilter] = $filterVal;
663 $this->_openedPanes
['Mailings'] = 1;
664 $this->_formValues
['hidden_CiviMail'] = 1;
670 CRM_Utils_Array
::value('uf_group_id', $this->_formValues
)
672 $operator = CRM_Utils_Array
::value('operator', $this->_formValues
, CRM_Contact_BAO_Query
::SEARCH_OPERATOR_AND
);
673 $this->set('queryOperator', $operator);
674 if ($operator == CRM_Contact_BAO_Query
::SEARCH_OPERATOR_OR
) {
675 $this->assign('operator', ts('OR'));
678 $this->assign('operator', ts('AND'));
681 // show the context menu only when we’re not searching for deleted contacts; CRM-5673
682 if (empty($this->_formValues
['deleted_contacts'])) {
683 $menuItems = CRM_Contact_BAO_Contact
::contextMenu();
684 $primaryActions = CRM_Utils_Array
::value('primaryActions', $menuItems, []);
685 $this->_contextMenu
= CRM_Utils_Array
::value('moreActions', $menuItems, []);
686 $this->assign('contextMenu', $primaryActions +
$this->_contextMenu
);
689 if (!isset($this->_componentMode
)) {
690 $this->_componentMode
= CRM_Contact_BAO_Query
::MODE_CONTACTS
;
692 self
::$_selectorName = $this->_modeValue
['selectorName'];
693 self
::setModeValues();
696 if (strpos(self
::$_selectorName, 'CRM_Contact_Selector') !== FALSE) {
697 $selector = new self
::$_selectorName(
698 $this->_customSearchClass
,
701 $this->_returnProperties
,
710 $selector = new self
::$_selectorName(
718 $selector->setKey($this->controller
->_key
);
720 $controller = new CRM_Contact_Selector_Controller($selector,
721 $this->get(CRM_Utils_Pager
::PAGE_ID
),
722 $this->get(CRM_Utils_Sort
::SORT_ID
),
723 CRM_Core_Action
::VIEW
,
725 CRM_Core_Selector_Controller
::TRANSFER
727 $controller->setEmbedded(TRUE);
728 $controller->setDynamicAction($setDynamic);
732 $this->postProcess();
735 * Note that we repeat this, since the search creates and stores
736 * values that potentially change the controller behavior. i.e. things
737 * like totalCount etc
740 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
741 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
742 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
745 $controller = new CRM_Contact_Selector_Controller($selector,
746 $this->get(CRM_Utils_Pager
::PAGE_ID
),
748 CRM_Core_Action
::VIEW
, $this, CRM_Core_Selector_Controller
::TRANSFER
750 $controller->setEmbedded(TRUE);
751 $controller->setDynamicAction($setDynamic);
754 $controller->moveFromSessionToTemplate();
760 public function &getFormValues() {
761 return $this->_formValues
;
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 if (array_key_exists($this->_searchButtonName
, $_POST) ||
782 ($this->_force
&& !$crmPID)
784 //reset the cache table for new search
785 $cacheKey = "civicrm search {$this->controller->_key}";
786 Civi
::service('prevnext')->deleteItem(NULL, $cacheKey);
789 //get the button name
790 $buttonName = $this->controller
->getButtonName();
792 if (isset($this->_ufGroupID
) && empty($this->_formValues
['uf_group_id'])) {
793 $this->_formValues
['uf_group_id'] = $this->_ufGroupID
;
796 if (isset($this->_componentMode
) && empty($this->_formValues
['component_mode'])) {
797 $this->_formValues
['component_mode'] = $this->_componentMode
;
800 if (isset($this->_operator
) && empty($this->_formValues
['operator'])) {
801 $this->_formValues
['operator'] = $this->_operator
;
804 if (empty($this->_formValues
['qfKey'])) {
805 $this->_formValues
['qfKey'] = $this->controller
->_key
;
808 if (!CRM_Core_Permission
::check('access deleted contacts')) {
809 unset($this->_formValues
['deleted_contacts']);
812 $this->set('type', $this->_action
);
813 $this->set('formValues', $this->_formValues
);
814 $this->set('queryParams', $this->_params
);
815 $this->set('returnProperties', $this->_returnProperties
);
817 if ($buttonName == $this->_actionButtonName
) {
818 // check actionName and if next, then do not repeat a search, since we are going to the next page
819 // hack, make sure we reset the task values
820 $stateMachine = $this->controller
->getStateMachine();
821 $formName = $stateMachine->getTaskFormName();
822 $this->controller
->resetPage($formName);
826 $output = CRM_Core_Selector_Controller
::SESSION
;
828 // create the selector, controller and run - store results in session
829 $searchChildGroups = TRUE;
830 if ($this->get('isAdvanced')) {
831 $searchChildGroups = FALSE;
836 if (strpos(self
::$_selectorName, 'CRM_Contact_Selector') !== FALSE) {
837 $selector = new self
::$_selectorName(
838 $this->_customSearchClass
,
841 $this->_returnProperties
,
851 $selector = new self
::$_selectorName(
862 $selector->setKey($this->controller
->_key
);
864 // added the sorting character to the form array
865 $config = CRM_Core_Config
::singleton();
866 // do this only for contact search
867 if ($setDynamic && $config->includeAlphabeticalPager
) {
868 // Don't recompute if we are just paging/sorting
869 if ($this->_reset ||
(empty($_GET['crmPID']) && empty($_GET['crmSID']) && !$this->_sortByCharacter
)) {
870 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($selector, $this->_sortByCharacter
);
871 $this->set('AToZBar', $aToZBar);
876 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
877 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
878 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
881 $controller = new CRM_Contact_Selector_Controller($selector,
882 $this->get(CRM_Utils_Pager
::PAGE_ID
),
884 CRM_Core_Action
::VIEW
,
888 $controller->setEmbedded(TRUE);
889 $controller->setDynamicAction($setDynamic);
897 public function &returnProperties() {
898 return CRM_Core_DAO
::$_nullObject;
902 * Return a descriptive name for the page, used in wizard header
906 public function getTitle() {