Assemblies einführen

This commit is contained in:
Marcel Diegelmann 2025-03-19 08:13:45 +01:00
parent e1418dfdc1
commit 6fa960df42
107 changed files with 14101 additions and 96 deletions

View file

@ -54,6 +54,7 @@ use App\Entity\Parts\PartTraits\InstockTrait;
use App\Entity\Parts\PartTraits\ManufacturerTrait;
use App\Entity\Parts\PartTraits\OrderTrait;
use App\Entity\Parts\PartTraits\ProjectTrait;
use App\Entity\Parts\PartTraits\AssemblyTrait;
use App\EntityListeners\TreeCacheInvalidationListener;
use App\Repository\PartRepository;
use App\Validator\Constraints\UniqueObjectCollection;
@ -125,6 +126,7 @@ class Part extends AttachmentContainingDBElement
use OrderTrait;
use ParametersTrait;
use ProjectTrait;
use AssemblyTrait;
use AssociationTrait;
use EDATrait;
@ -186,6 +188,7 @@ class Part extends AttachmentContainingDBElement
$this->orderdetails = new ArrayCollection();
$this->parameters = new ArrayCollection();
$this->project_bom_entries = new ArrayCollection();
$this->assembly_bom_entries = new ArrayCollection();
$this->associated_parts_as_owner = new ArrayCollection();
$this->associated_parts_as_other = new ArrayCollection();

View file

@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace App\Entity\Parts\PartTraits;
use App\Entity\AssemblySystem\Assembly;
use App\Entity\AssemblySystem\AssemblyBOMEntry;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
trait AssemblyTrait
{
/**
* @var Collection<AssemblyBOMEntry> $assembly_bom_entries
*/
#[ORM\OneToMany(mappedBy: 'part', targetEntity: AssemblyBOMEntry::class, cascade: ['remove'], orphanRemoval: true)]
protected Collection $assembly_bom_entries;
/**
* @var Assembly|null If a assembly is set here, then this part is special and represents the builds of an assembly.
*/
#[ORM\OneToOne(inversedBy: 'build_part', targetEntity: Assembly::class)]
#[ORM\JoinColumn]
protected ?Assembly $built_assembly = null;
/**
* Returns all AssemblyBOMEntry that use this part.
*
* @phpstan-return Collection<int, AssemblyBOMEntry>
*/
public function getAssemblyBomEntries(): Collection
{
return $this->assembly_bom_entries;
}
/**
* Checks whether this part represents the builds of a assembly
* @return bool True if it represents the builds, false if not
*/
#[Groups(['part:read'])]
public function isAssemblyBuildPart(): bool
{
return $this->built_assembly !== null;
}
/**
* Returns the assembly that this part represents the builds of, or null if it doesn't
*/
public function getBuiltAssembly(): ?Assembly
{
return $this->built_assembly;
}
/**
* Sets the assembly that this part represents the builds of
* @param Assembly|null $built_assembly The assembly that this part represents the builds of, or null if it is not a build part
*/
public function setBuiltAssembly(?Assembly $built_assembly): self
{
$this->built_assembly = $built_assembly;
return $this;
}
/**
* Get all assemblies which uses this part.
*
* @return Assembly[] all assemblies which uses this part as a one-dimensional array of Assembly objects
*/
public function getAssemblies(): array
{
$assemblies = [];
foreach($this->assembly_bom_entries as $entry) {
$assemblies[] = $entry->getAssembly();
}
return $assemblies;
}
}