mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-13 05:39:33 +00:00
Baugruppen Stückliste um referenzierte Baugruppe erweitern
This commit is contained in:
parent
4f9c20a409
commit
4e1c890b5b
48 changed files with 1205 additions and 152 deletions
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\AssemblySystem;
|
||||
|
||||
use App\Repository\AssemblyRepository;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
use ApiPlatform\Metadata\ApiFilter;
|
||||
|
|
@ -38,6 +39,7 @@ use ApiPlatform\Serializer\Filter\PropertyFilter;
|
|||
use App\ApiPlatform\Filter\LikeFilter;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Validator\Constraints\UniqueObjectCollection;
|
||||
use App\Validator\Constraints\AssemblySystem\UniqueReferencedAssembly;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use App\Entity\Attachments\AssemblyAttachment;
|
||||
use App\Entity\Base\AbstractStructuralDBElement;
|
||||
|
|
@ -58,7 +60,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|||
*
|
||||
* @extends AbstractStructuralDBElement<AssemblyAttachment, AssemblyParameter>
|
||||
*/
|
||||
#[ORM\Entity]
|
||||
#[ORM\Entity(repositoryClass: AssemblyRepository::class)]
|
||||
#[ORM\Table(name: 'assemblies')]
|
||||
#[UniqueEntity(fields: ['ipn'], message: 'assembly.ipn.must_be_unique')]
|
||||
#[ORM\Index(columns: ['ipn'], name: 'assembly_idx_ipn')]
|
||||
|
|
@ -109,8 +111,9 @@ class Assembly extends AbstractStructuralDBElement
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[Groups(['extended', 'full', 'import'])]
|
||||
#[ORM\OneToMany(mappedBy: 'assembly', targetEntity: AssemblyBOMEntry::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OneToMany(targetEntity: AssemblyBOMEntry::class, mappedBy: 'assembly', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[UniqueObjectCollection(message: 'assembly.bom_entry.part_already_in_bom', fields: ['part'])]
|
||||
#[UniqueReferencedAssembly]
|
||||
#[UniqueObjectCollection(message: 'assembly.bom_entry.project_already_in_bom', fields: ['project'])]
|
||||
#[UniqueObjectCollection(message: 'assembly.bom_entry.name_already_in_bom', fields: ['name'])]
|
||||
protected Collection $bom_entries;
|
||||
|
|
@ -386,4 +389,22 @@ class Assembly extends AbstractStructuralDBElement
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all referenced assemblies which uses this assembly.
|
||||
*
|
||||
* @return Assembly[] all referenced assemblies which uses this assembly as a one-dimensional array of assembly objects
|
||||
*/
|
||||
public function getReferencedAssemblies(): array
|
||||
{
|
||||
$assemblies = [];
|
||||
|
||||
foreach($this->bom_entries as $entry) {
|
||||
if ($entry->getAssembly() !== null) {
|
||||
$assemblies[] = $entry->getReferencedAssembly();
|
||||
}
|
||||
}
|
||||
|
||||
return $assemblies;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,6 +133,18 @@ class AssemblyBOMEntry extends AbstractDBElement implements UniqueValidatableInt
|
|||
#[Groups(['bom_entry:read', 'bom_entry:write', 'full'])]
|
||||
protected ?Part $part = null;
|
||||
|
||||
/**
|
||||
* @var Assembly|null The associated assembly
|
||||
*/
|
||||
#[Assert\Expression(
|
||||
'(this.getPart() === null or this.getReferencedAssembly() === null) and (this.getName() === null or (this.getName() != null and this.getName() != ""))',
|
||||
message: 'validator.assembly.bom_entry.only_part_or_assembly_allowed'
|
||||
)]
|
||||
#[ORM\ManyToOne(targetEntity: Assembly::class)]
|
||||
#[ORM\JoinColumn(name: 'id_referenced_assembly', nullable: true, onDelete: 'SET NULL')]
|
||||
#[Groups(['bom_entry:read', 'bom_entry:write', ])]
|
||||
protected ?Assembly $referencedAssembly = null;
|
||||
|
||||
/**
|
||||
* @var Project|null The associated project
|
||||
*/
|
||||
|
|
@ -237,6 +249,17 @@ class AssemblyBOMEntry extends AbstractDBElement implements UniqueValidatableInt
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getReferencedAssembly(): ?Assembly
|
||||
{
|
||||
return $this->referencedAssembly;
|
||||
}
|
||||
|
||||
public function setReferencedAssembly(?Assembly $referencedAssembly): AssemblyBOMEntry
|
||||
{
|
||||
$this->referencedAssembly = $referencedAssembly;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProject(): ?Project
|
||||
{
|
||||
return $this->project;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue