src/Domain/Entity/PointOfInterest/OpeningDate.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Entity\PointOfInterest;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use ApiPlatform\Metadata\Link;
  7. use ApiPlatform\Metadata\Post;
  8. use App\Domain\Entity\Behavior\Identifiable;
  9. use Gedmo\Timestampable\Traits\Timestampable;
  10. /**
  11.  * Class OpeningDate
  12.  * @package App\Domain\Entity\PointOfInterest
  13.  */
  14. #[ApiResource(
  15.     operations: [
  16.         new Get(),
  17.         new GetCollection(),
  18.         new Post()
  19.     ],
  20.     normalizationContext: ['groups' => ['opening_date_read']],
  21.     denormalizationContext: ['groups' => ['opening_date_write']]
  22. )]
  23. #[ApiResource(
  24.     uriTemplate'/revisions/{uuid}/opening_dates',
  25.     operations: [
  26.         new GetCollection()
  27.     ],
  28.     uriVariables: [
  29.         'uuid' => new Link(fromProperty'openingDates'fromClassRevision::class)
  30.     ]
  31. )]
  32. class OpeningDate
  33. {
  34.     use Identifiable;
  35.     use Timestampable;
  36.     public function __construct(
  37.         public \DateTime $end,
  38.         public Revision $revision,
  39.         public \DateTime $start,
  40.     ) {}
  41.     public function getFormattedEnd(): string
  42.     {
  43.         return $this->end->format('Y-m-d');
  44.     }
  45.     public function getFormattedStart(): string
  46.     {
  47.         return $this->start->format('Y-m-d');
  48.     }
  49.     /**
  50.      * Renvoie "MM-dd" pour ignorer l’année
  51.      */
  52.     public function getStartMonthDay(): string
  53.     {
  54.         return $this->start->format('m-d');
  55.     }
  56.     /**
  57.      * Renvoie "MM-dd" pour ignorer l’année
  58.      */
  59.     public function getEndMonthDay(): string
  60.     {
  61.         return $this->end->format('m-d');
  62.     }
  63. }