mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-23 02:09:03 +02:00
Added ability to view part relations on a part info page
This commit is contained in:
parent
cc2332a83a
commit
7f612bc371
7 changed files with 143 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue