foreach ($formValues as $id => $values) {
- self::legacyConvertFormValues($id, $values);
-
if (self::isAlreadyProcessedForQueryFormat($values)) {
$params[] = $values;
continue;
}
+
+ self::legacyConvertFormValues($id, $values);
+
// The form uses 1 field to represent two db fields
if ($id == 'contact_type' && $values && (!is_array($values) || !array_intersect(array_keys($values), CRM_Core_DAO::acceptedSQLOperators()))) {
$contactType = array();
*
*/
public static function legacyConvertFormValues($id, &$values) {
- if (in_array($id, array('group', 'tag')) && is_array($values)) {
+ $legacyElements = array(
+ 'group',
+ 'tag',
+ 'contact_tags',
+ 'contact_type',
+ 'membership_type_id',
+ 'membership_status_id',
+ );
+ if (in_array($id, $legacyElements) && is_array($values)) {
// prior to 4.7, formValues for some attributes (e.g. group, tag) are stored in array(id1 => 1, id2 => 1),
// as per the recent Search fixes $values need to be in standard array(id1, id2) format
$ids = array_keys($values, 1);
if (count($ids) > 1 ||
- (count($ids) == 1 && (key($values) > 1 || (key($values) == 1 && $values[1] == 1))) // handle (0 => 4), (1 => 1)
+ (count($ids) == 1 &&
+ (key($values) > 1 ||
+ is_string(key($values)) ||
+ (key($values) == 1 && $values[1] == 1) // handle (0 => 4), (1 => 1)
+ )
+ )
) {
$values = $ids;
}
*
* @return bool;
*/
- protected static function isAlreadyProcessedForQueryFormat($values) {
+ public static function isAlreadyProcessedForQueryFormat($values) {
if (!is_array($values)) {
return FALSE;
}
$result = unserialize($fv);
}
- // check to see if we need to convert the old privacy array
- // CRM-9180
- if (isset($result['privacy'])) {
- if (is_array($result['privacy'])) {
- $result['privacy_operator'] = 'AND';
- $result['privacy_toggle'] = 1;
- if (isset($result['privacy']['do_not_toggle'])) {
- if ($result['privacy']['do_not_toggle']) {
- $result['privacy_toggle'] = 2;
+ $specialFields = array('contact_type', 'group', 'contact_tags', 'member_membership_type_id', 'member_status_id');
+ foreach ($result as $element => $value) {
+ if (CRM_Contact_BAO_Query::isAlreadyProcessedForQueryFormat($value)) {
+ $id = CRM_Utils_Array::value(0, $value);
+ $value = CRM_Utils_Array::value(2, $value);
+ if (is_array($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
+ $value = CRM_Utils_Array::value(key($value), $value);
+ }
+ $result[$id] = $value;
+ unset($result[$element]);
+ continue;
+ }
+ if (!empty($value) && is_array($value)) {
+ if (in_array($element, $specialFields)) {
+ $element = str_replace('member_membership_type_id', 'membership_type_id', $element);
+ $element = str_replace('member_status_id', 'membership_status_id', $element);
+ CRM_Contact_BAO_Query::legacyConvertFormValues($element, $value);
+ $result[$element] = $value;
+ }
+ // As per the OK (Operator as Key) value format, value array may contain key
+ // as an operator so to ensure the default is always set actual value
+ elseif (in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
+ $result[$element] = CRM_Utils_Array::value(key($value), $value);
+ if (is_string($result[$element])) {
+ $result[$element] = str_replace("%", '', $result[$element]);
}
- unset($result['privacy']['do_not_toggle']);
}
+ }
+ if (substr($element, 0, 7) == 'custom_' &&
+ (substr($element, -5, 5) == '_from' || substr($element, -3, 3) == '_to')
+ ) {
+ // Ensure the _relative field is set if from or to are set to ensure custom date
+ // fields with 'from' or 'to' values are displayed when the are set in the smart group
+ // being loaded. (CRM-17116)
+ if (!isset($result[CRM_Contact_BAO_Query::getCustomFieldName($element) . '_relative'])) {
+ $result[CRM_Contact_BAO_Query::getCustomFieldName($element) . '_relative'] = 0;
+ }
+ }
+ // check to see if we need to convert the old privacy array
+ // CRM-9180
+ if (!empty($result['privacy'])) {
+ if (is_array($result['privacy'])) {
+ $result['privacy_operator'] = 'AND';
+ $result['privacy_toggle'] = 1;
+ if (isset($result['privacy']['do_not_toggle'])) {
+ if ($result['privacy']['do_not_toggle']) {
+ $result['privacy_toggle'] = 2;
+ }
+ unset($result['privacy']['do_not_toggle']);
+ }
- $result['privacy_options'] = array();
- foreach ($result['privacy'] as $name => $value) {
- if ($value) {
- $result['privacy_options'][] = $name;
+ $result['privacy_options'] = array();
+ foreach ($result['privacy'] as $name => $value) {
+ if ($value) {
+ $result['privacy_options'][] = $name;
+ }
}
}
+ unset($result['privacy']);
}
- unset($result['privacy']);
}
return $result;
}
if ($this->_ssID && empty($_POST)) {
- $specialFields = array('contact_type', 'group', 'contact_tags', 'member_membership_type_id', 'member_status_id');
-
- foreach ($defaults as $element => $value) {
- if (!empty($value) && is_array($value)) {
- if (in_array($element, $specialFields)) {
- $element = str_replace('member_membership_type_id', 'membership_type_id', $element);
- $element = str_replace('member_status_id', 'membership_status_id', $element);
- $defaults[$element] = array_keys($value);
- }
- // As per the OK (Operator as Key) value format, value array may contain key
- // as an operator so to ensure the default is always set actual value
- elseif (in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
- $defaults[$element] = CRM_Utils_Array::value(key($value), $value);
- if (is_string($defaults[$element])) {
- $defaults[$element] = str_replace("%", '', $defaults[$element]);
- }
- }
- }
- if (substr($element, 0, 7) == 'custom_' &&
- (substr($element, -5, 5) == '_from' || substr($element, -3, 3) == '_to')
- ) {
- // Ensure the _relative field is set if from or to are set to ensure custom date
- // fields with 'from' or 'to' values are displayed when the are set in the smart group
- // being loaded. (CRM-17116)
- if (!isset($defaults[CRM_Contact_BAO_Query::getCustomFieldName($element) . '_relative'])) {
- $defaults[CRM_Contact_BAO_Query::getCustomFieldName($element) . '_relative'] = 0;
- }
- }
- }
+ $defaults = array_merge($defaults, CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID));
}
return $defaults;
}
$form->assign('elements', array('includeGroups', 'excludeGroups', 'andOr', 'includeTags', 'excludeTags'));
}
- /**
- * Set search form field defaults here.
- * @return array
- */
- public function setDefaultValues() {
- $defaults = array('andOr' => '1');
-
- if (!empty($this->_formValues)) {
- $defaults['andOr'] = CRM_Utils_Array::value('andOr', $this->_formValues, '1');
-
- $defaults['includeGroups'] = CRM_Utils_Array::value('includeGroups', $this->_formValues);
- $defaults['excludeGroups'] = CRM_Utils_Array::value('excludeGroups', $this->_formValues);
-
- $defaults['includeTags'] = CRM_Utils_Array::value('includeTags', $this->_formValues);
- $defaults['excludeTags'] = CRM_Utils_Array::value('excludeTags', $this->_formValues);
- }
-
- return $defaults;
- }
-
/**
* @param int $offset
* @param int $rowcount
return 'CRM/Contact/Form/Search/Custom/MultipleValues.tpl';
}
- /**
- * @return array
- */
- public function setDefaultValues() {
- return array();
- }
-
/**
* @param $row
*/
return 'CRM/Contact/Form/Search/Custom.tpl';
}
- /**
- * @return array
- */
- public function setDefaultValues() {
- return array();
- }
-
/**
* @param $row
*/
* @return array|null
*/
public function setDefaultValues() {
+ if (!empty($this->_formValues)) {
+ return $this->_formValues;
+ }
$config = CRM_Core_Config::singleton();
$countryDefault = $config->defaultContactCountry;
$stateprovinceDefault = $config->defaultContactStateProvince;
* @return array
*/
public function setDefaultValues() {
- return array(
- 'household_name' => '',
- );
+ return array_merge(array('household_name' => ''), $this->_formValues);
}
/**
return $this->whereClause($where, $params);
}
- /**
- * @return array
- */
- public function setDefaultValues() {
- return array();
- }
-
/**
* @return string
*/
$links = self::links($this->_context, $this->_contextMenu, $this->_key);
//check explicitly added contact to a Smart Group.
- $groupID = CRM_Utils_Array::key('1', $this->_formValues['group']);
+ $groupID = CRM_Utils_Array::value('group', $this->_formValues);
$pseudoconstants = array();
// for CRM-3157 purposes