add time entry filter normalizeation

This commit is contained in:
Gregor Vostrak
2026-10-02 14:20:47 +02:00
parent 349623d537
commit ded56c0798
5 changed files with 165 additions and 11 deletions

View File

@@ -111,7 +111,8 @@ class TimeEntryFilter
*/
public function addMemberIdsFilter(?array $memberIds): self
{
if ($memberIds === null) {
// An empty selection is no constraint, the same as null
if ($memberIds === null || count($memberIds) === 0) {
return $this;
}
$this->builder->whereIn('member_id', $memberIds);
@@ -181,6 +182,10 @@ class TimeEntryFilter
}
$includeNone = in_array(self::NONE_VALUE, $clientIds, true);
$clientIds = array_values(array_filter($clientIds, fn (string $id): bool => $id !== self::NONE_VALUE));
// An empty selection (no client IDs and not filtering for "none") is no constraint, so apply nothing
if (count($clientIds) === 0 && ! $includeNone) {
return $this;
}
$this->builder->where(function (Builder $builder) use ($clientIds, $includeNone): void {
if (count($clientIds) > 0) {
@@ -204,6 +209,10 @@ class TimeEntryFilter
}
$includeNone = in_array(self::NONE_VALUE, $projectIds, true);
$projectIds = array_values(array_filter($projectIds, fn (string $id): bool => $id !== self::NONE_VALUE));
// An empty selection (no project IDs and not filtering for "none") is no constraint, so apply nothing
if (count($projectIds) === 0 && ! $includeNone) {
return $this;
}
$this->builder->where(function (Builder $builder) use ($projectIds, $includeNone): void {
if (count($projectIds) > 0) {
@@ -269,6 +278,10 @@ class TimeEntryFilter
}
$includeNone = in_array(self::NONE_VALUE, $taskIds, true);
$taskIds = array_values(array_filter($taskIds, fn (string $id): bool => $id !== self::NONE_VALUE));
// An empty selection (no task IDs and not filtering for "none") is no constraint, so apply nothing
if (count($taskIds) === 0 && ! $includeNone) {
return $this;
}
$this->builder->where(function (Builder $builder) use ($taskIds, $includeNone): void {
if (count($taskIds) > 0) {