if (!empty($_POST)) {
$this->_formValues = $this->controller->exportValues($this->_name);
- foreach (array('activity_type_id', 'status_id', 'activity_subject') as $element) {
- $value = CRM_Utils_Array::value($element, $this->_formValues);
- if ($value) {
- if (is_array($value)) {
- if ($element == 'status_id') {
- unset($this->_formValues[$element]);
- $this->_formValues['activity_' . $element] = $value;
- }
- }
- else {
- $this->_formValues[$element] = array('LIKE' => "%$value%");
- }
- }
- }
+ $specialParams = array(
+ 'activity_type_id',
+ 'status_id',
+ 'activity_subject'
+ );
+ $changeNames = array('status_id' => 'activity_status_id');
+ CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, $specialParams, $changeNames);
}
$this->fixFormValues();
elseif ($name === 'name') {
$value = $strtolower(CRM_Core_DAO::escapeString($value));
if ($wildcard) {
- $value = "%$value%";
$op = 'LIKE';
+ $value = self::getWildCardedValue($wildcard, $op, $value);
}
$wc = self::caseImportant($op) ? "LOWER({$field['where']})" : "{$field['where']}";
$this->_where[$grouping][] = self::buildClause($wc, $op, "'$value'");
elseif ($name === 'current_employer') {
$value = $strtolower(CRM_Core_DAO::escapeString($value));
if ($wildcard) {
- $value = "%$value%";
$op = 'LIKE';
+ $value = self::getWildCardedValue($wildcard, $op, $value);
}
$wc = self::caseImportant($op) ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name";
$ceWhereClause = self::buildClause($wc, $op,
$this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )";
$value = $strtolower(CRM_Core_DAO::escapeString($value));
if ($wildcard) {
- $value = "%$value%";
$op = 'LIKE';
+ $value = self::getWildCardedValue($wildcard, $op, $value);
}
$wc = 'civicrm_website.url';
$value = $strtolower($value);
}
if ($wildcard) {
- $value = "%$value%";
$op = 'LIKE';
+ $value = self::getWildCardedValue($wildcard, $op, $value);
}
$this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type);
$value = $strtolower(CRM_Core_DAO::escapeString(trim($value)));
if (strlen($value)) {
$fieldsub = array();
- $value = "'" . $this->getWildCardedValue($wildcard, $op, $value) . "'";
+ $value = "'" . self::getWildCardedValue($wildcard, $op, $value) . "'";
if ($fieldName == 'sort_name') {
$wc = self::caseImportant($op) ? "LOWER(contact_a.sort_name)" : "contact_a.sort_name";
}
$op = '=';
}
else {
- $value = $this->getWildCardedValue($wildcard, $op, $n);
+ $value = self::getWildCardedValue($wildcard, $op, $n);
}
$this->_qill[$grouping][] = ts('Email') . " $op '$n'";
$this->_where[$grouping][] = self::buildClause('civicrm_email.email', $op, $value, 'String');
*
* @return string
*/
- public function getWildCardedValue($wildcard, $op, $value) {
+ public static function getWildCardedValue($wildcard, $op, $value) {
+ if (!$value) {
+ return;
+ }
if ($wildcard && $op == 'LIKE') {
if (CRM_Core_Config::singleton()->includeWildCardInName && (substr($value, 0, 1) != '%')) {
return "%$value%";
}
}
+ /**
+ * Process special fields of Search Form in OK (Operator in Key) format
+ *
+ * @param array $formValues
+ * @param array $specialFields
+ * Special params to be processed
+ * @param array $changeNames
+ * Array of fields whose name should be changed
+ */
+ public static function processSpecialFormValue(&$formValues, $specialFields, $changeNames = array()) {
+ foreach ($specialFields as $element) {
+ $value = CRM_Utils_Array::value($element, $formValues);
+ if ($value) {
+ if (is_array($value)) {
+ if (in_array($element, $changeNames)) {
+ unset($formValues[$element]);
+ $element = $changeNames[$element];
+ }
+ $formValues[$element] = array('IN' => $value);
+ }
+ else {
+ // if wildcard is already present return searchString as it is OR append and/or prepend with wildcard
+ $isWilcard = strstr($value, '%') ? FALSE : CRM_Core_Config::singleton()->includeWildCardInName;
+ $formValues[$element] = array(
+ 'LIKE' => self::getWildCardedValue($isWilcard, 'LIKE', $value)
+ );
+ }
+ }
+ }
+ }
+
}
'contact_tags',
'preferred_communication_method',
);
- foreach ($specialParams as $element) {
- $value = CRM_Utils_Array::value($element, $this->_formValues);
- if ($value) {
- if (is_array($value)) {
- if ($element == 'status_id') {
- unset($this->_formValues[$element]);
- $element = 'activity_' . $element;
- }
- $this->_formValues[$element] = array('IN' => $value);
- }
- elseif (strstr($value, '%')) {
- $this->_formValues[$element] = array('LIKE' => $value);
- }
- }
- }
+ $changeNames = array('status_id' => 'activity_status_id');
+ CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, $specialParams, $changeNames);
$taglist = CRM_Utils_Array::value('contact_taglist', $this->_formValues);