From: eileen Date: Fri, 7 Jun 2019 05:16:59 +0000 (+1200) Subject: Support url defaults on event search X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6fbf3a31a162dd5bdaff0db876360bc4e0f09a49;p=civicrm-core.git Support url defaults on event search This adds url support for sort_name & participant_status_id & participant_register_date to event search civicrm/event/search?reset=1&sort_name=p&participant_status_id=1&participant_register_date_low=20180101 --- diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 481051512f..2957645991 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -132,7 +132,11 @@ class CRM_Core_Form_Search extends CRM_Core_Form { * @throws \Exception */ public function setDefaultValues() { - return array_merge($this->getEntityDefaults($this->getDefaultEntity()), (array) $this->_formValues); + $defaults = (array) $this->_formValues; + foreach (['Contact', $this->getDefaultEntity()] as $entity) { + $defaults = array_merge($this->getEntityDefaults($entity), $defaults); + } + return $defaults; } /** @@ -251,16 +255,16 @@ class CRM_Core_Form_Search extends CRM_Core_Form { */ protected function getEntityDefaults($entity) { $defaults = []; - foreach ($this->getSearchFieldMetadata()[$entity] as $fieldName => $fieldSpec) { - if (empty($_POST[$fieldSpec['name']])) { - $value = CRM_Utils_Request::retrieveValue($fieldName, $this->getValidationTypeForField($entity, $fieldName), FALSE, NULL, 'GET'); + foreach (CRM_Utils_Array::value($entity, $this->getSearchFieldMetadata(), []) as $fieldName => $fieldSpec) { + if (empty($_POST[$fieldName])) { + $value = CRM_Utils_Request::retrieveValue($fieldName, $this->getValidationTypeForField($entity, $fieldName), NULL, NULL, 'GET'); if ($value !== NULL) { $defaults[$fieldName] = $value; } if ($fieldSpec['type'] === CRM_Utils_Type::T_DATE || ($fieldSpec['type'] === CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)) { - $low = CRM_Utils_Request::retrieveValue($fieldName . '_low', 'Timestamp', FALSE, NULL, 'GET'); - $high = CRM_Utils_Request::retrieveValue($fieldName . '_high', 'Timestamp', FALSE, NULL, 'GET'); - if ($low !== FALSE || $high !== FALSE) { + $low = CRM_Utils_Request::retrieveValue($fieldName . '_low', 'Timestamp', NULL, NULL, 'GET'); + $high = CRM_Utils_Request::retrieveValue($fieldName . '_high', 'Timestamp', NULL, NULL, 'GET'); + if ($low !== NULL || $high !== NULL) { $defaults[$fieldName . '_relative'] = 0; $defaults[$fieldName . '_low'] = $low ? date('Y-m-d H:i:s', strtotime($low)) : NULL; $defaults[$fieldName . '_high'] = $high ? date('Y-m-d H:i:s', strtotime($high)) : NULL; @@ -327,12 +331,14 @@ class CRM_Core_Form_Search extends CRM_Core_Form { * to define the string. */ protected function addSortNameField() { + $title = civicrm_api3('setting', 'getvalue', ['name' => 'includeEmailInName', 'group' => 'Search Preferences']) ? $this->getSortNameLabelWithEmail() : $this->getSortNameLabelWithOutEmail(); $this->addElement( 'text', 'sort_name', - civicrm_api3('setting', 'getvalue', ['name' => 'includeEmailInName', 'group' => 'Search Preferences']) ? $this->getSortNameLabelWithEmail() : $this->getSortNameLabelWithOutEmail(), + $title, CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name') ); + $this->searchFieldMetadata['Contact']['sort_name'] = ['name' => 'sort_name', 'title' => $title, 'type' => CRM_Utils_Type::T_STRING]; } /** diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index 412590c22a..e53572d90d 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -419,19 +419,6 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { public function addRules() { } - /** - * Set the default form values. - * - * - * @return array - * the default array reference - */ - public function setDefaultValues() { - $defaults = []; - $defaults = $this->_formValues; - return $defaults; - } - public function fixFormValues() { // if this search has been forced // then see if there are any get values, and if so over-ride the post values