src/Entity/Article.php line 61

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ArticleRepository;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use ApiPlatform\Core\Annotation\ApiProperty;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  9. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  11. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Gedmo\Mapping\Annotation as Gedmo;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  19. /**
  20.  * @ORM\Entity(repositoryClass=ArticleRepository::class)
  21.  * @ApiResource(
  22.  *      normalizationContext={
  23.  *          "groups"={"article:read"}
  24.  *      },
  25.  *      denormalizationContext={
  26.  *          "groups"={"article:write"}
  27.  *      },
  28.  *      itemOperations={
  29.  *         "get"={
  30.  *              "security"="is_granted('ROLE_USER')"
  31.  *          }
  32.  *      },
  33.  *      collectionOperations={
  34.  *          "get"={
  35.  *              "security"="is_granted('ROLE_USER')"
  36.  *          }
  37.  *      }
  38.  * )
  39.  * @ApiFilter(OrderFilter::class, 
  40.  *      properties={
  41.  *          "id", "title", "categoryName", 
  42.  *          "homepage", "active", 
  43.  *          "startAt", "endAt", 
  44.  *          "createdAt", "updatedAt"
  45.  *      }
  46.  * )
  47.  * @ApiFilter(BooleanFilter::class)
  48.  * @ApiFilter(DateFilter::class)
  49.  * @ApiFilter(SearchFilter::class)
  50.  * @ApiFilter(PropertyFilter::class, 
  51.  *      arguments={
  52.  *          "parameterName"="fields", 
  53.  *          "overrideDefaultProperties"=true
  54.  *     }
  55.  * )
  56.  * @Vich\Uploadable
  57.  */
  58. class Article
  59. {
  60.     /**
  61.      * @ORM\Id
  62.      * @ORM\GeneratedValue
  63.      * @ORM\Column(type="integer")
  64.      * @ApiProperty(identifier=true)
  65.      * @Groups({"article:read", "article:read:id"})
  66.      */
  67.     private $id null;
  68.     /**
  69.      * @ORM\Column(type="string", length=255, nullable=true)
  70.      * @Groups({"article:read", "article:read:title", "article:write"})
  71.      * @Assert\NotBlank
  72.      */
  73.     private $title;
  74.     /**
  75.      * @ORM\Column(type="string", length=255, nullable=true)
  76.      * @Groups({"article:read", "article:read:categoryName", "article:write"})
  77.      */
  78.     private $categoryName;
  79.     /**
  80.      * @ORM\Column(type="string", length=255, nullable=true)
  81.      * @Groups({"article:read", "article:read:shortDescription", "article:write"})
  82.      * @Assert\NotBlank
  83.      */
  84.     private $shortDescription;
  85.     /**
  86.      * @ORM\Column(type="text", nullable=true)
  87.      * @Groups({"article:read", "article:read:description", "article:write"})
  88.      * @Assert\NotBlank
  89.      */
  90.     private $description;
  91.     /**
  92.      * @ORM\ManyToOne(targetEntity=MediaObject::class, cascade={"persist", "refresh", "remove"})
  93.      * @Groups({"article:read", "article:write", "article:read:smallPicture"})
  94.      */
  95.     private $smallPicture;
  96.     /**
  97.      * @ORM\ManyToOne(targetEntity=MediaObject::class, cascade={"persist", "refresh", "remove"})
  98.      * @Groups({"article:read", "article:write", "article:read:picture"})
  99.      */
  100.     private $picture;
  101.     /**
  102.      * @ORM\ManyToOne(targetEntity=MediaObject::class, cascade={"persist", "refresh", "remove"})
  103.      * @Groups({"article:read", "article:write", "article:read:largePicture"})
  104.      */
  105.     private $largePicture;
  106.     /**
  107.      * @ORM\Column(type="datetime", nullable=true)
  108.      * @Groups({"article:read", "article:write", "article:read:startAt"})
  109.      */
  110.     private $startAt;
  111.     /**
  112.      * @ORM\Column(type="datetime", nullable=true)
  113.      * @Groups({"article:read", "article:write", "article:read:endAt"})
  114.      */
  115.     private $endAt;
  116.     /**
  117.      * @ORM\Column(type="boolean", options={"default": "1"})
  118.      * @Groups({"article:read", "article:read:homepage", "article:write"})
  119.      */
  120.     private $homepage false;
  121.     /**
  122.      * @ORM\Column(type="boolean", options={"default": "1"})
  123.      * @Groups({"article:read", "article:read:active", "article:write"})
  124.      */
  125.     private $active true;
  126.     /**
  127.      * @ORM\Column(type="datetime")
  128.      * @Gedmo\Timestampable(on="create")
  129.      * @Groups({"article:read", "article:read:createdAt"})
  130.      */
  131.     private $createdAt;
  132.     /**
  133.      * @ORM\Column(type="datetime")
  134.      * @Gedmo\Timestampable(on="update")
  135.      * @Groups({"article:read", "article:read:updatedAt"})
  136.      */
  137.     private $updatedAt;
  138.     public function getId(): ?int
  139.     {
  140.         return $this->id;
  141.     }
  142.     public function getTitle(): ?string
  143.     {
  144.         return $this->title;
  145.     }
  146.     public function setTitle(string $title): self
  147.     {
  148.         $this->title $title;
  149.         return $this;
  150.     }
  151.     public function getCategoryName(): ?string
  152.     {
  153.         return $this->categoryName;
  154.     }
  155.     public function setCategoryName(string $categoryName): self
  156.     {
  157.         $this->categoryName $categoryName;
  158.         return $this;
  159.     }
  160.     public function getShortDescription(): ?string
  161.     {
  162.         return $this->shortDescription;
  163.     }
  164.     public function setShortDescription(string $shortDescription): self
  165.     {
  166.         $this->shortDescription $shortDescription;
  167.         return $this;
  168.     }
  169.     public function getDescription(): ?string
  170.     {
  171.         return $this->description;
  172.     }
  173.     public function setDescription(string $description): self
  174.     {
  175.         $this->description $description;
  176.         return $this;
  177.     }
  178.     public function getSmallPicture(): ?MediaObject
  179.     {
  180.         return $this->smallPicture;
  181.     }
  182.     public function setSmallPicture(?MediaObject $smallPicture): self
  183.     {
  184.         $this->smallPicture $smallPicture;
  185.         return $this;
  186.     }
  187.     public function getPicture(): ?MediaObject
  188.     {
  189.         return $this->picture;
  190.     }
  191.     public function setPicture(?MediaObject $picture): self
  192.     {
  193.         $this->picture $picture;
  194.         return $this;
  195.     }
  196.     public function getLargePicture(): ?MediaObject
  197.     {
  198.         return $this->largePicture;
  199.     }
  200.     public function setLargePicture(?MediaObject $largePicture): self
  201.     {
  202.         $this->largePicture $largePicture;
  203.         return $this;
  204.     }
  205.     public function getStartAt(): ?\DateTime
  206.     {
  207.         return $this->startAt;
  208.     }
  209.     public function setStartAt(\DateTime $startAt): self
  210.     {
  211.         $this->startAt $startAt;
  212.         return $this;
  213.     }
  214.     public function getEndAt(): ?\DateTime
  215.     {
  216.         return $this->endAt;
  217.     }
  218.     public function setEndAt(\DateTime $endAt): self
  219.     {
  220.         $this->endAt $endAt;
  221.         return $this;
  222.     }
  223.     public function getHomepage(): ?bool
  224.     {
  225.         return $this->homepage;
  226.     }
  227.     public function isHomepage(): ?bool
  228.     {
  229.         return $this->getHomepage();
  230.     }
  231.     public function setHomepage(bool $homepage): self
  232.     {
  233.         $this->homepage $homepage;
  234.         return $this;
  235.     }
  236.     public function getActive(): ?bool
  237.     {
  238.         return $this->active;
  239.     }
  240.     public function isActive(): ?bool
  241.     {
  242.         return $this->getActive();
  243.     }
  244.     public function setActive(bool $active): self
  245.     {
  246.         $this->active $active;
  247.         return $this;
  248.     }
  249.     public function getCreatedAt(): ?\DateTime
  250.     {
  251.         return $this->createdAt;
  252.     }
  253.     public function setCreatedAt(\DateTime $createdAt): self
  254.     {
  255.         $this->createdAt $createdAt;
  256.         return $this;
  257.     }
  258.     public function getUpdatedAt(): ?\DateTime
  259.     {
  260.         return $this->updatedAt;
  261.     }
  262.     public function setUpdatedAt(\DateTime $updatedAt): self
  263.     {
  264.         $this->updatedAt $updatedAt;
  265.         return $this;
  266.     }
  267. }