From af50eb54628ae111604d1b491c41df3ec156fcdd Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Wed, 23 Feb 2022 17:57:10 +0100 Subject: [PATCH] small enhancements to Collection Signed-off-by: Michael Kaufmann --- lib/Froxlor/UI/Collection.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/Froxlor/UI/Collection.php b/lib/Froxlor/UI/Collection.php index 4a20eda2..cf9417ad 100644 --- a/lib/Froxlor/UI/Collection.php +++ b/lib/Froxlor/UI/Collection.php @@ -1,4 +1,5 @@ class = $class; $this->params = $params; @@ -57,16 +58,20 @@ class Collection return json_encode($this->get()); } - public function has($column, $class, $parentKey = 'id', $childKey = 'id', $params = []) + public function has($column, $class, $parentKey = 'id', $childKey = 'id', $params = []): Collection { - $attributes = $this->getListing($class, $params); + // check if the api result contains any items (not the overall listingCount as we might be in a search-resultset) + if (count($this->items) > 0) { + $attributes = $this->getListing($class, $params); - foreach ($this->items['data']['list'] as $key => $item) { - foreach ($attributes['data']['list'] as $list) { - if ($item[$parentKey] == $list[$childKey]) { - $this->items['data']['list'][$key][$column] = $list; + foreach ($this->items['data']['list'] as $key => $item) { + foreach ($attributes['data']['list'] as $list) { + if ($item[$parentKey] == $list[$childKey]) { + $this->items['data']['list'][$key][$column] = $list; + } } } } + return $this; } -} \ No newline at end of file +}