src/Entity/News.php line 33

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\NewsRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use ApiPlatform\Metadata\ApiFilter;
  10. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use ApiPlatform\Metadata\Delete;
  13. use ApiPlatform\Metadata\Get;
  14. use ApiPlatform\Metadata\GetCollection;
  15. use ApiPlatform\Metadata\Post;
  16. use ApiPlatform\Metadata\Put;
  17. #[ORM\Entity(repositoryClassNewsRepository::class)]
  18. #[ApiResource(
  19.     normalizationContext: ['groups' => ['news:read']],
  20.     denormalizationContext: ['groups' => ['news:write']],
  21.     order: ['id' => 'DESC'], paginationClientItemsPerPagetrue,
  22.     // security: "is_granted('ROLE_ADMIN')"
  23.     )
  24. ]
  25. #[Get()]
  26. #[Put(security"is_granted('EDIT_NEWS', object)")]
  27. #[Delete(security"is_granted('EDIT_NEWS', object)")]
  28. #[GetCollection]
  29. #[Post(securityPostDenormalize"is_granted('EDIT_NEWS', object)")]
  30. #[ApiFilter(SearchFilter::class, properties: [
  31.     'categories.id' => 'exact'
  32.     'name' => 'ipartial',
  33.     'language.id' => 'exact'
  34. ])]
  35. class News
  36. {
  37.     #[Groups(['news:read''news:write'])]
  38.     #[ORM\Id]
  39.     #[ORM\GeneratedValue]
  40.     #[ORM\Column]
  41.     private ?int $id null;
  42.     #[Groups(['news:read''news:write'])]
  43.     #[ORM\Column(length255)]
  44.     private ?string $name null;
  45.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  46.     #[Groups(['news:read''news:write'])]
  47.     private ?\DateTimeInterface $date null;
  48.     #[Groups(['news:read''news:write'])]
  49.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  50.     private ?string $newsShot null;
  51.     #[Groups(['news:read''news:write'])]
  52.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  53.     private ?string $newsFull null;
  54.     #[Groups(['news:read''news:write'])]
  55.     #[ORM\Column(length2nullabletrue)]
  56.     private ?string $active null;
  57.     #[Groups(['news:read''news:write'])]
  58.     #[ORM\Column(length2nullabletrue)]
  59.     private ?string $top null;
  60.     #[Groups(['news:read''news:write'])]
  61.     #[ORM\Column(length255nullabletrue)]
  62.     private ?string $audio_link null;
  63.     #[Groups(['news:read''news:write'])]
  64.     #[ORM\Column(length255nullabletrue)]
  65.     private ?string $video_link null;
  66.     #[Groups(['news:read''news:write'])]
  67.     #[ORM\Column(length255nullabletrue)]
  68.     private ?string $audio_title null;
  69.     #[Groups(['news:read''news:write'])]
  70.     #[ORM\Column(length2nullabletrue)]
  71.     private ?string $audio_active null;
  72.     #[Groups(['news:read''news:write'])]
  73.     #[ORM\Column(length255nullabletrue)]
  74.     private ?string $video_img null;
  75.     #[ORM\Column(length255nullabletrue)]
  76.     private ?string $slider null;
  77.     #[ORM\Column(length255nullabletrue)]
  78.     private ?string $dateStart null;
  79.     #[ORM\Column(length255nullabletrue)]
  80.     private ?string $address null;
  81.     #[ORM\Column(length255nullabletrue)]
  82.     private ?string $shortDescription null;
  83.     #[ORM\Column(length255nullabletrue)]
  84.     private ?string $contentImg null;
  85.     #[Groups(['news:read''news:write'])]
  86.     #[ORM\ManyToMany(targetEntityCategory::class, mappedBy'news')]
  87.     private Collection $categories;
  88.     #[Groups(['news:read''news:write'])]
  89.     #[ORM\ManyToOne(inversedBy'news')]
  90.     private ?MediaObject $media null;
  91.     #[Groups(['news:read''news:write'])]
  92.     #[ORM\ManyToOne(inversedBy'news')]
  93.     private ?Languages $language null;
  94.     #[Groups(['news:read''news:write'])]
  95.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'tralations')]
  96.     private ?self $translation null;
  97.     /**
  98.      * @var Collection<int, self>
  99.      */
  100.     #[Groups(['news:read''news:write'])]
  101.     #[ORM\OneToMany(mappedBy'translation'targetEntityself::class)]
  102.     private Collection $tralations
  103.     
  104.     #[Groups(['news:read''news:write'])]
  105.     #[ORM\Column(length255nullabletrue)]
  106.     private ?string $opacityCard null
  107.     public function __construct() 
  108.     {
  109.         $this->categories = new ArrayCollection();
  110.         $this->tralations = new ArrayCollection();
  111.     }
  112.     public function getId(): ?int
  113.     {
  114.         return $this->id;
  115.     }
  116.     public function getName(): ?string
  117.     {
  118.         return $this->name;
  119.     }
  120.     public function setName(string $name): self
  121.     {
  122.         $this->name $name;
  123.         return $this;
  124.     }
  125.     public function getDate(): ?\DateTimeInterface
  126.     {
  127.         return $this->date;
  128.     }
  129.     public function setDate(\DateTimeInterface $date): self
  130.     {
  131.         $this->date $date;
  132.         return $this;
  133.     }
  134.     public function getNewsShot(): ?string
  135.     {
  136.         return $this->newsShot;
  137.     }
  138.     public function setNewsShot(?string $newsShot): self
  139.     {
  140.         $this->newsShot $newsShot;
  141.         return $this;
  142.     }
  143.     public function getNewsFull(): ?string
  144.     {
  145.         return $this->newsFull;
  146.     }
  147.     public function setNewsFull(?string $newsFull): self
  148.     {
  149.         $this->newsFull $newsFull;
  150.         return $this;
  151.     }
  152.     public function getActive(): ?string
  153.     {
  154.         return $this->active;
  155.     }
  156.     public function setActive(string $active): self
  157.     {
  158.         $this->active $active;
  159.         return $this;
  160.     }
  161.     public function getTop(): ?string
  162.     {
  163.         return $this->top;
  164.     }
  165.     public function setTop(?string $top): self
  166.     {
  167.         $this->top $top;
  168.         return $this;
  169.     }
  170.     public function getAudioLink(): ?string
  171.     {
  172.         return $this->audio_link;
  173.     }
  174.     public function setAudioLink(?string $audio_link): self
  175.     {
  176.         $this->audio_link $audio_link;
  177.         return $this;
  178.     }
  179.     public function getVideoLink(): ?string
  180.     {
  181.         return $this->video_link;
  182.     }
  183.     public function setVideoLink(?string $video_link): self
  184.     {
  185.         $this->video_link $video_link;
  186.         return $this;
  187.     }
  188.     public function getAudioTitle(): ?string
  189.     {
  190.         return $this->audio_title;
  191.     }
  192.     public function setAudioTitle(?string $audio_title): self
  193.     {
  194.         $this->audio_title $audio_title;
  195.         return $this;
  196.     }
  197.     public function getAudioActive(): ?string
  198.     {
  199.         return $this->audio_active;
  200.     }
  201.     public function setAudioActive(?string $audio_active): self
  202.     {
  203.         $this->audio_active $audio_active;
  204.         return $this;
  205.     }
  206.     public function getVideoImg(): ?string
  207.     {
  208.         return $this->video_img;
  209.     }
  210.     public function setVideoImg(?string $video_img): self
  211.     {
  212.         $this->video_img $video_img;
  213.         return $this;
  214.     }
  215.     public function getSlider(): ?string
  216.     {
  217.         return $this->slider;
  218.     }
  219.     public function setSlider(?string $slider): static
  220.     {
  221.         $this->slider $slider;
  222.         
  223.         return $this;
  224.     }
  225.     /**
  226.      * @return Collection<int, Category>
  227.      */
  228.     public function getCategories(): Collection
  229.     {
  230.         return $this->categories;
  231.     }
  232.     public function addCategory(Category $category): static
  233.     {
  234.         if (!$this->categories->contains($category)) {
  235.             $this->categories->add($category);
  236.             $category->addNews($this);
  237.         }
  238.         return $this;
  239.     }
  240.     public function getDateStart(): ?string
  241.     {
  242.         return $this->dateStart;
  243.     }
  244.     public function setDateStart(?string $dateStart): static
  245.     {
  246.         $this->dateStart $dateStart;
  247.         return $this;
  248.     }
  249.     public function getAddress(): ?string
  250.     {
  251.         return $this->address;
  252.     }
  253.     public function setAddress(?string $address): static
  254.     {
  255.         $this->address $address;
  256.         return $this;
  257.     }
  258.     public function getShortDescription(): ?string
  259.     {
  260.         return $this->shortDescription;
  261.     }
  262.     public function setShortDescription(?string $shortDescription): static
  263.     {
  264.         $this->shortDescription $shortDescription;
  265.         return $this;
  266.     }
  267.     public function getContentImg(): ?string
  268.     {
  269.         return $this->contentImg;
  270.     }
  271.     public function setContentImg(?string $contentImg): static
  272.     {
  273.         $this->contentImg $contentImg;
  274.         
  275.         return $this;
  276.     }
  277.     public function removeCategory(Category $category): static
  278.     {
  279.         if ($this->categories->removeElement($category)) {
  280.             $category->removeNews($this);
  281.         }
  282.         return $this;
  283.     }
  284.     public function getMedia(): ?MediaObject
  285.     {
  286.         return $this->media;
  287.     }
  288.     public function setMedia(?MediaObject $media): static
  289.     {
  290.         $this->media $media;
  291.         return $this;
  292.     }
  293.     public function getLanguage(): ?Languages
  294.     {
  295.         return $this->language;
  296.     }
  297.     public function setLanguage(?Languages $language): static
  298.     {
  299.         $this->language $language;
  300.         return $this;
  301.     }
  302.     public function getTranslation(): ?self
  303.     {
  304.         return $this->translation;
  305.     }
  306.     public function setTranslation(?self $translation): static
  307.     {
  308.         $this->translation $translation;
  309.         return $this;
  310.     }
  311.     /**
  312.      * @return Collection<int, self>
  313.      */
  314.     public function getTralations(): Collection
  315.     {
  316.         return $this->tralations;
  317.     }
  318.     public function addTralation(self $tralation): static
  319.     {
  320.         if (!$this->tralations->contains($tralation)) {
  321.             $this->tralations->add($tralation);
  322.             $tralation->setTranslation($this);
  323.         }
  324.         return $this;
  325.     }
  326.     public function removeTralation(self $tralation): static
  327.     {
  328.         if ($this->tralations->removeElement($tralation)) {
  329.             // set the owning side to null (unless already changed)
  330.             if ($tralation->getTranslation() === $this) {
  331.                 $tralation->setTranslation(null);
  332.             }
  333.         }
  334.         return $this;
  335.     }
  336.     
  337.     public function getOpacityCard(): ?string
  338.     {
  339.         return $this->opacityCard;
  340.     }
  341.     public function setOpacityCard(?string $opacityCard): static
  342.     {
  343.         $this->opacityCard $opacityCard;
  344.         return $this;
  345.     }
  346. }