mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-24 04:44:35 +02:00
Show the number of parts with this element and all its child elements in Admin pages
This commit is contained in:
parent
a9642b27a6
commit
32638777d9
4 changed files with 54 additions and 14 deletions
|
@ -93,7 +93,7 @@ abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
|
|||
* @NoneOfItsChildren()
|
||||
* @Groups({"include_parents"})
|
||||
*/
|
||||
protected $parent;
|
||||
protected $parent = null;
|
||||
|
||||
/** @var string[] all names of all parent elements as a array of strings,
|
||||
* the last array element is the name of the element itself
|
||||
|
@ -271,16 +271,17 @@ abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
|
|||
*/
|
||||
public function getSubelements(): iterable
|
||||
{
|
||||
return $this->children;
|
||||
return $this->children ?? new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see getSubelements()
|
||||
* @return Collection<static>|iterable
|
||||
* @psalm-return Collection<int, static>
|
||||
*/
|
||||
public function getChildren(): iterable
|
||||
{
|
||||
return $this->children;
|
||||
return $this->getSubelements();
|
||||
}
|
||||
|
||||
public function isNotSelectable(): bool
|
||||
|
|
|
@ -45,6 +45,23 @@ abstract class AbstractPartsContainingRepository extends StructuralDBElementRepo
|
|||
*/
|
||||
abstract public function getPartsCount(object $element): int;
|
||||
|
||||
/**
|
||||
* Returns the count of the parts associated with this element and all its children.
|
||||
* Please be aware that this function is pretty slow on large trees!
|
||||
* @param AbstractPartsContainingDBElement $element
|
||||
* @return int
|
||||
*/
|
||||
public function getPartsCountRecursive(AbstractPartsContainingDBElement $element): int
|
||||
{
|
||||
$count = $this->getPartsCount($element);
|
||||
|
||||
foreach ($element->getChildren() as $child) {
|
||||
$count += $this->getPartsCountRecursive($child);
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
protected function getPartsByField(object $element, array $order_by, string $field_name): array
|
||||
{
|
||||
if (!$element instanceof AbstractPartsContainingDBElement) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue