You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
2.6 KiB

<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiProperty;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OneToOne;
#[Entity]
class Dojo extends Thing
{
#[Column(unique: true)]
public string $name;
/** @var Character[] */
#[ApiProperty(writable: false)]
#[OneToMany(targetEntity: Character::class, mappedBy: 'dojo')]
#[JoinColumn(onDelete: 'cascade', nullable: false)]
public iterable $members;
#[ApiProperty(writable: false)]
#[ManyToOne()]
#[JoinColumn(onDelete: 'cascade', nullable: true)]
public ?Village $village;
#[ApiProperty(writable: false)]
#[OneToOne(inversedBy: 'dojo', cascade: [
'persist'
])]
#[JoinColumn(onDelete: 'cascade', nullable: false)]
public User $owner;
public function __construct()
{
$this->members = new ArrayCollection();
}
/**
* Helper method that reads the timestamp section from the ulid
*/
public function getCreatedAt(): \DateTimeImmutable
{
return $this->id->getDateTime();
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Character>
*/
public function getMembers(): Collection
{
return $this->members;
}
public function addMember(Character $member): static
{
if (!$this->members->contains($member)) {
$this->members->add($member);
$member->setDojo($this);
}
return $this;
}
public function removeMember(Character $member): static
{
if ($this->members->removeElement($member)) {
// set the owning side to null (unless already changed)
if ($member->getDojo() === $this) {
$member->setDojo(null);
}
}
return $this;
}
public function getVillage(): ?Village
{
return $this->village;
}
public function setVillage(?Village $village): static
{
$this->village = $village;
return $this;
}
public function getOwner(): ?User
{
return $this->owner;
}
public function setOwner(User $owner): static
{
$this->owner = $owner;
return $this;
}
}