src/Entity/DayEvent.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Repository\DayEventRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity(repositoryClass=DayEventRepository::class)
  12.  * @ORM\HasLifecycleCallbacks()
  13.  * @ApiResource(
  14.  *     denormalizationContext={"groups"={"day_event:write"}},
  15.  *     collectionOperations={
  16.  *          "post_day_event"={
  17.  *              "method"="POST",
  18.  *              "path"="/day_events",
  19.  *              "controller"="App\Controller\Api\DayEventController::post",
  20.  *              "security"="is_granted('ROLE_USER')",
  21.  *              "openapi_context"={
  22.  *                  "summary"="Creates a new DayEvent resource",
  23.  *                  "description"="Creation of a new DayEvent resource with tvUser auto fill"
  24.  *              }
  25.  *          }},
  26.  *     itemOperations={
  27.  *          "get" = {
  28.  *              "security"="is_granted('ROLE_ADMIN')"
  29.  *          }
  30.  *      }
  31.  * )
  32.  */
  33. class DayEvent
  34. {
  35.     const DAY_END 'day_end';
  36.     const DAY_REDO 'day_redo';
  37.     const TYPES = [
  38.       self::DAY_END,
  39.       self::DAY_REDO,
  40.     ];
  41.     /**
  42.      * @ORM\Id
  43.      * @ORM\GeneratedValue
  44.      * @ORM\Column(type="integer", options={"comment":"Clé primaire"})
  45.      */
  46.     private $id;
  47.     /**
  48.      * @ORM\ManyToOne(targetEntity=Day::class, inversedBy="dayEvents")
  49.      * @ORM\JoinColumn(nullable=false)
  50.      * @Groups({"day_event:write"})
  51.      */
  52.     private $day;
  53.     /**
  54.      * @ORM\ManyToOne(targetEntity=TvUser::class, inversedBy="dayEvents")
  55.      * @ORM\JoinColumn(nullable=true)
  56.      */
  57.     private $tvUser;
  58.     /**
  59.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="dayEvents")
  60.      * @ORM\JoinColumn(nullable=true)
  61.      * @Assert\NotNull
  62.      */
  63.     private $user;
  64.     /**
  65.      * @ORM\Column(type="datetime", options={"comment":"Date et heure de l'évènement"})
  66.      * @Gedmo\Timestampable(on="create")
  67.      */
  68.     private $createdAt;
  69.     /**
  70.      * @ORM\Column(type="string", length=255, options={"comment":"Type d'evenenment donné (ex: début de journée, fin de journée, ...)"})
  71.      * @Groups({"day_event:write"})
  72.      * @Assert\Choice(choices=self::TYPES, message="day_event.types")
  73.      * @ApiProperty(
  74.      *     attributes={
  75.      *         "openapi_context"={"type"="string", "enum"=self::TYPES, "example"="day_end|day_redo"}
  76.      *     }
  77.      * )
  78.      */
  79.     private $type;
  80.     public function getId(): ?int
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function getDay(): ?Day
  85.     {
  86.         return $this->day;
  87.     }
  88.     public function setDay(?Day $day): self
  89.     {
  90.         $this->day $day;
  91.         return $this;
  92.     }
  93.     public function getTvUser(): ?TvUser
  94.     {
  95.         return $this->tvUser;
  96.     }
  97.     public function setTvUser(?TvUser $tvUser): self
  98.     {
  99.         $this->tvUser $tvUser;
  100.         return $this;
  101.     }
  102.     public function getUser(): ?User
  103.     {
  104.         return $this->user;
  105.     }
  106.     public function setUser(?User $user): self
  107.     {
  108.         $this->user $user;
  109.         return $this;
  110.     }
  111.     public function getCreatedAt(): ?\DateTimeInterface
  112.     {
  113.         return $this->createdAt;
  114.     }
  115.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  116.     {
  117.         $this->createdAt $createdAt;
  118.         return $this;
  119.     }
  120.     public function getType(): ?string
  121.     {
  122.         return $this->type;
  123.     }
  124.     public function setType(string $type): self
  125.     {
  126.         $this->type $type;
  127.         return $this;
  128.     }
  129.     public static function getImplodedTypes(): string
  130.     {
  131.         return implode('|'self::TYPES);
  132.     }
  133. }