src/Domain/Entity/Award.php line 44

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Domain\Entity;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Post;
  9. use ApiPlatform\Metadata\Put;
  10. use App\Application\Controller\Api\Award\ImportAction;
  11. use App\Domain\Entity\Behavior\Identifiable;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
  15. /**
  16.  * Class CamperVan
  17.  *
  18.  * @package App\Domain\Entity
  19.  */
  20. #[ApiResource(
  21.     operations            : [
  22.         new Get(),
  23.         new GetCollection(filters: ['award.search_filter''soft_delete']),
  24.         new Post(
  25.             uriTemplate'/awards/import',
  26.             controller ImportAction::class,
  27.             security   "is_granted('ROLE_ADMIN')",
  28.             deserializefalse,
  29.             serialize  false,
  30.         ),
  31.         new Post(security"is_granted('ROLE_ADMIN')"),
  32.         new Put(security"is_granted('ROLE_ADMIN')"),
  33.         new Delete(),
  34.     ],
  35.     normalizationContext  : ['groups' => ['award_read']],
  36.     denormalizationContext: ['groups' => ['award_write']],
  37.     filters               : ['award.search_filter'],
  38.     order                 : ['year' => 'DESC']
  39. )]
  40. class Award
  41. {
  42.     use Identifiable;
  43.     use SoftDeleteable;
  44.     /**
  45.      * @var ArrayCollection
  46.      */
  47.     public Collection $pointOfInterests;
  48.     /**
  49.      * @param string $code
  50.      * @param string $year
  51.      * @param Media|null $picture
  52.      */
  53.     public function __construct(
  54.         public string $code,
  55.         public string $year,
  56.         public ?Media $picture null,
  57.     ) {
  58.         $this->pointOfInterests = new ArrayCollection();
  59.     }
  60.     /**
  61.      * @return Collection
  62.      */
  63.     public function getPointOfInterests(): Collection
  64.     {
  65.         return $this->pointOfInterests;
  66.     }
  67.     /**
  68.      * @return int
  69.      */
  70.     public function getPointOfInterestCount(): int
  71.     {
  72.         return $this->pointOfInterests->count();
  73.     }
  74.     /**
  75.      * @param Collection $pointOfInterests
  76.      */
  77.     public function setPointOfInterests(Collection $pointOfInterests): void
  78.     {
  79.         $this->pointOfInterests $pointOfInterests;
  80.     }
  81.     public function addPointOfInterest(PointOfInterest $pointOfInterest): void
  82.     {
  83.         if ($this->pointOfInterests->contains($pointOfInterest)) {
  84.             return;
  85.         }
  86.         $this->pointOfInterests->add($pointOfInterest);
  87.         $pointOfInterest->addAward($this);
  88.     }
  89.     public function removePointOfInterest(PointOfInterest $pointOfInterest): void
  90.     {
  91.         if (!$this->pointOfInterests->contains($pointOfInterest)) {
  92.             return;
  93.         }
  94.         $this->pointOfInterests->removeElement($pointOfInterest);
  95.         $pointOfInterest->removeAward($this);
  96.     }
  97. }