<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use App\Repository\AwardLogRepository;
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=AwardLogRepository::class)
* @ApiResource(
* normalizationContext={
* "groups"={"award_log:read"}
* },
* denormalizationContext={
* "groups"={"award_log:write"}
* },
* collectionOperations={
* "get"={"security"="is_granted('ROLE_ADMIN')"}
* },
* itemOperations={
* "get"={"security"="is_granted('ROLE_ADMIN')"}
* }
* )
* @ApiFilter(SearchFilter::class, properties={
* "id": "exact", "type": "exact", "subType": "exact", "tvUser.id": "exact",
* "tvUser.tvCompany.id": "exact", "award.id": "exact"
* })
*/
class AwardLog
{
const AWARD_EVENT = "award_event";
const AWARD_START = "award_start";
const AWARD_END = "award_end";
const AWARD_REDO = "award_redo";
const USER_EVENT = "user_event";
const USER_WON = "user_won";
const USER_LOST = "user_lost";
const TYPES = [
self::AWARD_EVENT,
self::USER_EVENT,
];
const SUBTYPES = [
self::AWARD_START,
self::AWARD_END,
self::AWARD_REDO,
self::USER_WON,
self::USER_LOST
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"award_config:read"})
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=TvUser::class, inversedBy="awardLogs", cascade={"persist", "refresh"})
* @Groups({"award_config:read"})
*/
private $tvUser;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="awardLogs", cascade={"persist", "refresh"})
* @Groups({"award_config:read"})
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity=Award::class, inversedBy="awardLogs")
* @Groups({"award_config:read"})
*/
private $award;
/**
* @ORM\ManyToOne(targetEntity=AwardOperation::class)
* @Groups({"award_config:read"})
*/
private $operation;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"award_config:read"})
*/
private $pointsWon;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"award_config:read"})
*/
private $pointsTotal = 0;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Choice(choices=self::TYPES)
* @Groups({"award_config:read"})
*/
private $type;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Choice(choices=self::SUBTYPES)
* @Groups({"award_config:read"})
*/
private $subType;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
public function __construct()
{
$this->pointsTotal = 0;
}
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getSubType(): ?string
{
return $this->subType;
}
public function setSubType(?string $subType): self
{
$this->subType = $subType;
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 getPointsWon(): ?int
{
return $this->pointsWon;
}
public function setPointsWon(?int $pointsWon): self
{
$this->pointsWon = $pointsWon;
return $this;
}
public function getPointsTotal(): ?int
{
return $this->pointsTotal;
}
public function setPointsTotal(?int $pointsTotal): self
{
$this->pointsTotal = $pointsTotal;
return $this;
}
public function getAward(): ?Award
{
return $this->award;
}
public function setAward(?Award $award): self
{
$this->award = $award;
return $this;
}
public function getOperation(): ?AwardOperation
{
return $this->operation;
}
public function setOperation(?AwardOperation $operation): self
{
$this->operation = $operation;
return $this;
}
}