diff --git a/src/Entity/Parts/Part.php b/src/Entity/Parts/Part.php index 20bc1020..281d577b 100644 --- a/src/Entity/Parts/Part.php +++ b/src/Entity/Parts/Part.php @@ -33,6 +33,7 @@ use App\Entity\Parts\PartTraits\BasicPropertyTrait; use App\Entity\Parts\PartTraits\InstockTrait; use App\Entity\Parts\PartTraits\ManufacturerTrait; use App\Entity\Parts\PartTraits\OrderTrait; +use App\Entity\ProjectSystem\ProjectBOMEntry; use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; @@ -65,9 +66,10 @@ class Part extends AttachmentContainingDBElement use ParametersTrait; /** - * TODO. + * @var Collection $project_bom_entries + * @ORM\OneToMany(targetEntity="App\Entity\ProjectSystem\ProjectBOMEntry", mappedBy="part") */ - protected $devices = []; + protected $project_bom_entries = []; /** @var Collection * @Assert\Valid() @@ -120,6 +122,7 @@ class Part extends AttachmentContainingDBElement $this->partLots = new ArrayCollection(); $this->orderdetails = new ArrayCollection(); $this->parameters = new ArrayCollection(); + $this->project_bom_entries = new ArrayCollection(); } public function __clone() @@ -149,6 +152,17 @@ class Part extends AttachmentContainingDBElement parent::__clone(); } + /** + * Returns all ProjectBOMEntries that use this part. + * @return Collection|ProjectBOMEntry[] + */ + public function getProjectBomEntries(): Collection + { + return $this->project_bom_entries; + } + + + /** * Get all devices which uses this part. * @@ -156,8 +170,14 @@ class Part extends AttachmentContainingDBElement * (empty array if there are no ones) * * the array is sorted by the devices names */ - public function getDevices(): array + public function getProjects(): array { - return $this->devices; + $projects = []; + + foreach($this->project_bom_entries as $entry) { + $projects[] = $entry->getProject(); + } + + return $projects; } } diff --git a/src/Entity/ProjectSystem/ProjectBOMEntry.php b/src/Entity/ProjectSystem/ProjectBOMEntry.php index 221c77bd..2d039411 100644 --- a/src/Entity/ProjectSystem/ProjectBOMEntry.php +++ b/src/Entity/ProjectSystem/ProjectBOMEntry.php @@ -72,7 +72,7 @@ class ProjectBOMEntry extends AbstractDBElement /** * @var Part|null The part associated with this - * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part") + * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="project_bom_entries") * @ORM\JoinColumn(name="id_part", referencedColumnName="id", nullable=true) */ protected ?Part $part = null; diff --git a/templates/Parts/info/_projects.html.twig b/templates/Parts/info/_projects.html.twig new file mode 100644 index 00000000..a4c265c8 --- /dev/null +++ b/templates/Parts/info/_projects.html.twig @@ -0,0 +1,26 @@ +{% import "components/attachments.macro.html.twig" as attachments %} + + + + + + + + + + + + + + {% for bom_entry in part.projectBomEntries %} + + + {# Name #} + {# Description #} + + + + {% endfor %} + + +
{% trans %}entity.info.name{% endtrans %}{% trans %}description.label{% endtrans %}{% trans %}project.bom.quantity{% endtrans %}{% trans %}project.bom.mountnames{% endtrans %}
{% if bom_entry.project.masterPictureAttachment is not null %}{{ attachments.attachment_icon(bom_entry.project.masterPictureAttachment, attachment_manager) }}{% endif %}{{ bom_entry.project.name }}{{ bom_entry.project.description|format_markdown }}{{ bom_entry.quantity | format_amount(part.partUnit) }}{{ bom_entry.mountnames }}
\ No newline at end of file diff --git a/templates/Parts/info/show_part_info.html.twig b/templates/Parts/info/show_part_info.html.twig index 021b6666..10cd423e 100644 --- a/templates/Parts/info/show_part_info.html.twig +++ b/templates/Parts/info/show_part_info.html.twig @@ -91,6 +91,15 @@ {% trans %}vendor.partinfo.history{% endtrans %} + {% if part.projectBomEntries is not empty %} + + {% endif %}