diff --git a/src/Entity/Base/AbstractStructuralDBElement.php b/src/Entity/Base/AbstractStructuralDBElement.php index 504d730c..f5c99b1b 100644 --- a/src/Entity/Base/AbstractStructuralDBElement.php +++ b/src/Entity/Base/AbstractStructuralDBElement.php @@ -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|iterable * @psalm-return Collection */ public function getChildren(): iterable { - return $this->children; + return $this->getSubelements(); } public function isNotSelectable(): bool diff --git a/src/Repository/AbstractPartsContainingRepository.php b/src/Repository/AbstractPartsContainingRepository.php index 88b9d021..ac59aa8b 100644 --- a/src/Repository/AbstractPartsContainingRepository.php +++ b/src/Repository/AbstractPartsContainingRepository.php @@ -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) { diff --git a/templates/AdminPages/_info.html.twig b/templates/AdminPages/_info.html.twig index 87a6e7c2..e4600b55 100644 --- a/templates/AdminPages/_info.html.twig +++ b/templates/AdminPages/_info.html.twig @@ -1,15 +1,15 @@ {% import "helper.twig" as helper %}
- -
+ +

{% if entity.iD %}{{ entity.id }}{% else %}-{% endif %}

- -
+ +

{% if entity.id is not null and date(entity.addedDate) > date('1900/01/01') %} @@ -22,8 +22,8 @@

- -
+ +

{% if entity.id is not null and date(entity.lastModified) > date('1900/01/01') %} {{ helper.date_user_combination(entity, true, "long") }} @@ -35,9 +35,9 @@

- -
-

+ +

+

{% if entity.id and partsContainingElement %} {{ repo.partsCount(entity) }} {% else %} @@ -45,4 +45,20 @@ {% endif %}

-
\ No newline at end of file +
+ +{# Check if we really have a structural element #} +{% if entity.parent is defined %} +
+ +
+

+ {% if entity.id and partsContainingElement %} + {{ repo.partsCountRecursive(entity) }} + {% else %} + - + {% endif %} +

+
+
+{% endif %} \ No newline at end of file diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index c1db526d..693e2e15 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -1092,7 +1092,7 @@ Sub elements will be moved upwards.]]> entity.info.parts_count - Count of parts with this element + Number of parts with this element @@ -9771,5 +9771,11 @@ Element 3 Target element ID + + + category.edit.partname_regex.placeholder + Number of parts with this element or its subelements + +