From e19cd67b88521830aa31780731803657e5779c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Wed, 4 Sep 2019 19:37:35 +0200 Subject: [PATCH] Show parts count on AdminPages of PartsContainingDBElements --- src/Entity/Base/Company.php | 2 +- src/Entity/Base/PartsContainingDBElement.php | 21 +++++++++ src/Entity/Parts/Category.php | 2 +- src/Entity/Parts/Footprint.php | 2 +- src/Entity/Parts/Manufacturer.php | 2 +- src/Entity/Parts/MeasurementUnit.php | 5 ++ src/Entity/Parts/Storelocation.php | 12 ++++- src/Entity/Parts/Supplier.php | 9 ++++ .../AdminPages/EntityAdminBase.html.twig | 34 +------------- templates/AdminPages/_info.html.twig | 46 +++++++++++++++++++ 10 files changed, 97 insertions(+), 38 deletions(-) create mode 100644 templates/AdminPages/_info.html.twig diff --git a/src/Entity/Base/Company.php b/src/Entity/Base/Company.php index b62aa62c..beebadd7 100644 --- a/src/Entity/Base/Company.php +++ b/src/Entity/Base/Company.php @@ -60,7 +60,7 @@ use Symfony\Component\Validator\Constraints as Assert; * * @ORM\MappedSuperclass() */ -abstract class Company extends StructuralDBElement +abstract class Company extends PartsContainingDBElement { /** * @var string The address of the company diff --git a/src/Entity/Base/PartsContainingDBElement.php b/src/Entity/Base/PartsContainingDBElement.php index bb0f1690..7c576d71 100644 --- a/src/Entity/Base/PartsContainingDBElement.php +++ b/src/Entity/Base/PartsContainingDBElement.php @@ -52,6 +52,9 @@ declare(strict_types=1); namespace App\Entity\Base; +use App\Entity\Parts\Part; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** @@ -61,5 +64,23 @@ use Doctrine\ORM\Mapping as ORM; */ abstract class PartsContainingDBElement extends StructuralDBElement { + /** + * @var Part[]|Collection + */ protected $parts; + + public function __construct() + { + parent::__construct(); + $this->parts = new ArrayCollection(); + } + + /** + * Returns the parts associated with this element. + * @return Collection|Part[] + */ + public function getParts() : Collection + { + return $this->parts; + } } diff --git a/src/Entity/Parts/Category.php b/src/Entity/Parts/Category.php index 59c5b24b..79f218eb 100644 --- a/src/Entity/Parts/Category.php +++ b/src/Entity/Parts/Category.php @@ -75,7 +75,7 @@ class Category extends PartsContainingDBElement protected $parent; /** - * @ORM\OneToMany(targetEntity="Part", mappedBy="category") + * @ORM\OneToMany(targetEntity="Part", mappedBy="category", fetch="EXTRA_LAZY") */ protected $parts; diff --git a/src/Entity/Parts/Footprint.php b/src/Entity/Parts/Footprint.php index 00bceac3..10b98410 100644 --- a/src/Entity/Parts/Footprint.php +++ b/src/Entity/Parts/Footprint.php @@ -90,7 +90,7 @@ class Footprint extends PartsContainingDBElement protected $filename; /** - * @ORM\OneToMany(targetEntity="Part", mappedBy="footprint") + * @ORM\OneToMany(targetEntity="Part", mappedBy="footprint", fetch="EXTRA_LAZY") */ protected $parts; diff --git a/src/Entity/Parts/Manufacturer.php b/src/Entity/Parts/Manufacturer.php index defb6373..01d7535f 100644 --- a/src/Entity/Parts/Manufacturer.php +++ b/src/Entity/Parts/Manufacturer.php @@ -84,7 +84,7 @@ class Manufacturer extends Company protected $parent; /** - * @ORM\OneToMany(targetEntity="Part", mappedBy="manufacturer") + * @ORM\OneToMany(targetEntity="Part", mappedBy="manufacturer", fetch="EXTRA_LAZY") */ protected $parts; diff --git a/src/Entity/Parts/MeasurementUnit.php b/src/Entity/Parts/MeasurementUnit.php index 25d74fa0..810814f7 100644 --- a/src/Entity/Parts/MeasurementUnit.php +++ b/src/Entity/Parts/MeasurementUnit.php @@ -82,6 +82,11 @@ class MeasurementUnit extends PartsContainingDBElement */ protected $parent; + /** + * @ORM\OneToMany(targetEntity="Part", mappedBy="partUnit", fetch="EXTRA_LAZY") + */ + protected $parts; + /** * Returns the ID as an string, defined by the element class. * This should have a form like P000014, for a part with ID 14. diff --git a/src/Entity/Parts/Storelocation.php b/src/Entity/Parts/Storelocation.php index db656012..835a2191 100644 --- a/src/Entity/Parts/Storelocation.php +++ b/src/Entity/Parts/Storelocation.php @@ -61,6 +61,7 @@ declare(strict_types=1); namespace App\Entity\Parts; +use App\Entity\Base\PartsContainingDBElement; use App\Entity\Base\StructuralDBElement; use Doctrine\ORM\Mapping as ORM; @@ -70,7 +71,7 @@ use Doctrine\ORM\Mapping as ORM; * @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository") * @ORM\Table("`storelocations`") */ -class Storelocation extends StructuralDBElement +class Storelocation extends PartsContainingDBElement { /** * @ORM\OneToMany(targetEntity="Storelocation", mappedBy="parent") @@ -108,6 +109,15 @@ class Storelocation extends StructuralDBElement */ protected $storage_type; + /** + * @ORM\ManyToMany(targetEntity="Part", fetch="EXTRA_LAZY") + * @ORM\JoinTable(name="part_lots", + * joinColumns={@ORM\JoinColumn(name="id_store_location", referencedColumnName="id")}, + * inverseJoinColumns={@ORM\JoinColumn(name="id_part", referencedColumnName="id")} + * ) + */ + protected $parts; + /******************************************************************************** * * Getters diff --git a/src/Entity/Parts/Supplier.php b/src/Entity/Parts/Supplier.php index 2a59fea0..d7effa4f 100644 --- a/src/Entity/Parts/Supplier.php +++ b/src/Entity/Parts/Supplier.php @@ -107,6 +107,15 @@ class Supplier extends Company */ protected $shipping_costs; + /** + * @ORM\ManyToMany(targetEntity="Part", fetch="EXTRA_LAZY") + * @ORM\JoinTable(name="orderdetails", + * joinColumns={@ORM\JoinColumn(name="id_supplier", referencedColumnName="id")}, + * inverseJoinColumns={@ORM\JoinColumn(name="part_id", referencedColumnName="id")} + * ) + */ + protected $parts; + /** * @return ?Currency */ diff --git a/templates/AdminPages/EntityAdminBase.html.twig b/templates/AdminPages/EntityAdminBase.html.twig index d6e28ef4..3c05d5c4 100644 --- a/templates/AdminPages/EntityAdminBase.html.twig +++ b/templates/AdminPages/EntityAdminBase.html.twig @@ -96,39 +96,7 @@
-
- -
-

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

-
-
- -
- -
-

- - {% if date(entity.addedDate) > date('1900/01/01') %} - {{ entity.addedDate | localizeddate("long") }} - {% else %} - - - {% endif %} -

-
-
- -
- -
-

- {% if date(entity.lastModified) > date('1900/01/01') %} - {{ entity.lastModified | localizeddate("long") }} - {% else %} - - - {% endif %} -

-
-
+ {% include "AdminPages/_info.html.twig" %}
diff --git a/templates/AdminPages/_info.html.twig b/templates/AdminPages/_info.html.twig new file mode 100644 index 00000000..2b1727c6 --- /dev/null +++ b/templates/AdminPages/_info.html.twig @@ -0,0 +1,46 @@ +
+ +
+

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

+
+
+ +
+ +
+

+ + {% if date(entity.addedDate) > date('1900/01/01') %} + {{ entity.addedDate | localizeddate("long") }} + {% else %} + - + {% endif %} +

+
+
+ +
+ +
+

+ {% if date(entity.lastModified) > date('1900/01/01') %} + {{ entity.lastModified | localizeddate("long") }} + {% else %} + - + {% endif %} +

+
+
+ +
+ +
+

+ {% if entity.id and entity.parts is defined %} + {{ entity.parts | length }} + {% else %} + - + {% endif %} +

+
+
\ No newline at end of file