Answer the question
In order to leave comments, you need to log in
How to edit such code? (or how to write the most idiotic code)?
foreach ($params as $param)
{
if ($param['label'] != 'name'){
if ($param['type_value'] == '1') {
if ($param['value'] != '')
$query->where(['like', $param['label'], $param['value']]);
}
else {
if(($param['firstcompare'] == '<' || $param['firstcompare'] == '<=' || $param['firstcompare'] == '=') && $param['firstvalue'] != '') {
if($param['secondcompare'] != '' && $param['secondvalue'] != ''){
$query->where([
'or',
$param['label'].$param['firstcompare'].$param['firstvalue'],
$param['label'].$param['secondcompare'].$param['secondvalue']
]);
// ->andWhere([$param['secondcompare'], $param['label'], $param['secondvalue']]);
}
else{
$query->where([$param['firstcompare'], $param['label'], $param['firstvalue']]);
}
}
elseif($param['firstcompare'] == '>' || $param['firstcompare'] == '>=' && $param['firstvalue'] != '')
{
if($param['secondcompare'] != '' && $param['secondvalue'] != ''){
$query->where([
'and',
$param['label'].$param['firstcompare'].$param['firstvalue'],
$param['label'].$param['secondcompare'].$param['secondvalue']
]);
}
else{
$query->where([$param['firstcompare'], $param['label'], $param['firstvalue']]);
}
}
elseif($param['firstcompare'] == '' || $param['firstvalue'] == '') {
if ($param['secondcompare'] != '' || $param['secondvalue'] != '')
$query->where([$param['secondcompare'], $param['label'], $param['secondvalue']]);
};
}
}
}
Answer the question
In order to leave comments, you need to log in
Javascript that will unlock the input of the second field only when the first one is filled, does this option not work?
For such cases, they have long been invented in various normal Forms frameworks
Move it to a separate class, write a test for it. Then you can comb as much as you like and see if the test has broken.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question