diff --git a/src/Entity/Parts/Part.php b/src/Entity/Parts/Part.php index 281d577b..51573138 100644 --- a/src/Entity/Parts/Part.php +++ b/src/Entity/Parts/Part.php @@ -25,6 +25,7 @@ namespace App\Entity\Parts; use App\Entity\Attachments\Attachment; use App\Entity\Attachments\AttachmentContainingDBElement; use App\Entity\Attachments\PartAttachment; +use App\Entity\Parts\PartTraits\ProjectTrait; use App\Entity\ProjectSystem\Project; use App\Entity\Parameters\ParametersTrait; use App\Entity\Parameters\PartParameter; @@ -64,12 +65,7 @@ class Part extends AttachmentContainingDBElement use ManufacturerTrait; use OrderTrait; use ParametersTrait; - - /** - * @var Collection $project_bom_entries - * @ORM\OneToMany(targetEntity="App\Entity\ProjectSystem\ProjectBOMEntry", mappedBy="part") - */ - protected $project_bom_entries = []; + use ProjectTrait; /** @var Collection * @Assert\Valid() @@ -151,33 +147,4 @@ 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. - * - * @return Project[] * all devices which uses this part as a one-dimensional array of Device objects - * (empty array if there are no ones) - * * the array is sorted by the devices names - */ - public function getProjects(): array - { - $projects = []; - - foreach($this->project_bom_entries as $entry) { - $projects[] = $entry->getProject(); - } - - return $projects; - } } diff --git a/src/Entity/Parts/PartTraits/ProjectTrait.php b/src/Entity/Parts/PartTraits/ProjectTrait.php new file mode 100644 index 00000000..998d6bc8 --- /dev/null +++ b/src/Entity/Parts/PartTraits/ProjectTrait.php @@ -0,0 +1,44 @@ + $project_bom_entries + * @ORM\OneToMany(targetEntity="App\Entity\ProjectSystem\ProjectBOMEntry", mappedBy="part", cascade={"remove"}, orphanRemoval=true) + */ + protected $project_bom_entries = []; + + /** + * 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. + * + * @return Project[] * all devices which uses this part as a one-dimensional array of Device objects + * (empty array if there are no ones) + * * the array is sorted by the devices names + */ + public function getProjects(): array + { + $projects = []; + + foreach($this->project_bom_entries as $entry) { + $projects[] = $entry->getProject(); + } + + return $projects; + } +} \ No newline at end of file