Select Git revision
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;