<?php
namespace App\Entity;
use App\Repository\UserCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: UserCategoryRepository::class)]
class UserCategory
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $name;
#[ORM\Column(type: 'array', nullable: true)]
private $roles = [];
#[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'categories')]
private $users;
public function __construct()
{
$this->users = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getRoles(): ?array
{
return $this->roles;
}
public function setRoles(?array $roles): self
{
$this->roles = $roles;
return $this;
}
public function __toString()
{
return $this->name;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->addCategory($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
$user->removeCategory($this);
}
return $this;
}
}