Skip to content

Commit

Permalink
additional fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Feb 27, 2019
1 parent b88644b commit 436bfd4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 16 deletions.
7 changes: 6 additions & 1 deletion CRM/Contact/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
}
Expand Down
5 changes: 1 addition & 4 deletions CRM/Contact/Form/Search/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
27 changes: 19 additions & 8 deletions CRM/Contact/Form/Search/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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.'),
Expand All @@ -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',
Expand Down Expand Up @@ -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(
Expand All @@ -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 [
Expand All @@ -383,17 +390,21 @@ 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'],
];
}

/**
* 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,
Expand Down
34 changes: 31 additions & 3 deletions CRM/Core/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 436bfd4

Please sign in to comment.