<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\UserGroupRepository;
use ApiPlatform\Core\Annotation\ApiFilter;
use App\Entity\Traits\TimestampableEntity;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Interfaces\ClientMappedInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* normalizationContext={"groups"={"UserGroup:Read"}, "skip_null_values"=false},
* denormalizationContext={"groups"={"UserGroup:Write"}},
* collectionOperations={
* "post",
* "get"={"security"="is_granted('ROLE_OPERATOR') || is_granted('ROLE_SUPPORT')"},
* "get_all"={
* "path"="/user_groups/get-all",
* "method"="GET",
* "pagination_enabled"=false,
* "security"="is_granted('ROLE_OPERATOR') || is_granted('ROLE_SUPPORT')"
* }
* },
* itemOperations={
* "get"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
* "put"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
* "patch"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
* "delete"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
* }
* )
* @ApiFilter(SearchFilter::class, properties={"name": "partial", "client.id": "exact", "containers.id": "exact", "users.id": "exact", "sessions.id": "exact"})
* @ApiFilter(BooleanFilter::class, properties={"isGenerated"})
* @ApiFilter(OrderFilter::class, properties={"id", "name": "ASC"})
* @ORM\Entity(repositoryClass=UserGroupRepository::class)
* @UniqueEntity(
* fields={"client", "name"},
* errorPath="name"
* )
* @ORM\Table(name="user_group",indexes={@ORM\Index(name="userGroup_name_idx", columns={"name"})})
*/
class UserGroup implements ClientMappedInterface
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"Conference:EL", "UserGroup:Read", "Container:Read", "User:Read", "Conference:Read", "Session:Read", "User:Me", "Document:Read", "ElCourse:Read", "VideoLibrary:Read", "DocFile:Read", "Nav:Read", "NavApp:Read", "Newsfeed:Read", "ElExam:Read", "VideoGallery:Read"})
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Client::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*
* @Groups({"UserGroup:Read", "UserGroup:Write"})
*/
private $client;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank(message="validation.userGroup:name.notBlank")
* @Assert\Length(max=255, maxMessage="validation.userGroup:name.max")
* @Groups({"Conference:EL", "User:Exp", "UserGroup:Read", "UserGroup:Write", "Container:Read", "User:Read", "Conference:Read", "Session:Read", "User:Me", "Document:Read", "ElCourse:Read", "VideoLibrary:Read", "DocFile:Read", "Nav:Read", "NavApp:Read", "Newsfeed:Read", "ElExam:Read", "VideoGallery:Read"})
*/
private $name;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"UserGroup:Read", "UserGroup:Write", "User:Read"})
* @Assert\Type(type="bool", message="validation.userGroup:isGenerated.typeBool")
*/
private $isGenerated = false;
/**
* @ORM\ManyToMany(targetEntity=Container::class, mappedBy="userGroups")
*/
private $containers;
/**
* @ORM\ManyToMany(targetEntity=User::class, mappedBy="userGroups")
*/
private $users;
/**
* @ORM\ManyToMany(targetEntity=Session::class, mappedBy="userGroups")
*/
private $sessions;
/**
* @ORM\ManyToMany(targetEntity=Survey::class, mappedBy="userGroups")
*/
private $surveys;
/**
* @ORM\ManyToMany(targetEntity=Conference::class, mappedBy="userGroups")
*/
private $conferences;
/**
* @ORM\ManyToMany(targetEntity=Nav::class, mappedBy="userGroups")
*/
private $navs;
/**
* @ORM\ManyToMany(targetEntity=Newsfeed::class, mappedBy="userGroups")
*/
private $newsfeeds;
public function __construct()
{
$this->users = new ArrayCollection();
$this->containers = new ArrayCollection();
$this->sessions = new ArrayCollection();
$this->surveys = new ArrayCollection();
$this->conferences = new ArrayCollection();
$this->navs = new ArrayCollection();
$this->newsfeeds = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getClient(): ?Client
{
return $this->client;
}
public function setClient(?client $client): self
{
$this->client = $client;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getIsGenerated(): ?bool
{
return $this->isGenerated;
}
public function setIsGenerated(?bool $isGenerated): self
{
$this->isGenerated = $isGenerated;
return $this;
}
/**
* @return Collection|Container[]
*/
public function getContainers(): Collection
{
return $this->containers;
}
public function addContainer(Container $container): self
{
if (!$this->containers->contains($container)) {
$this->containers[] = $container;
$container->addUserGroup($this);
}
return $this;
}
public function removeContainer(Container $container): self
{
if ($this->containers->removeElement($container)) {
$container->removeUserGroup($this);
}
return $this;
}
/**
* @return Collection|Container[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->addUserGroup($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
$user->removeUserGroup($this);
}
return $this;
}
/**
* @return Collection|Session[]
*/
public function getSessions(): Collection
{
return $this->sessions;
}
public function addSession(Session $session): self
{
if (!$this->sessions->contains($session)) {
$this->sessions[] = $session;
$session->addUserGroup($this);
}
return $this;
}
public function removeSession(Session $session): self
{
if ($this->sessions->removeElement($session)) {
$session->removeUserGroup($this);
}
return $this;
}
/**
* @return Collection|Survey[]
*/
public function getSurveys(): Collection
{
return $this->surveys;
}
public function addSurvey(Survey $survey): self
{
if (!$this->surveys->contains($survey)) {
$this->surveys[] = $survey;
$survey->addUserGroup($this);
}
return $this;
}
public function removeSurvey(Survey $survey): self
{
if ($this->surveys->removeElement($survey)) {
$survey->removeUserGroup($this);
}
return $this;
}
/**
* @return Collection<int, Conference>
*/
public function getConferences(): Collection
{
return $this->conferences;
}
public function addConference(Conference $conference): self
{
if (!$this->conferences->contains($conference)) {
$this->conferences[] = $conference;
$conference->addUserGroup($this);
}
return $this;
}
public function removeConference(Conference $conference): self
{
if ($this->conferences->removeElement($conference)) {
$conference->removeUserGroup($this);
}
}
/**
* @return Collection<int, Nav>
*/
public function getNavs(): Collection
{
return $this->navs;
}
public function addNav(Nav $nav): self
{
if (!$this->navs->contains($nav)) {
$this->navs[] = $nav;
$nav->addUserGroup($this);
}
return $this;
}
public function removeNav(Nav $nav): self
{
if ($this->navs->removeElement($nav)) {
$nav->removeUserGroup($this);
}
return $this;
}
/**
* @return Collection<int, Newsfeed>
*/
public function getNewsfeeds(): Collection
{
return $this->newsfeeds;
}
public function addNewsfeed(Newsfeed $newsfeed): self
{
if (!$this->newsfeeds->contains($newsfeed)) {
$this->newsfeeds[] = $newsfeed;
$newsfeed->addUserGroup($this);
}
return $this;
}
public function removeNewsfeed(Newsfeed $newsfeed): self
{
if ($this->newsfeeds->removeElement($newsfeed)) {
$newsfeed->removeUserGroup($this);
}
return $this;
}
}