src/Entity/ProgramEvent.php line 33

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\ProgramEventRepository;
  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=ProgramEventRepository::class)
  12.  * @ORM\HasLifecycleCallbacks()
  13.  * @ApiResource(
  14.  *      denormalizationContext={"groups"={"program_event:read", "program_event:write"}},
  15.  *      collectionOperations={
  16.  *          "post"={
  17.  *              "security"="is_granted('ROLE_USER')"
  18.  *          },
  19.  *          "get"={
  20.  *              "security"="is_granted('ROLE_USER')"
  21.  *          }
  22.  *      },
  23.  *      itemOperations={
  24.  *          "get"={
  25.  *              "security"="is_granted('ROLE_USER')"
  26.  *          }
  27.  *      }
  28.  * )
  29.  */
  30. class ProgramEvent
  31. {
  32.     const PROGRAM_START 'program_start';
  33.     const PROGRAM_END 'program_end';
  34.     const PROGRAM_REDO 'program_redo';
  35.     const TYPES = [
  36.         self::PROGRAM_START,
  37.         self::PROGRAM_END,
  38.         self::PROGRAM_REDO,
  39.     ];
  40.     /**
  41.      * @ORM\Id
  42.      * @ORM\GeneratedValue
  43.      * @ORM\Column(type="integer")
  44.      * @Groups({"program_event:read"})
  45.      */
  46.     private $id;
  47.     /**
  48.      * @ORM\ManyToOne(targetEntity=Program::class, inversedBy="programEvents")
  49.      * @ORM\JoinColumn(nullable=true)
  50.      * @Groups({"program_event:read", "day_event:write"})
  51.      */
  52.     private $program;
  53.     /**
  54.      * @ORM\ManyToOne(targetEntity=Channel::class, inversedBy="programEvents")
  55.      * @ORM\JoinColumn(nullable=true)
  56.      * @Groups({"program_event:read", "day_event:write"})
  57.      */
  58.     private $channel;
  59.     /**
  60.      * @ORM\ManyToOne(targetEntity=TvUser::class, inversedBy="programEvents")
  61.      * @ORM\JoinColumn(nullable=true)
  62.      * @Groups({"program_event:read", "day_event:write"})
  63.      */
  64.     private $tvUser;
  65.     /**
  66.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="programEvents")
  67.      * @ORM\JoinColumn(nullable=true)
  68.      * @Assert\NotNull
  69.      * @Groups({"program_event:read", "day_event:write"})
  70.      */
  71.     private $user;
  72.     /**
  73.      * @ORM\Column(type="string", length=255)
  74.      * @Groups({"program_event:read", "day_event:write"})
  75.      * @Assert\Choice(choices=self::TYPES, message="program_event.types")
  76.      * @ApiProperty(
  77.      *     attributes={
  78.      *         "openapi_context"={"type"="string", "enum"=self::TYPES, "example"="program_start|program_end|program_redo"}
  79.      *     }
  80.      * )
  81.      */
  82.     private $type;
  83.     /**
  84.      * @ORM\Column(type="datetime")
  85.      * @Gedmo\Timestampable(on="create")
  86.      * @Groups({"program_event:read"})
  87.      */
  88.     private $createdAt;
  89.     public function getId(): ?int
  90.     {
  91.         return $this->id;
  92.     }
  93.     public function getProgram(): ?Program
  94.     {
  95.         return $this->program;
  96.     }
  97.     public function setProgram(?Program $program): self
  98.     {
  99.         $this->program $program;
  100.         return $this;
  101.     }
  102.     public function getChannel(): ?Channel
  103.     {
  104.         return $this->channel;
  105.     }
  106.     public function setChannel(?Channel $channel): self
  107.     {
  108.         $this->channel $channel;
  109.         return $this;
  110.     }
  111.     public function getTvUser(): ?TvUser
  112.     {
  113.         return $this->tvUser;
  114.     }
  115.     public function setTvUser(?TvUser $tvUser): self
  116.     {
  117.         $this->tvUser $tvUser;
  118.         return $this;
  119.     }
  120.     public function getUser(): ?User
  121.     {
  122.         return $this->user;
  123.     }
  124.     public function setUser(?User $user): self
  125.     {
  126.         $this->user $user;
  127.         return $this;
  128.     }
  129.     public function getType(): ?string
  130.     {
  131.         return $this->type;
  132.     }
  133.     public function setType(string $type): self
  134.     {
  135.         $this->type $type;
  136.         return $this;
  137.     }
  138.     public function getCreatedAt(): ?\DateTimeInterface
  139.     {
  140.         return $this->createdAt;
  141.     }
  142.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  143.     {
  144.         $this->createdAt $createdAt;
  145.         return $this;
  146.     }
  147.     public static function getImplodedTypes(): string
  148.     {
  149.         return implode('|'self::TYPES);
  150.     }
  151. }