From 436bfd46a166b9c1657b64de755c72935f730d7f Mon Sep 17 00:00:00 2001 From: Monish Deb Date: Wed, 20 Feb 2019 16:47:42 +0530 Subject: [PATCH] additional fixes --- CRM/Contact/Form/Search.php | 7 +++++- CRM/Contact/Form/Search/Advanced.php | 5 +--- CRM/Contact/Form/Search/Criteria.php | 27 +++++++++++++++------- CRM/Core/Form/Search.php | 34 +++++++++++++++++++++++++--- 4 files changed, 57 insertions(+), 16 deletions(-) diff --git a/CRM/Contact/Form/Search.php b/CRM/Contact/Form/Search.php index 382892281fb4..e126b55e8421 100644 --- a/CRM/Contact/Form/Search.php +++ b/CRM/Contact/Form/Search.php @@ -101,7 +101,7 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search { * * @var array */ - protected $_params; + public $_params; /** * The return properties used for search. @@ -765,6 +765,11 @@ public static function setSearchParamFromUrl(&$form) { ); foreach ($searchFields as $name => $type) { if ($value = CRM_Utils_Request::retrieve($name, $type)) { + $value = $form->formatSpecialFormValue($name, $value, $type); + if (strstr($name, '_date_relative')) { + $fieldName = str_replace('_relative', '', $name); + list($form->_formValues[$fieldName . '_low'], $form->_formValues[$fieldName . '_high']) = CRM_Utils_Date::getFromTo($value, NULL, NULL); + } $form->_formValues[$name] = $value; } } diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index 6c40a36ed7a4..1f02b4bd7801 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -199,10 +199,7 @@ public function setDefaultValues() { $this->_ssID = $this->get('ssID'); } - $defaults = array_merge($this->_formValues, array( - 'privacy_toggle' => 1, - 'operator' => 'AND', - )); + $defaults = array_merge(['privacy_toggle' => 1, 'operator' => 'AND'], $this->_formValues); $this->normalizeDefaultValues($defaults); if ($this->_context === 'amtg') { diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index 37556bb1dec9..f9d9533c7fdc 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -265,7 +265,6 @@ protected static function setBasicSearchFields($form) { /** * Return list of basic contact fields that can be displayed for the basic search section. * - * @param array */ public static function getBasicSearchFields() { return [ @@ -297,6 +296,10 @@ public static function getBasicSearchFields() { 'help' => ['id' => 'id-all-tag-types'], 'data_type' => 'String', ], + 'deleted_contacts' => [ + 'name' => 'deleted_contacts', + 'data_type' => 'Positive', + ], 'phone_numeric' => [ 'name' => 'phone_numeric', 'description' => ts('Punctuation and spaces are ignored.'), @@ -310,6 +313,14 @@ public static function getBasicSearchFields() { 'template' => 'CRM/Contact/Form/Search/Criteria/Fields/privacy_toggle.tpl', 'data_type' => 'Integer', ], + 'privacy_options' => [ + 'name' => 'privacy_options', + 'data_type' => 'String', + ], + 'privacy_operator' => [ + 'name' => 'privacy_operator', + 'data_type' => 'String', + ], 'preferred_communication_method' => [ 'name' => 'preferred_communication_method', 'template' => 'CRM/Contact/Form/Search/Criteria/Fields/preferred_communication_method.tpl', @@ -342,8 +353,6 @@ public static function getBasicSearchFields() { /** * Return list of location fields that can be displayed for the Address search section. - * - * @param array */ public static function getLocationSearchFields() { return array( @@ -365,8 +374,6 @@ public static function getLocationSearchFields() { /** * Return list of demographic fields that can be displayed for the Demographics search section. - * - * @param array */ public static function getDemographicsSearchFields() { return [ @@ -383,6 +390,8 @@ public static function getChangeLogSearchFields() { return [ 'changed_by' => ['title' => ts('Modified By'), 'data_type' => 'String'], 'log_date' => ['title' => NULL, 'data_type' => 'Positive'], + 'log_date_low' => ['title' => NULL, 'data_type' => 'Date'], + 'log_date_high' => ['title' => NULL, 'data_type' => 'Date'], 'log_date_relative' => ['data_type' => 'String'], ]; } @@ -390,10 +399,12 @@ public static function getChangeLogSearchFields() { /** * Return list of custom fields that can be displayed for the Custom Fields search section. * - * @param array + * @param array $extends + * + * return array */ - public static function getCustomSearchFields() { - $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization', 'Address'), + public static function getCustomSearchFields($extends = NULL) { + $extends = $extends ?: array_merge(array('Contact', 'Individual', 'Household', 'Organization', 'Address'), CRM_Contact_BAO_ContactType::subTypes() ); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 562b23c7af64..68f5cf86e749 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -172,6 +172,30 @@ public function addFormFieldsFromMetadata() { } } + /** + * Format some special form values including date fields + * + * @param string $name + * @param string $value + * @param string $dataType + * + * @return string|array + */ + public function formatSpecialFormValue($name, $value, $dataType) { + if ($dataType == 'Date') { + // @todo we should pick up searchDate format here + $value = date('d/m/Y', strtotime($value)); + } + elseif (in_array($name, [ + 'privacy_options', + 'activity_tags', + ])) { + $value = explode(',', $value); + } + + return $value; + } + /** * Get the validation rule to apply to a function. * @@ -352,20 +376,24 @@ protected function loadSearchParamsFromUrl() { return; } - $enabledComponents = CRM_Core_Component::getEnabledComponents(); + $enabledComponents = array_merge(CRM_Core_Component::getEnabledComponents(), [ + 'CiviActivity' => ['namespace' => 'CRM_Activity'], + ]); if (!$this->_component) { if (method_exists('CRM_Contact_Form_Search', 'setSearchParamFromUrl')) { CRM_Contact_Form_Search::setSearchParamFromUrl($this); } foreach ($enabledComponents as $component) { - $searchClass = $component->namespace . '_Form_Search'; + $component = (array) $component; + $searchClass = $component['namespace'] . '_Form_Search'; if (method_exists($searchClass, 'setSearchParamFromUrl')) { $searchClass::setSearchParamFromUrl($this); } } } elseif (array_key_exists($this->_component, $enabledComponents)) { - $searchClass = $enabledComponents[$this->_component]->namespace . '_Form_Search'; + $component = (array) $enabledComponents[$this->_component]; + $searchClass = $component['namespace'] . '_Form_Search'; if (method_exists($searchClass, 'setSearchParamFromUrl')) { $searchClass::setSearchParamFromUrl($this); }