Added ability to view part relations on a part info page

This commit is contained in:
Jan Böhmer 2023-11-15 00:44:45 +01:00
parent cc2332a83a
commit 7f612bc371
7 changed files with 143 additions and 0 deletions

View file

@ -136,5 +136,17 @@ class PartAssociation extends AbstractDBElement
return $this;
}
/**
* Returns the translation key for the type of this association.
* If the type is set to OTHER, then the other_type field value is used.
* @return string
*/
public function getTypeTranslationKey(): string
{
if ($this->type === AssociationType::OTHER) {
return $this->other_type ?? 'Unknown';
}
return $this->type->getTranslationKey();
}
}

View file

@ -23,7 +23,9 @@ declare(strict_types=1);
namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartAssociation;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Validator\Constraints\Valid;
use Doctrine\ORM\Mapping as ORM;
@ -89,4 +91,18 @@ trait AssociationTrait
{
return $this->associated_parts_as_other;
}
/**
* Returns all associations where this part is the owned or other part.
* @return Collection<PartAssociation>
*/
public function getAssociatedPartsAll(): Collection
{
return new ArrayCollection(
array_merge(
$this->associated_parts_as_owner->toArray(),
$this->associated_parts_as_other->toArray()
)
);
}
}