src/Entity/Page.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. use Gedmo\Timestampable\Traits\TimestampableEntity;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. /**
  16.  * @ORM\Entity(repositoryClass="App\Repository\PageRepository")
  17.  * @ORM\HasLifecycleCallbacks()
  18.  */
  19. #[ApiResource(
  20.     collectionOperations: ['get''post' => ['security' => "is_granted('ROLE_ADMIN')"]],
  21.     itemOperations: ['get''put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"], 'delete' => ['security' => "is_granted('ROLE_ADMIN')"]],
  22. )]
  23. #[ApiFilter(PropertyFilter::class)]
  24. #[ApiFilter(OrderFilter::class, properties: ['id''pageTitle''isActive',  'createdAt'], arguments: ['orderParameterName' => 'order'])]
  25. class Page
  26. {
  27.     use TimestampableEntity;
  28.     /**
  29.      * @ORM\Id()
  30.      * @ORM\GeneratedValue()
  31.      * @ORM\Column(type="integer")
  32.      */
  33.     private $id;
  34.     /**
  35.      * @Groups({"data"})
  36.      * @ORM\Column(type="text", nullable=true)
  37.      */
  38.     #[ApiFilter(SearchFilter::class, strategySearchFilter::STRATEGY_PARTIAL)]
  39.     protected $pageTitle;
  40.     /**
  41.      * @Groups({"data"})
  42.      * @ORM\Column(type="string", length=255)
  43.      * @Gedmo\Slug(fields={"pageTitle"})
  44.      */
  45.     #[ApiFilter(SearchFilter::class, strategySearchFilter::STRATEGY_EXACT)]
  46.     private $slug;
  47.     /**
  48.      * @Groups({"data"})
  49.      * @ORM\OneToMany(targetEntity="App\Entity\PageSection", cascade={"persist"}, mappedBy="page", orphanRemoval=true)
  50.      * @ORM\OrderBy({"position" = "ASC"})
  51.      * @Assert\Valid()
  52.      */
  53.     private $pageSections;
  54.     public function __construct()
  55.     {
  56.         $this->pageSections = new ArrayCollection();
  57.     }
  58.     public function getId(): ?int
  59.     {
  60.         return $this->id;
  61.     }
  62.     /**
  63.      * @return Collection|PageSection[]
  64.      */
  65.     public function getPageSections(): Collection
  66.     {
  67.         return $this->pageSections;
  68.     }
  69.     public function addPageSection(PageSection $pageSection): self
  70.     {
  71.         if (!$this->pageSections->contains($pageSection)) {
  72.             $this->pageSections[] = $pageSection;
  73.             $pageSection->setPage($this);
  74.         }
  75.         return $this;
  76.     }
  77.     public function removePageSection(PageSection $pageSection): self
  78.     {
  79.         if ($this->pageSections->contains($pageSection)) {
  80.             $this->pageSections->removeElement($pageSection);
  81.             // set the owning side to null (unless already changed)
  82.             if ($pageSection->getPage() === $this) {
  83.                 $pageSection->setPage(null);
  84.             }
  85.         }
  86.         return $this;
  87.     }
  88.     public function getPageTitle(): ?string
  89.     {
  90.         return $this->pageTitle;
  91.     }
  92.     public function setPageTitle(?string $pageTitle): self
  93.     {
  94.         $this->pageTitle $pageTitle;
  95.         return $this;
  96.     }
  97.     public function getSlug(): ?string
  98.     {
  99.         return $this->slug;
  100.     }
  101.     public function setSlug(string $slug): self
  102.     {
  103.         $this->slug $slug;
  104.         return $this;
  105.     }
  106. }