Skip to content

Commit

Permalink
Fix search of "<" values in number to avoid empty values and storage …
Browse files Browse the repository at this point in the history
…the correct operator
  • Loading branch information
alex-render committed Nov 28, 2022
1 parent 24763a4 commit fe424e2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
59 changes: 47 additions & 12 deletions lib/dedalo/component_number/class.component_number.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ public function set_dato($dato) {
public function get_valor() {

$valor = $this->get_dato();
$valor = component_number::number_to_string($valor);


if($this->modo!=='search'){
$valor = component_number::number_to_string($valor);
}

return (string)$valor;
}//end get_valor
Expand All @@ -60,6 +62,9 @@ public function get_valor() {
*/
public function set_format_form_type( $dato ) {

if($this->modo === 'search'){
return $dato;
}
$propiedades = $this->get_propiedades();

if($dato === null || empty($dato)){
Expand Down Expand Up @@ -295,11 +300,26 @@ public static function resolve_query_object_sql($query_object) {
break;
# SMALLER OR EQUAL THAN
case (substr($q, 0, 2)==='<='):
$operator = '<=';
$q_clean = str_replace($operator, '', $q);
$q_clean = str_replace(',', '.', $q_clean);
$query_object->operator = $operator;
$query_object->q_parsed = '\''.$q_clean.'\'';
$query_object_one = clone $query_object;
$operator = '<=';
$q_clean = str_replace($operator, '', $q);
$q_clean = str_replace(',', '.', $q_clean);
$query_object_one->operator = $operator;
$query_object_one->q_parsed = '\''.$q_clean.'\'';

$query_object_two = clone $query_object;
$operator = 'IS NOT NULL';
$q_clean_two = '';
$query_object_two->operator = $operator;
$query_object_two->q_parsed = $q_clean_two;
$query_object_two->type = 'string';

// Group in a new "AND"
$current_op = '$and';
$new_query_object = new stdClass();
$new_query_object->{$current_op} = [$query_object_one,$query_object_two];

$query_object = $new_query_object;
break;
# BIGGER THAN
case (substr($q, 0, 1)==='>'):
Expand All @@ -311,11 +331,26 @@ public static function resolve_query_object_sql($query_object) {
break;
# SMALLER THAN
case (substr($q, 0, 1)==='<'):
$operator = '<';
$q_clean = str_replace($operator, '', $q);
$q_clean = str_replace(',', '.', $q_clean);
$query_object->operator = $operator;
$query_object->q_parsed = '\''.$q_clean.'\'';
$query_object_one = clone $query_object;
$operator = '<';
$q_clean = str_replace($operator, '', $q);
$q_clean = str_replace(',', '.', $q_clean);
$query_object_one->operator = $operator;
$query_object_one->q_parsed = '\''.$q_clean.'\'';

$query_object_two = clone $query_object;
$operator = 'IS NOT NULL';
$q_clean_two = '';
$query_object_two->operator = $operator;
$query_object_two->q_parsed = $q_clean_two;
$query_object_two->type = 'string';

// Group in a new "AND"
$current_op = '$and';
$new_query_object = new stdClass();
$new_query_object->{$current_op} = [$query_object_one,$query_object_two];

$query_object = $new_query_object;
break;
// EQUAL DEFAULT
default:
Expand Down
5 changes: 2 additions & 3 deletions lib/dedalo/component_number/component_number.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@
break;

case 'search':
# dato is injected by trigger search wen is needed
# dato is injected by trigger search when it's needed
$dato = $this->get_dato();
$valor = $this->get_valor();

$valor = $this->get_valor();
# Search input name (var search_input_name is injected in search -> records_search_list.phtml)
# and recovered in component_common->get_search_input_name()
# Normally is section_tipo + component_tipo, but when in portal can be portal_tipo + section_tipo + component_tipo
Expand Down
7 changes: 6 additions & 1 deletion lib/dedalo/component_number/js/component_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ var component_number = new function() {
for (let i = 0; i < inputs_len; i++) {

//Add
dato = self.fix_number_format(inputs[i].value)
if(wrapper_obj.dataset.modo==='search'){
dato = inputs[i].value
}else{
dato = self.fix_number_format(inputs[i].value)
}


break; // Component is not multi yet..
}
Expand Down

0 comments on commit fe424e2

Please sign in to comment.