<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\ProgramEventRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=ProgramEventRepository::class)
* @ORM\HasLifecycleCallbacks()
* @ApiResource(
* denormalizationContext={"groups"={"program_event:read", "program_event:write"}},
* collectionOperations={
* "post"={
* "security"="is_granted('ROLE_USER')"
* },
* "get"={
* "security"="is_granted('ROLE_USER')"
* }
* },
* itemOperations={
* "get"={
* "security"="is_granted('ROLE_USER')"
* }
* }
* )
*/
class ProgramEvent
{
const PROGRAM_START = 'program_start';
const PROGRAM_END = 'program_end';
const PROGRAM_REDO = 'program_redo';
const TYPES = [
self::PROGRAM_START,
self::PROGRAM_END,
self::PROGRAM_REDO,
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"program_event:read"})
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Program::class, inversedBy="programEvents")
* @ORM\JoinColumn(nullable=true)
* @Groups({"program_event:read", "day_event:write"})
*/
private $program;
/**
* @ORM\ManyToOne(targetEntity=Channel::class, inversedBy="programEvents")
* @ORM\JoinColumn(nullable=true)
* @Groups({"program_event:read", "day_event:write"})
*/
private $channel;
/**
* @ORM\ManyToOne(targetEntity=TvUser::class, inversedBy="programEvents")
* @ORM\JoinColumn(nullable=true)
* @Groups({"program_event:read", "day_event:write"})
*/
private $tvUser;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="programEvents")
* @ORM\JoinColumn(nullable=true)
* @Assert\NotNull
* @Groups({"program_event:read", "day_event:write"})
*/
private $user;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"program_event:read", "day_event:write"})
* @Assert\Choice(choices=self::TYPES, message="program_event.types")
* @ApiProperty(
* attributes={
* "openapi_context"={"type"="string", "enum"=self::TYPES, "example"="program_start|program_end|program_redo"}
* }
* )
*/
private $type;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
* @Groups({"program_event:read"})
*/
private $createdAt;
public function getId(): ?int
{
return $this->id;
}
public function getProgram(): ?Program
{
return $this->program;
}
public function setProgram(?Program $program): self
{
$this->program = $program;
return $this;
}
public function getChannel(): ?Channel
{
return $this->channel;
}
public function setChannel(?Channel $channel): self
{
$this->channel = $channel;
return $this;
}
public function getTvUser(): ?TvUser
{
return $this->tvUser;
}
public function setTvUser(?TvUser $tvUser): self
{
$this->tvUser = $tvUser;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public static function getImplodedTypes(): string
{
return implode('|', self::TYPES);
}
}