src/Entity/UserGroup.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\UserGroupRepository;
  5. use ApiPlatform\Core\Annotation\ApiFilter;
  6. use App\Entity\Traits\TimestampableEntity;
  7. use Doctrine\Common\Collections\Collection;
  8. use ApiPlatform\Core\Annotation\ApiResource;
  9. use App\Entity\Interfaces\ClientMappedInterface;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  14. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  15. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  16. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  17. /**
  18.  * @ApiResource(
  19.  *      attributes={"security"="is_granted('ROLE_ADMIN')"},
  20.  *      normalizationContext={"groups"={"UserGroup:Read"}, "skip_null_values"=false},
  21.  *      denormalizationContext={"groups"={"UserGroup:Write"}},
  22.  *      collectionOperations={
  23.  *          "post",
  24.  *          "get"={"security"="is_granted('ROLE_OPERATOR') || is_granted('ROLE_SUPPORT')"},
  25.  *          "get_all"={
  26.  *              "path"="/user_groups/get-all",
  27.  *              "method"="GET",
  28.  *              "pagination_enabled"=false,
  29.  *              "security"="is_granted('ROLE_OPERATOR') || is_granted('ROLE_SUPPORT')"
  30.  *          }
  31.  *      },
  32.  *      itemOperations={
  33.  *          "get"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
  34.  *          "put"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
  35.  *          "patch"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
  36.  *          "delete"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
  37.  *      }
  38.  * )
  39.  * @ApiFilter(SearchFilter::class, properties={"name": "partial", "client.id": "exact", "containers.id": "exact", "users.id": "exact", "sessions.id": "exact"})
  40.  * @ApiFilter(BooleanFilter::class, properties={"isGenerated"})
  41.  * @ApiFilter(OrderFilter::class, properties={"id", "name": "ASC"})
  42.  * @ORM\Entity(repositoryClass=UserGroupRepository::class)
  43.  * @UniqueEntity(
  44.  *     fields={"client", "name"},
  45.  *     errorPath="name"
  46.  * )
  47.  * @ORM\Table(name="user_group",indexes={@ORM\Index(name="userGroup_name_idx", columns={"name"})})
  48.  */
  49. class UserGroup implements ClientMappedInterface
  50. {
  51.     /**
  52.      * Hook timestampable behavior
  53.      * updates createdAt, updatedAt fields
  54.      */
  55.     use TimestampableEntity;
  56.     /**
  57.      * @ORM\Id
  58.      * @ORM\GeneratedValue
  59.      * @ORM\Column(type="integer")
  60.      * @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"})
  61.      */
  62.     private $id;
  63.     /**
  64.      * @ORM\ManyToOne(targetEntity=Client::class)
  65.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  66.      * 
  67.      * @Groups({"UserGroup:Read", "UserGroup:Write"})
  68.      */
  69.     private $client;
  70.     /**
  71.      * @ORM\Column(type="string", length=255)
  72.      * @Assert\NotBlank(message="validation.userGroup:name.notBlank")
  73.      * @Assert\Length(max=255, maxMessage="validation.userGroup:name.max")
  74.      * @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"})
  75.      */
  76.     private $name;
  77.     /**
  78.      * @ORM\Column(type="boolean", nullable=true)
  79.      * @Groups({"UserGroup:Read", "UserGroup:Write", "User:Read"})
  80.      * @Assert\Type(type="bool", message="validation.userGroup:isGenerated.typeBool")
  81.      */
  82.     private $isGenerated false;
  83.     /**
  84.      * @ORM\ManyToMany(targetEntity=Container::class, mappedBy="userGroups")
  85.      */
  86.     private $containers;
  87.     /**
  88.      * @ORM\ManyToMany(targetEntity=User::class, mappedBy="userGroups")
  89.      */
  90.     private $users;
  91.     /**
  92.      * @ORM\ManyToMany(targetEntity=Session::class, mappedBy="userGroups")
  93.      */
  94.     private $sessions;
  95.     /**
  96.      * @ORM\ManyToMany(targetEntity=Survey::class, mappedBy="userGroups")
  97.      */
  98.     private $surveys;
  99.     /**
  100.      * @ORM\ManyToMany(targetEntity=Conference::class, mappedBy="userGroups")
  101.      */
  102.     private $conferences;
  103.     /**
  104.      * @ORM\ManyToMany(targetEntity=Nav::class, mappedBy="userGroups")
  105.      */
  106.     private $navs;
  107.     /**
  108.      * @ORM\ManyToMany(targetEntity=Newsfeed::class, mappedBy="userGroups")
  109.      */
  110.     private $newsfeeds;
  111.     public function __construct()
  112.     {
  113.         $this->users = new ArrayCollection();
  114.         $this->containers = new ArrayCollection();
  115.         $this->sessions = new ArrayCollection();
  116.         $this->surveys = new ArrayCollection();
  117.         $this->conferences = new ArrayCollection();
  118.         $this->navs = new ArrayCollection();
  119.         $this->newsfeeds = new ArrayCollection();
  120.     }
  121.     public function getId(): ?int
  122.     {
  123.         return $this->id;
  124.     }
  125.     public function getClient(): ?Client
  126.     {
  127.         return $this->client;
  128.     }
  129.     public function setClient(?client $client): self
  130.     {
  131.         $this->client $client;
  132.         return $this;
  133.     }
  134.     public function getName(): ?string
  135.     {
  136.         return $this->name;
  137.     }
  138.     public function setName(string $name): self
  139.     {
  140.         $this->name $name;
  141.         return $this;
  142.     }
  143.     public function getIsGenerated(): ?bool
  144.     {
  145.         return $this->isGenerated;
  146.     }
  147.     public function setIsGenerated(?bool $isGenerated): self
  148.     {
  149.         $this->isGenerated $isGenerated;
  150.         return $this;
  151.     }
  152.     /**
  153.      * @return Collection|Container[]
  154.      */
  155.     public function getContainers(): Collection
  156.     {
  157.         return $this->containers;
  158.     }
  159.     public function addContainer(Container $container): self
  160.     {
  161.         if (!$this->containers->contains($container)) {
  162.             $this->containers[] = $container;
  163.             $container->addUserGroup($this);
  164.         }
  165.         return $this;
  166.     }
  167.     public function removeContainer(Container $container): self
  168.     {
  169.         if ($this->containers->removeElement($container)) {
  170.             $container->removeUserGroup($this);
  171.         }
  172.         return $this;
  173.     }
  174.     /**
  175.      * @return Collection|Container[]
  176.      */
  177.     public function getUsers(): Collection
  178.     {
  179.         return $this->users;
  180.     }
  181.     public function addUser(User $user): self
  182.     {
  183.         if (!$this->users->contains($user)) {
  184.             $this->users[] = $user;
  185.             $user->addUserGroup($this);
  186.         }
  187.         return $this;
  188.     }
  189.     public function removeUser(User $user): self
  190.     {
  191.         if ($this->users->removeElement($user)) {
  192.             $user->removeUserGroup($this);
  193.         }
  194.         return $this;
  195.     }
  196.     /**
  197.      * @return Collection|Session[]
  198.      */
  199.     public function getSessions(): Collection
  200.     {
  201.         return $this->sessions;
  202.     }
  203.     public function addSession(Session $session): self
  204.     {
  205.         if (!$this->sessions->contains($session)) {
  206.             $this->sessions[] = $session;
  207.             $session->addUserGroup($this);
  208.         }
  209.         return $this;
  210.     }
  211.     public function removeSession(Session $session): self
  212.     {
  213.         if ($this->sessions->removeElement($session)) {
  214.             $session->removeUserGroup($this);
  215.         }
  216.         return $this;
  217.     }
  218.     /**
  219.      * @return Collection|Survey[]
  220.      */
  221.     public function getSurveys(): Collection
  222.     {
  223.         return $this->surveys;
  224.     }
  225.     public function addSurvey(Survey $survey): self
  226.     {
  227.         if (!$this->surveys->contains($survey)) {
  228.             $this->surveys[] = $survey;
  229.             $survey->addUserGroup($this);
  230.         }
  231.         return $this;
  232.     }
  233.     public function removeSurvey(Survey $survey): self
  234.     {
  235.         if ($this->surveys->removeElement($survey)) {
  236.             $survey->removeUserGroup($this);
  237.         }
  238.         return $this;
  239.     }
  240.     /**
  241.      * @return Collection<int, Conference>
  242.      */
  243.     public function getConferences(): Collection
  244.     {
  245.         return $this->conferences;
  246.     }
  247.     public function addConference(Conference $conference): self
  248.     {
  249.         if (!$this->conferences->contains($conference)) {
  250.             $this->conferences[] = $conference;
  251.             $conference->addUserGroup($this);
  252.         }
  253.         return $this;
  254.     }
  255.     public function removeConference(Conference $conference): self
  256.     {
  257.         if ($this->conferences->removeElement($conference)) {
  258.             $conference->removeUserGroup($this);
  259.         }
  260.     }
  261.     /**
  262.      * @return Collection<int, Nav>
  263.      */
  264.     public function getNavs(): Collection
  265.     {
  266.         return $this->navs;
  267.     }
  268.     public function addNav(Nav $nav): self
  269.     {
  270.         if (!$this->navs->contains($nav)) {
  271.             $this->navs[] = $nav;
  272.             $nav->addUserGroup($this);
  273.         }
  274.         return $this;
  275.     }
  276.     public function removeNav(Nav $nav): self
  277.     {
  278.         if ($this->navs->removeElement($nav)) {
  279.             $nav->removeUserGroup($this);
  280.         }
  281.         return $this;
  282.     }
  283.     /**
  284.      * @return Collection<int, Newsfeed>
  285.      */
  286.     public function getNewsfeeds(): Collection
  287.     {
  288.         return $this->newsfeeds;
  289.     }
  290.     public function addNewsfeed(Newsfeed $newsfeed): self
  291.     {
  292.         if (!$this->newsfeeds->contains($newsfeed)) {
  293.             $this->newsfeeds[] = $newsfeed;
  294.             $newsfeed->addUserGroup($this);
  295.         }
  296.         return $this;
  297.     }
  298.     public function removeNewsfeed(Newsfeed $newsfeed): self
  299.     {
  300.         if ($this->newsfeeds->removeElement($newsfeed)) {
  301.             $newsfeed->removeUserGroup($this);
  302.         }
  303.         return $this;
  304.     }    
  305. }