src/Entity/CompanyProduct.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Annotation\EsUploadable;
  4. use Doctrine\ORM\Mapping as ORM;
  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\Repository\CompanyProductRepository;
  10. use App\Entity\Interfaces\ClientMappedInterface;
  11. use App\Entity\Interfaces\UploadMappedInterface;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  16. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  17. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  18. use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
  19. use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
  20. /**
  21.  * @ApiResource(
  22.  *      attributes={"filters"={"translation.groups"}},
  23.  *      normalizationContext={"groups"={"CompanyProduct:Read"}, "skip_null_values"=false},
  24.  *      denormalizationContext={"groups"={"CompanyProduct:Write", "CompanyProductTranslationsGroup"}},
  25.  *      collectionOperations={
  26.  *          "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
  27.  *          "post"={"security"="is_granted('ROLE_ADMIN')"}
  28.  *      },
  29.  *      itemOperations={
  30.  *          "get"={"security"="is_granted('ROLE_SUPER_ADMIN') || is_granted('IS_CLIENT_OWNER_COMPANY_SPE_PRODUCT', object)"},
  31.  *          "put"={"security"="is_granted('ROLE_SUPER_ADMIN') || is_granted('IS_CLIENT_OWNER_COMPANY_SPE_PRODUCT', object)"},
  32.  *          "patch"={"security"="is_granted('ROLE_SUPER_ADMIN') || is_granted('IS_CLIENT_OWNER_COMPANY_SPE_PRODUCT', object)"},
  33.  *          "delete"={"security"="is_granted('ROLE_SUPER_ADMIN') || is_granted('IS_CLIENT_OWNER_COMPANY_SPE_PRODUCT', object)"}
  34.  *     }
  35.  * )
  36.  * @ApiFilter(SearchFilter::class, properties={"id": "exact", "container.id": "exact", "company.id": "exact", "translations.name": "partial", "companyProductTags.id": "exact", "companyProductTags.name": "partial"})
  37.  * @ApiFilter(BooleanFilter::class, properties={"isActive"})
  38.  * @ApiFilter(OrderFilter::class, properties={"translations.name": "DESC"})
  39.  * @ORM\Entity(repositoryClass=CompanyProductRepository::class)
  40.  */
  41. class CompanyProduct extends AbstractTranslatable implements ClientMappedInterfaceUploadMappedInterface
  42. {
  43.     /**
  44.      * Hook timestampable behavior
  45.      * updates createdAt, updatedAt fields
  46.      */
  47.     use TimestampableEntity;
  48.     /**
  49.      * @ORM\OneToMany(targetEntity="CompanyProductTranslation", mappedBy="translatable", fetch="EXTRA_LAZY", indexBy="locale", cascade={"PERSIST"}, orphanRemoval=true)
  50.      *
  51.      * @Groups({"CompanyProduct:Write", "CompanyProductTranslationsGroup"})
  52.      * @Assert\Valid()
  53.      */
  54.     protected $translations;
  55.     /**
  56.      * @Groups({"CompanyProduct:Read"})
  57.      */
  58.     private $name;
  59.     /**
  60.      * @Groups({"CompanyProduct:Read"})
  61.      */
  62.     private $description;
  63.     /**
  64.      * @Groups({"CompanyProduct:Read"})
  65.      */
  66.     private $ctaLabel;
  67.     /**
  68.      * @ORM\Id
  69.      * @ORM\GeneratedValue
  70.      * @ORM\Column(type="integer")
  71.      * @Groups({"CompanyProduct:Read"})
  72.      */
  73.     private $id;
  74.     /**
  75.      * @ORM\Column(type="string", length=255, nullable=true)
  76.      * @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
  77.      * @EsUploadable()
  78.      */
  79.     protected $imageName;
  80.     /**
  81.      * @ORM\Column(type="boolean", nullable=true)
  82.      * @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
  83.      */
  84.     private $isActive;
  85.     /**
  86.      * @ORM\Column(type="boolean", nullable=true)
  87.      * @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
  88.      */
  89.     private $isCta;
  90.     /**
  91.      * @ORM\Column(type="string", length=255, nullable=true)
  92.      * @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
  93.      */
  94.     private $ctaUrl;
  95.     /**
  96.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  97.      * @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
  98.      */
  99.     private $price;
  100.     /**
  101.      * @ORM\ManyToOne(targetEntity=Client::class)
  102.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  103.      *
  104.      * @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
  105.      */
  106.     private $client;
  107.     /**
  108.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="companyProducts")
  109.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  110.      *
  111.      * @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
  112.      */
  113.     private $company;
  114.     /**
  115.      * @ORM\ManyToMany(targetEntity=CompanyProductTag::class, inversedBy="companyProducts", cascade={"persist"})
  116.      *
  117.      * @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
  118.      */
  119.     private $companyProductTags;
  120.     public function __construct()
  121.     {
  122.         parent::__construct();
  123.         $this->companyProductTags = new ArrayCollection();
  124.     }
  125.     protected function createTranslation(): TranslationInterface
  126.     {
  127.         return new CompanyProductTranslation();
  128.     }
  129.     public function getName(): ?string
  130.     {
  131.         return $this->getTranslation()->getName();
  132.     }
  133.     public function setName(string $name): self
  134.     {
  135.         $this->getTranslation()->setName($name);
  136.         return $this;
  137.     }
  138.     public function getDescription(): ?string
  139.     {
  140.         return $this->getTranslation()->getDescription();
  141.     }
  142.     public function setDescription(string $description): self
  143.     {
  144.         $this->getTranslation()->setDescription($description);
  145.         return $this;
  146.     }
  147.     public function getCtaLabel(): ?string
  148.     {
  149.         return $this->getTranslation()->getCtaLabel();
  150.     }
  151.     public function setCtaLabel(string $ctaLabel): self
  152.     {
  153.         $this->getTranslation()->setCtaLabel($ctaLabel);
  154.         return $this;
  155.     }
  156.     public function getId(): ?int
  157.     {
  158.         return $this->id;
  159.     }
  160.     public function getImageName(): ?string
  161.     {
  162.         return $this->imageName;
  163.     }
  164.     public function setImageName(?string $imageName): self
  165.     {
  166.         $this->imageName $imageName;
  167.         return $this;
  168.     }
  169.     public function getIsActive(): ?bool
  170.     {
  171.         return $this->isActive;
  172.     }
  173.     public function setIsActive(?bool $isActive): self
  174.     {
  175.         $this->isActive $isActive;
  176.         return $this;
  177.     }
  178.     public function getIsCta(): ?bool
  179.     {
  180.         return $this->isCta;
  181.     }
  182.     public function setIsCta(?bool $isCta): self
  183.     {
  184.         $this->isCta $isCta;
  185.         return $this;
  186.     }
  187.     public function getCtaUrl(): ?string
  188.     {
  189.         return $this->ctaUrl;
  190.     }
  191.     public function setCtaUrl(?string $ctaUrl): self
  192.     {
  193.         $this->ctaUrl $ctaUrl;
  194.         return $this;
  195.     }
  196.     public function getPrice(): ?string
  197.     {
  198.         return $this->price;
  199.     }
  200.     public function setPrice(?string $price): self
  201.     {
  202.         $this->price $price;
  203.         return $this;
  204.     }
  205.     public function getClient(): ?Client
  206.     {
  207.         return $this->client;
  208.     }
  209.     public function setClient(?Client $client): self
  210.     {
  211.         $this->client $client;
  212.         return $this;
  213.     }
  214.     public function getCompany(): ?Company
  215.     {
  216.         return $this->company;
  217.     }
  218.     public function setCompany(?Company $company): self
  219.     {
  220.         $this->company $company;
  221.         return $this;
  222.     }
  223.     /**
  224.      * @return Collection|CompanyProductTag[]
  225.      */
  226.     public function getCompanyProductTags(): Collection
  227.     {
  228.         return $this->companyProductTags;
  229.     }
  230.     public function addCompanyProductTag(CompanyProductTag $companyProductTag): self
  231.     {
  232.         if (!$this->companyProductTags->contains($companyProductTag)) {
  233.             $this->companyProductTags[] = $companyProductTag;
  234.         }
  235.         return $this;
  236.     }
  237.     public function removeCompanyProductTag(CompanyProductTag $companyProductTag): self
  238.     {
  239.         $this->companyProductTags->removeElement($companyProductTag);
  240.         return $this;
  241.     }
  242. }