src/Entity/UserTag.php line 51

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\UserTagRepository;
  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\ElasticUpdateInterface;
  10. use App\Entity\Interfaces\ClientMappedInterface;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  15. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  16. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  17. /**
  18.  * @ApiResource(
  19.  *      attributes={"security"="is_granted('ROLE_ADMIN')"},
  20.  *      normalizationContext={"groups"={"UserTag:Read"}, "skip_null_values"=false},
  21.  *      denormalizationContext={"groups"={"UserTag:Write"}},
  22.  *      collectionOperations={
  23.  *          "post",
  24.  *          "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
  25.  *          "get_for_public_page"={
  26.  *              "route_name"="api_pub_user_tags_get_for_public_page_collection",
  27.  *              "method"="GET",
  28.  *              "security"="is_granted('PUBLIC_ACCESS')",
  29.  *              "normalization_context"={"groups"={"UserTag:PRead"}, "skip_null_values"=false}
  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"})
  40.  * @ApiFilter(OrderFilter::class, properties={"id": "ASC", "name"})
  41.  * @ORM\Entity(repositoryClass=UserTagRepository::class)
  42.  * @ORM\Table(name="user_tag",indexes={@ORM\Index(name="user_tag_name_idx", columns={"name"})})
  43.  * @UniqueEntity(
  44.  *     fields={"client", "name"},
  45.  *     errorPath="name"
  46.  * )
  47.  */
  48. class UserTag implements ClientMappedInterfaceElasticUpdateInterface
  49. {
  50.     /**
  51.      * Hook timestampable behavior
  52.      * updates createdAt, updatedAt fields
  53.      */
  54.     use TimestampableEntity;
  55.     /**
  56.      * @ORM\Id
  57.      * @ORM\GeneratedValue
  58.      * @ORM\Column(type="integer")
  59.      * @Groups({"UserTag:Read", "User:Read", "User:Me", "UserTag:PRead"})
  60.      */
  61.     private $id;
  62.     /**
  63.      * @ORM\Column(type="string", length=64)
  64.      * @Groups({"User:Exp", "UserTag:Read", "UserTag:Write", "User:Read", "User:Write", "User:Me", "User:Attendee-List", "User:Change-Profile", "User:PRead", "UserTag:PRead"})
  65.      *
  66.      * @Assert\NotBlank(message="validation.userTag:name.notBlank")
  67.      * @Assert\Length(max=64, maxMessage="validation.userTag:name.max")
  68.      */
  69.     private $name;
  70.     /**
  71.      * @ORM\ManyToMany(targetEntity=User::class, inversedBy="userTags")
  72.      * @Groups({"UserTag:Write"})
  73.      */
  74.     private $users;
  75.     /**
  76.      * @ORM\ManyToOne(targetEntity=Client::class)
  77.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  78.      * @Groups({"UserTag:Read", "UserTag:Write", "User:Write", "User:Change-Profile"})
  79.      */
  80.     private $client;
  81.     public function __construct()
  82.     {
  83.         $this->users = new ArrayCollection();
  84.     }
  85.     public function getId(): ?int
  86.     {
  87.         return $this->id;
  88.     }
  89.     public function getName(): ?string
  90.     {
  91.         return $this->name;
  92.     }
  93.     public function setName(string $name): self
  94.     {
  95.         $this->name $name;
  96.         return $this;
  97.     }
  98.     /**
  99.      * @return Collection|User[]
  100.      */
  101.     public function getUsers(): Collection
  102.     {
  103.         return $this->users;
  104.     }
  105.     public function addUser(User $user): self
  106.     {
  107.         if (!$this->users->contains($user)) {
  108.             $this->users[] = $user;
  109.         }
  110.         return $this;
  111.     }
  112.     public function removeUser(User $user): self
  113.     {
  114.         $this->users->removeElement($user);
  115.         return $this;
  116.     }
  117.     public function getClient(): ?Client
  118.     {
  119.         return $this->client;
  120.     }
  121.     public function setClient(?Client $client): self
  122.     {
  123.         $this->client $client;
  124.         return $this;
  125.     }
  126.     public function getQueueInfo(): array
  127.     {
  128.         return [
  129.             'type' => 'UserTag',
  130.             'id' => $this->getId()
  131.         ];
  132.     }
  133. }