<?php
/**
* @package BLUUE
* @author Thomas HERISSON (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace App\Entity;
use Symfony\Component\Uid\Uuid;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\ProfileRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=ProfileRepository::class)
* @ORM\Table(name="profile", indexes={
* @ORM\Index(name="name", columns={"name"}),
* @ORM\Index(name="deleted_at", columns={"deleted_at"})
* })
*/
class Profile
{
use TimestampableEntity;
use SoftDeleteableEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid")
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
* @Groups({"get"})
*/
private ?Uuid $id = null;
/**
* @ORM\Column(type="string", length=64)
* @Groups({"get"})
*/
private string $name;
/**
* @ORM\Column(type="json")
* @Groups({"get"})
*/
private array $roles = [];
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="profile", fetch="EXTRA_LAZY")
*/
private Collection $users;
public function __construct()
{
$this->users = new ArrayCollection();
}
/**
* @return Uuid|null
*/
public function getId(): ?Uuid
{
return $this->id;
}
/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @return array
*/
public function getRoles(): array
{
return $this->roles;
}
/**
* @param string $name
* @return $this
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @param array $roles
* @return $this
*/
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
/**
* @param User $user
* @return $this
*/
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setProfile($this);
}
return $this;
}
/**
* @param User $user
* @return $this
*/
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
if ($user->getProfile() === $this) {
$user->setProfile(null);
}
}
return $this;
}
}