<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use App\Repository\DailyRewardLogRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ApiResource(
* normalizationContext={"groups"={"daily_reward_log:read"}},
* denormalizationContext={"groups"={"daily_reward_log:write"}},
* itemOperations={
* "get"={"security"="is_granted('ROLE_USER')"},
* "patch"={"security"="is_granted('ROLE_USER')"}
* },
* collectionOperations={
* "get"={"security"="is_granted('ROLE_USER')"},
* "post"={"security"="is_granted('ROLE_USER')"}
* }
* )
* @ORM\Entity(repositoryClass=DailyRewardLogRepository::class)
* @ORM\Table(
* name="daily_reward_log",
* uniqueConstraints={
* @ORM\UniqueConstraint(name="unique_user_date", columns={"user_id", "log_date"})
* }
* )
* @UniqueEntity(
* fields={"user", "logDate"},
* message="Un log de récompense quotidienne existe déjà pour cet utilisateur à cette date."
* )
* @ApiFilter(SearchFilter::class, properties={"user.id": "exact", "company.id": "exact"})
* @ApiFilter(BooleanFilter::class, properties={"isCollected"})
* @ApiFilter(DateFilter::class, properties={"logDate", "notificationScheduledFor", "notificationSentAt"})
* @ApiFilter(OrderFilter::class)
*/
class DailyRewardLog
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"daily_reward_log:read"})
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false)
* @Groups({"daily_reward_log:read", "daily_reward_log:write"})
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity=Company::class)
* @Groups({"daily_reward_log:read", "daily_reward_log:write"})
*/
private $company;
/**
* @ORM\ManyToOne(targetEntity=Teamplay::class)
* @Groups({"daily_reward_log:read", "daily_reward_log:write"})
*/
private $teamplay;
/**
* Date du log (jour normalisé à minuit)
* @ORM\Column(type="date")
* @Groups({"daily_reward_log:read", "daily_reward_log:write"})
*/
private $logDate;
/**
* Indique si l'utilisateur a récupéré ses points
* @ORM\Column(type="boolean", options={"default": "0"})
* @Groups({"daily_reward_log:read", "daily_reward_log:write"})
*/
private $isCollected = false;
/**
* Nombre de points disponibles pour cette récompense quotidienne
* @ORM\Column(type="integer", options={"default": "0"})
* @Groups({"daily_reward_log:read", "daily_reward_log:write"})
*/
private $pointAmount = 0;
/**
* Heure programmée pour la notification (avec décalage aléatoire)
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"daily_reward_log:read"})
*/
private $notificationScheduledFor;
/**
* Date d'envoi de la notification
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"daily_reward_log:read"})
*/
private $notificationSentAt;
/**
* Décalage en minutes pour cette notification (pour étaler les connexions)
* @ORM\Column(type="integer", nullable=true)
* @Groups({"daily_reward_log:read"})
*/
private $notificationOffsetMinutes;
/**
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
* @Gedmo\Timestampable(on="create")
* @Groups({"daily_reward_log:read"})
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Gedmo\Timestampable(on="update")
* @Groups({"daily_reward_log:read"})
*/
private $updatedAt;
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getTeamplay(): ?Teamplay
{
return $this->teamplay;
}
public function setTeamplay(?Teamplay $teamplay): self
{
$this->teamplay = $teamplay;
return $this;
}
public function getLogDate(): ?\DateTimeInterface
{
return $this->logDate;
}
public function setLogDate(\DateTimeInterface $logDate): self
{
$this->logDate = $logDate;
return $this;
}
public function getIsCollected(): bool
{
return $this->isCollected;
}
public function setIsCollected(bool $isCollected): self
{
$this->isCollected = $isCollected;
return $this;
}
public function getPointAmount(): int
{
return $this->pointAmount;
}
public function setPointAmount(int $pointAmount): self
{
$this->pointAmount = $pointAmount;
return $this;
}
public function getNotificationScheduledFor(): ?\DateTimeInterface
{
return $this->notificationScheduledFor;
}
public function setNotificationScheduledFor(?\DateTimeInterface $notificationScheduledFor): self
{
$this->notificationScheduledFor = $notificationScheduledFor;
return $this;
}
public function getNotificationSentAt(): ?\DateTimeInterface
{
return $this->notificationSentAt;
}
public function setNotificationSentAt(?\DateTimeInterface $notificationSentAt): self
{
$this->notificationSentAt = $notificationSentAt;
return $this;
}
public function getNotificationOffsetMinutes(): ?int
{
return $this->notificationOffsetMinutes;
}
public function setNotificationOffsetMinutes(?int $notificationOffsetMinutes): self
{
$this->notificationOffsetMinutes = $notificationOffsetMinutes;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
}