<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Core\Serializer\Filter\GroupFilter;
use App\Repository\PedometerLogRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=PedometerLogRepository::class)
* @ORM\Table(
* uniqueConstraints={
* @ORM\UniqueConstraint(name="unique_user_day", columns={"user_id", "log_date"})
* },
* indexes={
* @ORM\Index(name="idx_user_log_date", columns={"user_id", "log_date"}),
* @ORM\Index(name="idx_log_date", columns={"log_date"})
* }
* )
* @ApiResource(
* normalizationContext={"groups"={"pedometer_log:read"}},
* denormalizationContext={"groups"={"pedometer_log:write"}},
* itemOperations={
* "get"={
* "security"="is_granted('ROLE_USER')"
* },
* "patch"={
* "security"="is_granted('ROLE_USER')"
* },
* "delete"={
* "security"="is_granted('ROLE_ADMIN')"
* }
* },
* collectionOperations={
* "get"={
* "security"="is_granted('ROLE_USER')"
* },
* "post"={
* "security"="is_granted('ROLE_USER')"
* }
* }
* )
* @ApiFilter(DateFilter::class, properties={"logDate"})
* @ApiFilter(SearchFilter::class, properties={"user": "exact"})
*/
class PedometerLog
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"pedometer_log:read"})
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=TvUser::class, inversedBy="pedometerLogs")
* @Groups({"pedometer_log:read", "pedometer_log:write"})
*/
private $tvUser;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="pedometerLogs")
* @Assert\NotNull
* @Groups({"pedometer_log:read", "pedometer_log:write"})
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity=TvCompany::class, inversedBy="pedometerLogs")
* @Groups({"pedometer_log:read"})
*/
private $tvCompany;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="pedometerLogs")
* @Groups({"pedometer_log:read"})
*/
private $company;
/**
* @ORM\Column(type="integer", nullable=false, options={"default": 0})
* @Assert\NotNull
* @Groups({"pedometer_log:read", "pedometer_log:write"})
*/
private $stepAmount = 0;
/**
* Date du jour (sans heure) pour identifier la journée unique
* @ORM\Column(type="date", nullable=false)
* @Groups({"pedometer_log:read", "pedometer_log:write"})
*/
private $logDate;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"pedometer_log:read", "pedometer_log:write"})
*/
private $dateStart;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"pedometer_log:read", "pedometer_log:write"})
*/
private $dateEnd;
/**
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
* @Gedmo\Timestampable(on="create")
* @Groups({"pedometer_log:read"})
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Gedmo\Timestampable(on="update")
* @Groups({"pedometer_log:read"})
*/
private $updatedAt;
/**
* Source des données: 'ios', 'android', 'garmin', 'manual'
* @ORM\Column(type="string", length=50, nullable=true)
* @Groups({"pedometer_log:read", "pedometer_log:write"})
*/
private $source;
/**
* Nombre de régularisations effectuées sur cette entrée
* @ORM\Column(type="integer", options={"default": 0})
* @Groups({"pedometer_log:read"})
*/
private $regularizationCount = 0;
/**
* Dernière valeur avant régularisation (pour audit)
* @ORM\Column(type="integer", nullable=true)
* @Groups({"pedometer_log:read"})
*/
private $previousStepAmount;
public function getId(): ?int
{
return $this->id;
}
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 getTvCompany(): ?TvCompany
{
return $this->tvCompany;
}
public function setTvCompany(?TvCompany $tvCompany): self
{
$this->tvCompany = $tvCompany;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getStepAmount(): ?int
{
return $this->stepAmount;
}
public function setStepAmount(?int $stepAmount): self
{
$this->stepAmount = $stepAmount ?? 0;
return $this;
}
public function getLogDate(): ?\DateTimeInterface
{
return $this->logDate;
}
public function setLogDate(\DateTimeInterface $logDate): self
{
$this->logDate = $logDate;
return $this;
}
public function getDateStart(): ?\DateTimeInterface
{
return $this->dateStart;
}
public function setDateStart(?\DateTimeInterface $dateStart): self
{
$this->dateStart = $dateStart;
return $this;
}
public function getDateEnd(): ?\DateTimeInterface
{
return $this->dateEnd;
}
public function setDateEnd(?\DateTimeInterface $dateEnd): self
{
$this->dateEnd = $dateEnd;
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;
}
public function getSource(): ?string
{
return $this->source;
}
public function setSource(?string $source): self
{
$this->source = $source;
return $this;
}
public function getRegularizationCount(): int
{
return $this->regularizationCount;
}
public function setRegularizationCount(int $regularizationCount): self
{
$this->regularizationCount = $regularizationCount;
return $this;
}
public function incrementRegularizationCount(): self
{
$this->regularizationCount++;
return $this;
}
public function getPreviousStepAmount(): ?int
{
return $this->previousStepAmount;
}
public function setPreviousStepAmount(?int $previousStepAmount): self
{
$this->previousStepAmount = $previousStepAmount;
return $this;
}
}