*/ #[ORM\OneToMany(targetEntity: OustedLabel::class, mappedBy: 'book', cascade: ['persist', 'remove'], orphanRemoval: true)] #[ORM\OrderBy(['label' => 'ASC'])] private Collection $labels; /** @var Collection */ #[ORM\OneToMany(targetEntity: OustedBorrowHistory::class, mappedBy: 'book', cascade: ['persist', 'remove'], orphanRemoval: true)] #[ORM\OrderBy(['at' => 'DESC'])] private Collection $borrowHistory; public function __construct(string $reason) { $this->reason = $reason; $this->labels = new ArrayCollection(); $this->borrowHistory = new ArrayCollection(); } public static function fromBook(Book $book, string $reason): self { $ousted = new self($reason); $ousted->copyDataFrom($book); return $ousted; } public function getReason(): string { return $this->reason; } /** * @return Collection */ public function getLabels(): Collection { return $this->labels; } protected function createLabel(string $label, LabelType $type): OustedLabel { return new OustedLabel($this, $label, $type); } /** * @return Collection */ public function getBorrowHistory(): Collection { return $this->borrowHistory; } public function addBorrowHistory(string $who, \DateTimeImmutable $at, \DateTimeImmutable $till): void { $this->borrowHistory->add(new OustedBorrowHistory($this, $who, $at, $till)); } }