// Get fields of type date
// FIXME: This is a hack until our fields contain this meta-data
$dateFields = array();
+ $stringFields = array();
$searchByLabelFields = array();
foreach ($fields as $name => $field) {
if (strpos($name, '_date') || CRM_Utils_Array::value('data_type', $field) == 'Date') {
$dateFields[] = $name;
}
+ // it's necessary to know which of the fields are from string data type
+ if (isset($field['type']) && $field['type'] === CRM_Utils_Type::T_STRING) {
+ $stringFields[] = $name;
+ }
// it's necessary to know which of the fields are searchable by label
if (isset($field['searchByLabel']) && $field['searchByLabel']) {
$searchByLabelFields[] = $name;
'newBlock' => $this->get('newBlock'),
'dateFields' => $dateFields,
'fieldOptions' => self::fieldOptions(),
+ 'stringFields' => $stringFields,
'searchByLabelFields' => $searchByLabelFields,
+ 'generalOperators' => array('' => ts('-operator-')) + CRM_Core_SelectValues::getSearchBuilderOperators(),
+ 'stringOperators' => array('' => ts('-operator-')) + CRM_Core_SelectValues::getSearchBuilderOperators(CRM_Utils_Type::T_STRING),
),
));
//get the saved search mapping id
*
* @return array
*/
- public static function getSearchBuilderOperators() {
- return array(
+ public static function getSearchBuilderOperators($fieldType = null) {
+ $builderOperators = array(
'=' => '=',
'!=' => '≠',
'>' => '>',
'IS NULL' => ts('Is Null'),
'IS NOT NULL' => ts('Not Null'),
);
+ if ($fieldType) {
+ switch ($fieldType) {
+ case CRM_Utils_Type::T_STRING:
+ unset($builderOperators['>']);
+ unset($builderOperators['<']);
+ unset($builderOperators['>=']);
+ unset($builderOperators['<=']);
+ break;
+ }
+ }
+ return $builderOperators;
}
/**
function handleUserInputField() {
var row = $(this).closest('tr');
var field = $('select[id^=mapper][id$="_1"]', row).val();
- var op = $('select[id^=operator]', row).val();
+ var operator = $('select[id^=operator]', row);
+ var op = operator.val();
+
+ var patt = /_1$/; // pattern to check if the change event came from field name
+ if (field !== null && patt.test(this.id)) {
+ if ($.inArray(field, CRM.searchBuilder.stringFields) >= 0) {
+ // string operators
+ buildOperator(operator, CRM.searchBuilder.stringOperators);
+ } else {
+ // general operators
+ buildOperator(operator, CRM.searchBuilder.generalOperators);
+ }
+ }
// These Ops don't get any input field.
var noFieldOps = ['', 'IS EMPTY', 'IS NOT EMPTY', 'IS NULL', 'IS NOT NULL'];
}
}
+ /**
+ * Add appropriate operator to selected field
+ * @param operator: jQuery object
+ * @param options: array
+ */
+ function buildOperator(operator, options) {
+ var selected = operator.val();
+ operator.html('');
+ $.each(options, function(value, label) {
+ operator.append('<option value="' + value + '">' + label + '</option>');
+ });
+ operator.val(selected);
+ }
+
/**
* Add select list if appropriate for this operation
* @param row: jQuery object