small enhancements to Collection

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-02-23 17:57:10 +01:00
parent 511c219d19
commit af50eb5462

View File

@@ -1,4 +1,5 @@
<?php <?php
namespace Froxlor\UI; namespace Froxlor\UI;
/** /**
@@ -23,7 +24,7 @@ class Collection
private array $params; private array $params;
private string $class; private string $class;
public function __construct($class, $userInfo, $params = []) public function __construct(string $class, array $userInfo, array $params = [])
{ {
$this->class = $class; $this->class = $class;
$this->params = $params; $this->params = $params;
@@ -57,8 +58,10 @@ class Collection
return json_encode($this->get()); 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
{ {
// 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); $attributes = $this->getListing($class, $params);
foreach ($this->items['data']['list'] as $key => $item) { foreach ($this->items['data']['list'] as $key => $item) {
@@ -69,4 +72,6 @@ class Collection
} }
} }
} }
return $this;
}
} }