$this->_where[$grouping][] = self::buildClause("contact_a.is_deleted", $op, $value);
$this->_qill[$grouping][] = "$field[title] $op \"$value\"";
}
- else {
+ elseif (!empty($field['where'])) {
+ $type = NULL;
+ if (!empty($field['type'])) {
+ $type = CRM_Utils_Type::typeToString($field['type']);
+ }
+
+ list($tableName, $fieldName) = explode('.', $field['where'], 2);
+
+ if (isset($locType[1]) &&
+ is_numeric($locType[1])
+ ) {
+ $setTables = FALSE;
+
+ //get the location name
+ list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
+
+ $fieldName = "LOWER(`$tName`.$fldName)";
+
+ // we set both _tables & whereTables because whereTables doesn't seem to do what the name implies it should
+ $this->_tables[$tName] = $this->_whereTables[$tName] = 1;
+
+ }
+ else {
+ if ($tableName == 'civicrm_contact') {
+ $fieldName = "LOWER(contact_a.{$fieldName})";
+ }
+ else {
+ if ($op != 'IN' && !is_numeric($value)) {
+ $fieldName = "LOWER({$field['where']})";
+ }
+ else {
+ $fieldName = "{$field['where']}";
+ }
+ }
+ }
+
+ list($qillop, $qillVal) = self::buildQillForFieldValue(NULL, $field['title'], $value, $op);
+ $this->_qill[$grouping][] = "$field[title] $qillop '$qillVal'";
+
if (is_array($value)) {
// traditionally an array being passed has been a fatal error. We can take advantage of this to add support
// for api style operators for functions that hit this point without worrying about regression
$operations = array_keys($value);
foreach ($operations as $operator) {
if (!in_array($operator, CRM_Core_DAO::acceptedSQLOperators())) {
+ //Via Contact get api value is not in array(operator => array(values)) format ONLY for IN/NOT IN operators
+ //so this condition will satisfy the search for now
+ if (strstr('IN', $op)) {
+ $value = array($op => $value);
+ }
// we don't know when this might happen
- CRM_Core_Error::fatal();
+ else {
+ CRM_Core_Error::fatal(ts("%1 is not a valid operator", array(1 => $operator)));
+ }
}
}
- $this->_where[$grouping][] = CRM_Core_DAO::createSQLFilter($name, $value, NULL);
- //since this is not currently being called by the form layer we can skip worrying about the 'qill' for now
- return;
+ $this->_where[$grouping][] = CRM_Core_DAO::createSQLFilter($fieldName, $value, $type);
}
-
- if (!empty($field['where'])) {
+ else {
if ($op != 'IN') {
$value = $strtolower($value);
}
$op = 'LIKE';
}
- if (isset($locType[1]) &&
- is_numeric($locType[1])
- ) {
- $setTables = FALSE;
-
- //get the location name
- list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
-
- $where = "`$tName`.$fldName";
-
- $this->_where[$grouping][] = self::buildClause("LOWER($where)", $op, $value);
- // we set both _tables & whereTables because whereTables doesn't seem to do what the name implies it should
- $this->_tables[$tName] = $this->_whereTables[$tName] = 1;
- $this->_qill[$grouping][] = "$field[title] $op '$value'";
- }
- else {
- list($tableName, $fieldName) = explode('.', $field['where'], 2);
- if ($tableName == 'civicrm_contact') {
- $fieldName = "LOWER(contact_a.{$fieldName})";
- }
- else {
- if ($op != 'IN' && !is_numeric($value)) {
- $fieldName = "LOWER({$field['where']})";
- }
- else {
- $fieldName = "{$field['where']}";
- }
- }
-
- $type = NULL;
- if (!empty($field['type'])) {
- $type = CRM_Utils_Type::typeToString($field['type']);
- }
-
- $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type);
- $this->_qill[$grouping][] = "$field[title] $op $value";
- }
+ $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type);
}
}
) {
list($name, $op, $value, $grouping, $wildcard) = $values;
- if (!$value) {
- return;
- }
-
if ($name == "{$fieldName}_low" ||
$name == "{$fieldName}_high"
) {
- if (isset($this->_rangeCache[$fieldName])) {
+ if (isset($this->_rangeCache[$fieldName]) || !$value) {
return;
}
$this->_rangeCache[$fieldName] = 1;
$value = $value[$op];
}
+ $date = $format = NULL;
if (strstr($op, 'IN')) {
$format = array();
foreach ($value as &$date) {
$date = "('" . implode("','", $value) . "')";
$format = implode(', ', $format);
}
- else {
+ elseif ($value) {
$date = CRM_Utils_Date::processDate($value);
if (!$appendTimeStamp) {
$date = substr($date, 0, 8);
}
- $date = "'$date'";
$format = CRM_Utils_Date::customFormat($date);
+ $date = "'$date'";
}
if ($date) {
else {
$this->_where[$grouping][] = "{$tableName}.{$dbFieldName} $op";
}
+
$this->_tables[$tableName] = $this->_whereTables[$tableName] = 1;
$op = CRM_Utils_Array::value($op, CRM_Core_SelectValues::getSearchBuilderOperators(), $op);
- $this->_qill[$grouping][] = "$fieldTitle $op \"$format\"";
+ $this->_qill[$grouping][] = "$fieldTitle $op $format";
}
}
*
* @return array
*/
- public static function buildQillForFieldValue($daoName, $fieldName, $fieldValue, $op, $pseduoExtraParam = array()) {
+ public static function buildQillForFieldValue($daoName = NULL, $fieldName, $fieldValue, $op, $pseduoExtraParam = array()) {
$qillOperators = CRM_Core_SelectValues::getSearchBuilderOperators();
if ($fieldName == 'activity_type_id') {
elseif ($daoName == 'CRM_Event_DAO_Event' && $fieldName == 'id') {
$pseduoOptions = CRM_Event_BAO_Event::getEvents(0, $fieldValue, TRUE, TRUE, TRUE);
}
- else {
+ elseif ($daoName) {
$pseduoOptions = CRM_Core_PseudoConstant::get($daoName, $fieldName, $pseduoExtraParam = array());
}
- //For those $fieldName which don't have any associated pseudoconstant defined
- if (empty($pseduoOptions)) {
- if (is_array($fieldValue)) {
- $op = key($fieldValue);
- $fieldValue = $fieldValue[$op];
- if (is_array($fieldValue)) {
- $fieldValue = implode(', ', $fieldValue);
- }
- }
- }
- elseif (is_array($fieldValue)) {
+ if (is_array($fieldValue)) {
$qillString = array();
if (in_array(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
$op = key($fieldValue);
$fieldValue = $fieldValue[$op];
}
- foreach ((array) $fieldValue as $val) {
- $qillString[] = $pseduoOptions[$val];
+ if (!empty($pseduoOptions)) {
+ foreach ((array) $fieldValue as $val) {
+ $qillString[] = $pseduoOptions[$val];
+ }
+ $fieldValue = implode(', ', $qillString);
+ }
+ else {
+ $fieldValue = implode(', ', $fieldValue);
}
- $fieldValue = implode(', ', $qillString);
}
- else {
- if (array_key_exists($fieldValue, $pseduoOptions)) {
- $fieldValue = $pseduoOptions[$fieldValue];
- }
+ elseif (!empty($pseduoOptions) && array_key_exists($fieldValue, $pseduoOptions)) {
+ $fieldValue = $pseduoOptions[$fieldValue];
}
return array(CRM_Utils_Array::value($op, $qillOperators, $op), $fieldValue);