Refactor variable check logic in department handling to support multiple positive value types

This commit is contained in:
Jepp9350
2025-05-30 10:11:36 +02:00
parent 9507705c05
commit fbf60da178
+12 -1
View File
@@ -848,8 +848,11 @@ trait form_t
// Check if the department has a variable (if the $onlyWithVariableTrue parameter is set)
if ($onlyWithVariableTrue) {
$department_variables = (new department_variables_o())->selectDepartment((int)$department['id']);
// Check if the department has the variables set to true
foreach ( $onlyWithVariableTrue as $variable ) {
//echo 'Checking variable: ' . $variable . ' for department: ' . $department['name'] . PHP_EOL;
if (!self::hasPositiveVariable($variable, $department_variables)) {
//echo 'Variable: ' . $variable . ' is not set to true for department: ' . $department['name'] . PHP_EOL;
continue 2;
}
}
@@ -861,6 +864,14 @@ trait form_t
public function hasPositiveVariable($variable, $department_variables_object): bool
{
return $department_variables_object->getVariable($variable) === 'true';
$positive_values = [
true,
'true',
1,
'1',
];
return in_array(
$department_variables_object->getVariable($variable),
$positive_values);
}
}