src/Entity/CompanyFormPage.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\CompanyFormPageRepository")
  12.  */
  13. #[ApiResource(
  14.     attributes: ['security' => "is_granted('ROLE_USER')"],
  15.     normalizationContext: ['groups' => ['companyForm:read']],
  16.     denormalizationContext: ['groups' => ['companyForm:write']],
  17.     collectionOperations: [
  18.         'get',
  19.         'post' => [
  20.             'security' => "is_granted('ROLE_ADMIN')",
  21.         ],
  22.     ],
  23.     itemOperations: [
  24.         'get',
  25.         'put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"],
  26.     ],
  27. )]
  28. class CompanyFormPage
  29. {
  30.     /**
  31.      * @ORM\Id()
  32.      * @ORM\GeneratedValue()
  33.      * @ORM\Column(type="integer")
  34.      */
  35.     private $id;
  36.     /**
  37.      * @var string
  38.      *
  39.      * @ORM\Column(type="string", length=128)
  40.      * @Assert\Length(max="128")
  41.      * @Assert\NotBlank()
  42.      * @Groups({"companyForm:read", "companyForm:write"})
  43.      */
  44.     private $label;
  45.     /**
  46.      * @var string
  47.      *
  48.      * @ORM\Column(type="string", length=128)
  49.      * @Gedmo\Slug(fields={"label"})
  50.      * @Groups({"companyForm:read", "companyForm:write"})
  51.      */
  52.     private $slug;
  53.     /**
  54.      * @var int
  55.      *
  56.      * @ORM\Column(type="integer")
  57.      * @Assert\NotBlank()
  58.      * @Assert\Type(type="integer")
  59.      * @Groups({"companyForm:read", "companyForm:write"})
  60.      */
  61.     private $position;
  62.     /**
  63.      * @var ArrayCollection
  64.      *
  65.      * @ORM\OneToMany(targetEntity="App\Entity\CompanyFormGroup", mappedBy="formPage", cascade={"persist"})
  66.      */
  67.     private $formGroups;
  68.     /**
  69.      * @ORM\Column(type="boolean")
  70.      * @Assert\Type("bool")
  71.      */
  72.     private $subscriptionRequired;
  73.     /**
  74.      * CompanyFormPage constructor.
  75.      *
  76.      * @throws \Exception
  77.      */
  78.     public function __construct()
  79.     {
  80.         $this->subscriptionRequired false;
  81.         $this->formGroups = new ArrayCollection();
  82.     }
  83.     public function getId(): ?int
  84.     {
  85.         return $this->id;
  86.     }
  87.     public function getLabel(): ?string
  88.     {
  89.         return $this->label;
  90.     }
  91.     public function setLabel(string $label): self
  92.     {
  93.         $this->label $label;
  94.         return $this;
  95.     }
  96.     public function getSlug(): ?string
  97.     {
  98.         return $this->slug;
  99.     }
  100.     public function setSlug(string $slug): self
  101.     {
  102.         $this->slug $slug;
  103.         return $this;
  104.     }
  105.     public function getPosition(): ?int
  106.     {
  107.         return $this->position;
  108.     }
  109.     public function setPosition(int $position): self
  110.     {
  111.         $this->position $position;
  112.         return $this;
  113.     }
  114.     /**
  115.      * @return Collection|CompanyFormGroup[]
  116.      */
  117.     public function getFormGroups(): Collection
  118.     {
  119.         return $this->formGroups;
  120.     }
  121.     public function addFormGroup(CompanyFormGroup $formGroup): self
  122.     {
  123.         if (!$this->formGroups->contains($formGroup)) {
  124.             $this->formGroups[] = $formGroup;
  125.             $formGroup->setFormPage($this);
  126.         }
  127.         return $this;
  128.     }
  129.     public function removeFormGroup(CompanyFormGroup $formGroup): self
  130.     {
  131.         if ($this->formGroups->contains($formGroup)) {
  132.             $this->formGroups->removeElement($formGroup);
  133.             // set the owning side to null (unless already changed)
  134.             if ($formGroup->getFormPage() === $this) {
  135.                 $formGroup->setFormPage(null);
  136.             }
  137.         }
  138.         return $this;
  139.     }
  140.     public function getSubscriptionRequired(): ?bool
  141.     {
  142.         return $this->subscriptionRequired;
  143.     }
  144.     public function setSubscriptionRequired(bool $subscriptionRequired): self
  145.     {
  146.         $this->subscriptionRequired $subscriptionRequired;
  147.         return $this;
  148.     }
  149. }