src/Entity/CompanyTag.php line 48

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\CompanyTagRepository;
  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 ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  13. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  14. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  15. /**
  16.  * @ApiResource(
  17.  *      attributes={"security"="is_granted('ROLE_ADMIN')"},
  18.  *      normalizationContext={"groups"={"CompanyTag:Read"}, "skip_null_values"=false},
  19.  *      denormalizationContext={"groups"={"CompanyTag:Write"}},
  20.  *      collectionOperations={
  21.  *          "post",
  22.  *          "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
  23.  *          "get_for_public_page"={
  24.  *              "route_name"="api_pub_company_tags_get_for_public_page_collection",
  25.  *              "method"="GET",
  26.  *              "security"="is_granted('PUBLIC_ACCESS')",
  27.  *              "normalization_context"={"groups"={"CompanyTag:PRead"}, "skip_null_values"=false}
  28.  *          }
  29.  *      },
  30.  *      itemOperations={
  31.  *          "get"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
  32.  *          "put"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
  33.  *          "patch"={"security"="is_granted('IS_CLIENT_OWNER', object)"},
  34.  *          "delete"={"security"="is_granted('IS_CLIENT_OWNER', object)"}
  35.  *      }
  36.  * )
  37.  * @ApiFilter(SearchFilter::class, properties={"name": "partial", "client.id": "exact"})
  38.  * @ApiFilter(OrderFilter::class, properties={"id": "ASC", "name"})
  39.  * @ORM\Entity(repositoryClass=CompanyTagRepository::class)
  40.  * @UniqueEntity(
  41.  *     fields={"client", "name"},
  42.  *     errorPath="name"
  43.  * )
  44.  */
  45. class CompanyTag implements ClientMappedInterface
  46. {
  47.     /**
  48.      * Hook timestampable behavior
  49.      * updates createdAt, updatedAt fields
  50.      */
  51.     use TimestampableEntity;
  52.     /**
  53.      * @ORM\Id
  54.      * @ORM\GeneratedValue
  55.      * @ORM\Column(type="integer")
  56.      * @Groups({"CompanyTag:Read", "Company:Read", "CompanyTag:PRead", "Company:PRead"})
  57.      */
  58.     private $id;
  59.     /**
  60.      * @ORM\Column(type="string", length=64)
  61.      * @Groups({"CompanyTag:Read", "CompanyTag:Write", "Company:Read", "Company:Write", "CompanyTag:PRead", "Company:PRead"})
  62.      */
  63.     private $name;
  64.     /**
  65.      * @ORM\ManyToMany(targetEntity=Company::class, inversedBy="companyTags")
  66.      * @Groups({"CompanyTag:Write", "Company:Write"})
  67.      */
  68.     private $companies;
  69.     /**
  70.      * @ORM\ManyToOne(targetEntity=Client::class)
  71.      * @ORM\JoinColumn(nullable=false)
  72.      * @Groups({"CompanyTag:Write"})
  73.      */
  74.     private $client;
  75.     public function __construct()
  76.     {
  77.         $this->companies = new ArrayCollection();
  78.     }
  79.     public function getId(): ?int
  80.     {
  81.         return $this->id;
  82.     }
  83.     public function getName(): ?string
  84.     {
  85.         return $this->name;
  86.     }
  87.     public function setName(string $name): self
  88.     {
  89.         $this->name $name;
  90.         return $this;
  91.     }
  92.     /**
  93.      * @return Collection<int, Company>
  94.      */
  95.     public function getCompanies(): Collection
  96.     {
  97.         return $this->companies;
  98.     }
  99.     public function addCompany(Company $company): self
  100.     {
  101.         if (!$this->companies->contains($company)) {
  102.             $this->companies[] = $company;
  103.         }
  104.         return $this;
  105.     }
  106.     public function removeCompany(Company $company): self
  107.     {
  108.         $this->companies->removeElement($company);
  109.         return $this;
  110.     }
  111.     public function getClient(): ?Client
  112.     {
  113.         return $this->client;
  114.     }
  115.     public function setClient(?Client $client): self
  116.     {
  117.         $this->client $client;
  118.         return $this;
  119.     }
  120. }