Select Git revision
SSC-01-05.amr.graph
Group.php 2.39 KiB
<?php
namespace App\Entity;
use App\Repository\GroupRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity(repositoryClass:GroupRepository::class)]
#[ORM\Table(name:'`group`')]
#[ORM\UniqueConstraint(columns: ['name', 'author'])]
#[UniqueEntity(fields: ['name', 'author'], message: 'group.name.unique', errorPath: 'name')]
class Group
{
public static int $GROUP_ALL_ID = -1;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type:'integer')]
private int $id;
#[ORM\Column(type:'string', length:255)]
private string $name;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'groups')]
#[ORM\JoinColumn(name: 'author', referencedColumnName: 'id', nullable: false)]
protected User $author;
/**
* @var Collection<Capsule>
*/
#[ORM\ManyToMany(targetEntity:Capsule::class, inversedBy:'groups')]
private Collection $capsules;
public function __construct()
{
$this->capsules = new ArrayCollection();
}
public function getId(): int
{
return $this->id;
}
public function setId(int $id): void
{
$this->id = $id;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getAuthor(): User
{
return $this->author;
}
public function setAuthor(User $author): self
{
$this->author = $author;
return $this;
}
/**
* @return Collection<Capsule>
*/
public function getCapsules(): Collection
{
return $this->capsules;
}
public function addCapsule(Capsule $capsule): self
{
if (!$this->capsules->contains($capsule)) {
$this->capsules[] = $capsule;
$capsule->addGroup($this);
}
return $this;
}
/**
* @param array<Capsule> $capsules
*/
public function addCapsules(array $capsules): self
{
foreach ($capsules as $capsule) {
$this->addCapsule($capsule);
}
return $this;
}
public function removeCapsule(Capsule $capsule): self
{
$this->capsules->removeElement($capsule);
return $this;
}
}