|
|
|
@ -2488,10 +2488,7 @@ JAVASCRIPT; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$extraFieldsAll = $this->get_all( |
|
|
|
|
['visible_to_self = ? AND filter = ?' => [1, 1]], |
|
|
|
|
'option_order' |
|
|
|
|
); |
|
|
|
|
$extraFieldsAll = $this->get_all(['visible_to_self = ? AND filter = ?' => [1, 1]], 'option_order'); |
|
|
|
|
$extraFieldsType = array_column($extraFieldsAll, 'field_type', 'variable'); |
|
|
|
|
$extraFields = array_column($extraFieldsAll, 'variable'); |
|
|
|
|
$filter = new stdClass(); |
|
|
|
@ -2535,7 +2532,6 @@ JAVASCRIPT; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$result = $this->getExtraFieldRules($filter, 'extra_', $condition); |
|
|
|
|
|
|
|
|
|
$conditionArray = $result['condition_array']; |
|
|
|
|
|
|
|
|
|
$whereCondition = ''; |
|
|
|
@ -2565,8 +2561,8 @@ JAVASCRIPT; |
|
|
|
|
*/ |
|
|
|
|
public function getExtraFieldRules($filters, $stringToSearch = 'extra_', $condition = 'OR') |
|
|
|
|
{ |
|
|
|
|
$extra_fields = []; |
|
|
|
|
$condition_array = []; |
|
|
|
|
$extraFields = []; |
|
|
|
|
$conditionArray = []; |
|
|
|
|
|
|
|
|
|
// Getting double select if exists |
|
|
|
|
$double_select = []; |
|
|
|
@ -2594,7 +2590,7 @@ JAVASCRIPT; |
|
|
|
|
// normal fields |
|
|
|
|
$field = $rule->field; |
|
|
|
|
if (isset($rule->data) && is_string($rule->data) && -1 != $rule->data) { |
|
|
|
|
$condition_array[] = $this->get_where_clause($field, $rule->op, $rule->data); |
|
|
|
|
$conditionArray[] = $this->get_where_clause($field, $rule->op, $rule->data); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// Extra fields |
|
|
|
@ -2603,7 +2599,8 @@ JAVASCRIPT; |
|
|
|
|
$original_field = str_replace($stringToSearch, '', $rule->field); |
|
|
|
|
$field_option = $this->get_handler_field_info_by_field_variable($original_field); |
|
|
|
|
|
|
|
|
|
if (self::FIELD_TYPE_DOUBLE_SELECT == $field_option['field_type']) { |
|
|
|
|
switch ($field_option['field_type']) { |
|
|
|
|
case self::FIELD_TYPE_DOUBLE_SELECT: |
|
|
|
|
if (isset($double_select[$rule->field])) { |
|
|
|
|
$data = explode('#', $rule->data); |
|
|
|
|
$rule->data = $data[1].'::'.$double_select[$rule->field]; |
|
|
|
@ -2616,34 +2613,47 @@ JAVASCRIPT; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!isset($rule->data)) { |
|
|
|
|
$condition_array[] = ' (' |
|
|
|
|
$conditionArray[] = ' (' |
|
|
|
|
.$this->get_where_clause($rule->field, $rule->op, $rule->data) |
|
|
|
|
.') '; |
|
|
|
|
$extra_fields[] = ['field' => $rule->field, 'id' => $field_option['id']]; |
|
|
|
|
$extraFields[] = ['field' => $rule->field, 'id' => $field_option['id']]; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
break; |
|
|
|
|
case self::FIELD_TYPE_TAG: |
|
|
|
|
if (isset($rule->data)) { |
|
|
|
|
if (isset($rule->data) && is_int($rule->data) && -1 == $rule->data) { |
|
|
|
|
continue; |
|
|
|
|
if (is_int($rule->data) && -1 == $rule->data) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
/*var_dump($rule->data); |
|
|
|
|
foreach ($rule->data as $option) { |
|
|
|
|
}*/ |
|
|
|
|
$where = $this->get_where_clause($rule->field, $rule->op, $rule->data, 'OR'); |
|
|
|
|
$condition_array[] = " ( $where ) "; |
|
|
|
|
|
|
|
|
|
$extra_fields[] = [ |
|
|
|
|
//$where = $this->get_where_clause($rule->field, $rule->op, $rule->data, 'OR'); |
|
|
|
|
//$conditionArray[] = " ( $where ) "; |
|
|
|
|
$extraFields[] = [ |
|
|
|
|
'field' => $rule->field, |
|
|
|
|
'id' => $field_option['id'], |
|
|
|
|
'data' => $rule->data, |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
if (isset($rule->data)) { |
|
|
|
|
if (is_int($rule->data) && -1 == $rule->data) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
$where = $this->get_where_clause($rule->field, $rule->op, $rule->data, 'OR'); |
|
|
|
|
$conditionArray[] = " ( $where ) "; |
|
|
|
|
$extraFields[] = [ |
|
|
|
|
'field' => $rule->field, |
|
|
|
|
'id' => $field_option['id'], |
|
|
|
|
'data' => $rule->data, |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$my_field = str_replace('_second', '', $rule->field); |
|
|
|
|
$original_field = str_replace($stringToSearch, '', $my_field); |
|
|
|
|
$field_option = $this->get_handler_field_info_by_field_variable($original_field); |
|
|
|
|
$extra_fields[] = [ |
|
|
|
|
$extraFields[] = [ |
|
|
|
|
'field' => $rule->field, |
|
|
|
|
'id' => $field_option['id'], |
|
|
|
|
]; |
|
|
|
@ -2652,17 +2662,7 @@ JAVASCRIPT; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*var_dump( |
|
|
|
|
[ |
|
|
|
|
'extra_fields' => $extra_fields, |
|
|
|
|
'condition_array' => $condition_array, |
|
|
|
|
] |
|
|
|
|
);*/ |
|
|
|
|
|
|
|
|
|
return [ |
|
|
|
|
'extra_fields' => $extra_fields, |
|
|
|
|
'condition_array' => $condition_array, |
|
|
|
|
]; |
|
|
|
|
return ['extra_fields' => $extraFields, 'condition_array' => $conditionArray]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -2741,7 +2741,6 @@ JAVASCRIPT; |
|
|
|
|
$inject_extra_fields .= " fvo$counter.display_text as {$extra['field']}, "; |
|
|
|
|
break; |
|
|
|
|
case self::FIELD_TYPE_TAG: |
|
|
|
|
// If using OR |
|
|
|
|
//$inject_extra_fields .= " tag$counter.tag as {$extra['field']}, "; |
|
|
|
|
// If using AND |
|
|
|
|
$newCounter = 1; |
|
|
|
@ -2751,8 +2750,11 @@ JAVASCRIPT; |
|
|
|
|
$fields[] = "tag$counter$newCounter.tag"; |
|
|
|
|
$newCounter++; |
|
|
|
|
} |
|
|
|
|
$tags = implode(' , " ", ', $fields); |
|
|
|
|
$inject_extra_fields .= " CONCAT($tags) as $tagAlias, "; |
|
|
|
|
|
|
|
|
|
if (!empty($fields)) { |
|
|
|
|
$tags = implode(' , " ", ', $fields); |
|
|
|
|
$inject_extra_fields .= " CONCAT($tags) as $tagAlias, "; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
$inject_extra_fields .= " fv$counter.value as {$extra['field']}, "; |
|
|
|
@ -2785,9 +2787,12 @@ JAVASCRIPT; |
|
|
|
|
$inject_where = null; |
|
|
|
|
$where = null; |
|
|
|
|
|
|
|
|
|
if (!empty($options['where'])) { |
|
|
|
|
if (!empty($options['extra'])) { |
|
|
|
|
// Removing double 1=1 |
|
|
|
|
// Removing double 1=1 |
|
|
|
|
if (!empty($options['extra']) && !empty($extra_fields)) { |
|
|
|
|
// Removing double 1=1 |
|
|
|
|
if (empty($options['where'])) { |
|
|
|
|
$options['where'] = ' 1 = 1 '; |
|
|
|
|
} |
|
|
|
|
$options['where'] = str_replace(' 1 = 1 AND', '', $options['where']); |
|
|
|
|
// Always OR |
|
|
|
|
$counter = 1; |
|
|
|
@ -2813,29 +2818,28 @@ JAVASCRIPT; |
|
|
|
|
"; |
|
|
|
|
break; |
|
|
|
|
case self::FIELD_TYPE_TAG: |
|
|
|
|
/*$options['where'] = str_replace( |
|
|
|
|
$extra_info['field'], |
|
|
|
|
'tag'.$counter.'.tag ', |
|
|
|
|
$options['where'] |
|
|
|
|
);*/ |
|
|
|
|
$newCounter = 1; |
|
|
|
|
$whereTag = []; |
|
|
|
|
foreach ($extra['data'] as $data) { |
|
|
|
|
$data = Database::escape_string($data); |
|
|
|
|
$key = $counter.$newCounter; |
|
|
|
|
$whereTag[] = ' tag'.$key.'.tag LIKE "%'.$data.'%" '; |
|
|
|
|
$inject_joins .= " |
|
|
|
|
INNER JOIN $this->table_field_rel_tag tag_rel$key |
|
|
|
|
ON ( |
|
|
|
|
tag_rel$key.field_id = ".$extra_info['id']." AND |
|
|
|
|
tag_rel$key.item_id = $alias.".$this->primaryKey." |
|
|
|
|
) |
|
|
|
|
INNER JOIN $this->table_field_tag tag$key |
|
|
|
|
ON (tag$key.id = tag_rel$key.tag_id) |
|
|
|
|
"; |
|
|
|
|
$newCounter++; |
|
|
|
|
if (isset($extra_info['data']) && !empty($extra_info['data'])) { |
|
|
|
|
$whereTag = []; |
|
|
|
|
foreach ($extra_info['data'] as $data) { |
|
|
|
|
$data = Database::escape_string($data); |
|
|
|
|
$key = $counter.$newCounter; |
|
|
|
|
$whereTag[] = ' tag'.$key.'.tag LIKE "%'.$data.'%" '; |
|
|
|
|
$inject_joins .= " |
|
|
|
|
INNER JOIN $this->table_field_rel_tag tag_rel$key |
|
|
|
|
ON ( |
|
|
|
|
tag_rel$key.field_id = ".$extra_info['id']." AND |
|
|
|
|
tag_rel$key.item_id = $alias.".$this->primaryKey." |
|
|
|
|
) |
|
|
|
|
INNER JOIN $this->table_field_tag tag$key |
|
|
|
|
ON (tag$key.id = tag_rel$key.tag_id) |
|
|
|
|
"; |
|
|
|
|
$newCounter++; |
|
|
|
|
} |
|
|
|
|
if (!empty($whereTag)) { |
|
|
|
|
$options['where'] .= ' AND ('.implode(' AND ', $whereTag).') '; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$options['where'] = ' ('.implode(' AND ', $whereTag).') '; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
// text, textarea, etc |
|
|
|
@ -2850,14 +2854,17 @@ JAVASCRIPT; |
|
|
|
|
$counter++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($options['where'])) { |
|
|
|
|
$where .= ' AND '.$options['where']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$order = null; |
|
|
|
|
|
|
|
|
|
$order = ''; |
|
|
|
|
if (!empty($options['order'])) { |
|
|
|
|
$order = ' ORDER BY '.$options['order']; |
|
|
|
|
} |
|
|
|
|
$limit = null; |
|
|
|
|
$limit = ''; |
|
|
|
|
if (!empty($options['limit'])) { |
|
|
|
|
$limit = ' LIMIT '.$options['limit']; |
|
|
|
|
} |
|
|
|
|