. */ declare(strict_types=1); namespace App\Entity\Attachments; use App\Entity\Base\MasterAttachmentTrait; use App\Entity\Base\AbstractNamedDBElement; use App\Entity\Contracts\HasAttachmentsInterface; use App\Entity\Contracts\HasMasterAttachmentInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** * @ORM\MappedSuperclass() */ abstract class AttachmentContainingDBElement extends AbstractNamedDBElement implements HasMasterAttachmentInterface, HasAttachmentsInterface { use MasterAttachmentTrait; /** * @var Attachment[]|Collection * //TODO * //@ORM\OneToMany(targetEntity="Attachment", mappedBy="element") * * Mapping is done in sub classes like part */ protected $attachments; public function __construct() { $this->attachments = new ArrayCollection(); } /******************************************************************************** * * Getters * *********************************************************************************/ /** * Gets all attachments associated with this element. * * @return Attachment[]|Collection */ public function getAttachments(): Collection { return $this->attachments; } /** * Adds an attachment to this element. * * @param Attachment $attachment Attachment * * @return $this */ public function addAttachment(Attachment $attachment): self { //Attachment must be associated with this element $attachment->setElement($this); $this->attachments->add($attachment); return $this; } /** * Removes the given attachment from this element. * * @param Attachment $attachment * @return $this */ public function removeAttachment(Attachment $attachment): self { $this->attachments->removeElement($attachment); return $this; } }