Show the number of parts with this element and all its child elements in Admin pages

This commit is contained in:
Jan Böhmer 2022-09-21 13:20:57 +02:00
parent a9642b27a6
commit 32638777d9
4 changed files with 54 additions and 14 deletions

View file

@ -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

View file

@ -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) {

View file

@ -1,15 +1,15 @@
{% import "helper.twig" as helper %}
<div class="form-group row">
<label class="col-form-label col-md-3">{% trans %}id.label{% endtrans %}</label>
<div class="col-md-9">
<label class="col-form-label col-md-4">{% trans %}id.label{% endtrans %}</label>
<div class="col-md-8">
<p class="form-control-plaintext">{% if entity.iD %}{{ entity.id }}{% else %}-{% endif %}</p>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-md-3">{% trans %}createdAt{% endtrans %}</label>
<div class="col-md-9">
<label class="col-form-label col-md-4">{% trans %}createdAt{% endtrans %}</label>
<div class="col-md-8">
<p class="form-control-plaintext">
{% if entity.id is not null and date(entity.addedDate) > date('1900/01/01') %}
@ -22,8 +22,8 @@
</div>
<div class="form-group row">
<label class="col-form-label col-md-3">{% trans %}lastModified{% endtrans %}</label>
<div class="col-md-9">
<label class="col-form-label col-md-4">{% trans %}lastModified{% endtrans %}</label>
<div class="col-md-8">
<p class="form-control-plaintext">
{% 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 @@
</div>
<div class="form-group row">
<label class="col-form-label col-md-3">{% trans %}entity.info.parts_count{% endtrans %}</label>
<div class="col-md-9">
<p class="form-control-static">
<label class="col-form-label col-md-4">{% trans %}entity.info.parts_count{% endtrans %}</label>
<div class="col-md-8">
<p class="form-control-plaintext">
{% if entity.id and partsContainingElement %}
{{ repo.partsCount(entity) }}
{% else %}
@ -46,3 +46,19 @@
</p>
</div>
</div>
{# Check if we really have a structural element #}
{% if entity.parent is defined %}
<div class="form-group row">
<label class="col-form-label col-md-4">{% trans %}entity.info.parts_count_recursive{% endtrans %}</label>
<div class="col-md-8">
<p class="form-control-plaintext">
{% if entity.id and partsContainingElement %}
{{ repo.partsCountRecursive(entity) }}
{% else %}
-
{% endif %}
</p>
</div>
</div>
{% endif %}

View file

@ -1092,7 +1092,7 @@ Sub elements will be moved upwards.]]></target>
</notes>
<segment>
<source>entity.info.parts_count</source>
<target>Count of parts with this element</target>
<target>Number of parts with this element</target>
</segment>
</unit>
<unit id="4FQqOUW" name="specifications.property">
@ -9771,5 +9771,11 @@ Element 3</target>
<target>Target element ID</target>
</segment>
</unit>
<unit id="_vbPEFP" name="category.edit.partname_regex.placeholder">
<segment>
<source>category.edit.partname_regex.placeholder</source>
<target>Number of parts with this element or its subelements</target>
</segment>
</unit>
</file>
</xliff>