src/Entity/PedometerLog.php line 58

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Annotation\ApiSubresource;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  9. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  11. use ApiPlatform\Core\Serializer\Filter\GroupFilter;
  12. use App\Repository\PedometerLogRepository;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Gedmo\Mapping\Annotation as Gedmo;
  15. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. /**
  19.  * @ORM\Entity(repositoryClass=PedometerLogRepository::class)
  20.  * @ORM\Table(
  21.  *     uniqueConstraints={
  22.  *         @ORM\UniqueConstraint(name="unique_user_day", columns={"user_id", "log_date"})
  23.  *     },
  24.  *     indexes={
  25.  *         @ORM\Index(name="idx_user_log_date", columns={"user_id", "log_date"}),
  26.  *         @ORM\Index(name="idx_log_date", columns={"log_date"})
  27.  *     }
  28.  * )
  29.  * @ApiResource(
  30.  *      normalizationContext={"groups"={"pedometer_log:read"}},
  31.  *      denormalizationContext={"groups"={"pedometer_log:write"}},
  32.  *      itemOperations={
  33.  *          "get"={
  34.  *              "security"="is_granted('ROLE_USER')"
  35.  *          }, 
  36.  *          "patch"={
  37.  *              "security"="is_granted('ROLE_USER')"
  38.  *          }, 
  39.  *          "delete"={
  40.  *              "security"="is_granted('ROLE_ADMIN')"
  41.  *          }
  42.  *      },
  43.  *      collectionOperations={
  44.  *          "get"={
  45.  *              "security"="is_granted('ROLE_USER')"
  46.  *          }, 
  47.  *          "post"={
  48.  *              "security"="is_granted('ROLE_USER')"
  49.  *          }
  50.  *      }
  51.  * )
  52.  * @ApiFilter(DateFilter::class, properties={"logDate"})
  53.  * @ApiFilter(SearchFilter::class, properties={"user": "exact"})
  54.  */
  55. class PedometerLog
  56. {
  57.     /**
  58.      * @ORM\Id
  59.      * @ORM\GeneratedValue
  60.      * @ORM\Column(type="integer")
  61.      * @Groups({"pedometer_log:read"})
  62.      */
  63.     private $id;
  64.     /**
  65.      * @ORM\ManyToOne(targetEntity=TvUser::class, inversedBy="pedometerLogs")
  66.      * @Groups({"pedometer_log:read", "pedometer_log:write"})
  67.      */
  68.     private $tvUser;
  69.     /**
  70.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="pedometerLogs")
  71.      * @Assert\NotNull
  72.      * @Groups({"pedometer_log:read", "pedometer_log:write"})
  73.      */
  74.     private $user;
  75.     /**
  76.      * @ORM\ManyToOne(targetEntity=TvCompany::class, inversedBy="pedometerLogs")
  77.      * @Groups({"pedometer_log:read"})
  78.      */
  79.     private $tvCompany;
  80.     /**
  81.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="pedometerLogs")
  82.      * @Groups({"pedometer_log:read"})
  83.      */
  84.     private $company;
  85.     /**
  86.      * @ORM\Column(type="integer", nullable=false, options={"default": 0})
  87.      * @Assert\NotNull
  88.      * @Groups({"pedometer_log:read", "pedometer_log:write"})
  89.      */
  90.     private $stepAmount = 0;
  91.     /**
  92.      * Date du jour (sans heure) pour identifier la journée unique
  93.      * @ORM\Column(type="date", nullable=false)
  94.      * @Groups({"pedometer_log:read", "pedometer_log:write"})
  95.      */
  96.     private $logDate;
  97.     /**
  98.      * @ORM\Column(type="datetime", nullable=true)
  99.      * @Groups({"pedometer_log:read", "pedometer_log:write"})
  100.      */
  101.     private $dateStart;
  102.     /**
  103.      * @ORM\Column(type="datetime", nullable=true)
  104.      * @Groups({"pedometer_log:read", "pedometer_log:write"})
  105.      */
  106.     private $dateEnd;
  107.     /**
  108.      * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  109.      * @Gedmo\Timestampable(on="create")
  110.      * @Groups({"pedometer_log:read"})
  111.      */
  112.     private $createdAt;
  113.     /**
  114.      * @ORM\Column(type="datetime", nullable=true)
  115.      * @Gedmo\Timestampable(on="update")
  116.      * @Groups({"pedometer_log:read"})
  117.      */
  118.     private $updatedAt;
  119.     /**
  120.      * Source des données: 'ios', 'android', 'garmin', 'manual'
  121.      * @ORM\Column(type="string", length=50, nullable=true)
  122.      * @Groups({"pedometer_log:read", "pedometer_log:write"})
  123.      */
  124.     private $source;
  125.     /**
  126.      * Nombre de régularisations effectuées sur cette entrée
  127.      * @ORM\Column(type="integer", options={"default": 0})
  128.      * @Groups({"pedometer_log:read"})
  129.      */
  130.     private $regularizationCount = 0;
  131.     /**
  132.      * Dernière valeur avant régularisation (pour audit)
  133.      * @ORM\Column(type="integer", nullable=true)
  134.      * @Groups({"pedometer_log:read"})
  135.      */
  136.     private $previousStepAmount;
  137.     public function getId(): ?int
  138.     {
  139.         return $this->id;
  140.     }
  141.     public function getTvUser(): ?TvUser
  142.     {
  143.         return $this->tvUser;
  144.     }
  145.     public function setTvUser(?TvUser $tvUser): self
  146.     {
  147.         $this->tvUser = $tvUser;
  148.         return $this;
  149.     }
  150.     public function getUser(): ?User
  151.     {
  152.         return $this->user;
  153.     }
  154.     public function setUser(?User $user): self
  155.     {
  156.         $this->user = $user;
  157.         return $this;
  158.     }
  159.     public function getTvCompany(): ?TvCompany
  160.     {
  161.         return $this->tvCompany;
  162.     }
  163.     public function setTvCompany(?TvCompany $tvCompany): self
  164.     {
  165.         $this->tvCompany = $tvCompany;
  166.         return $this;
  167.     }
  168.     public function getCompany(): ?Company
  169.     {
  170.         return $this->company;
  171.     }
  172.     public function setCompany(?Company $company): self
  173.     {
  174.         $this->company = $company;
  175.         return $this;
  176.     }
  177.     public function getStepAmount(): ?int
  178.     {
  179.         return $this->stepAmount;
  180.     }
  181.     public function setStepAmount(?int $stepAmount): self
  182.     {
  183.         $this->stepAmount = $stepAmount ?? 0;
  184.         return $this;
  185.     }
  186.     public function getLogDate(): ?\DateTimeInterface
  187.     {
  188.         return $this->logDate;
  189.     }
  190.     public function setLogDate(\DateTimeInterface $logDate): self
  191.     {
  192.         $this->logDate = $logDate;
  193.         return $this;
  194.     }
  195.     public function getDateStart(): ?\DateTimeInterface
  196.     {
  197.         return $this->dateStart;
  198.     }
  199.     public function setDateStart(?\DateTimeInterface $dateStart): self
  200.     {
  201.         $this->dateStart = $dateStart;
  202.         return $this;
  203.     }
  204.     public function getDateEnd(): ?\DateTimeInterface
  205.     {
  206.         return $this->dateEnd;
  207.     }
  208.     public function setDateEnd(?\DateTimeInterface $dateEnd): self
  209.     {
  210.         $this->dateEnd = $dateEnd;
  211.         return $this;
  212.     }
  213.     public function getCreatedAt(): ?\DateTimeInterface
  214.     {
  215.         return $this->createdAt;
  216.     }
  217.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  218.     {
  219.         $this->createdAt = $createdAt;
  220.         return $this;
  221.     }
  222.     public function getUpdatedAt(): ?\DateTimeInterface
  223.     {
  224.         return $this->updatedAt;
  225.     }
  226.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  227.     {
  228.         $this->updatedAt = $updatedAt;
  229.         return $this;
  230.     }
  231.     public function getSource(): ?string
  232.     {
  233.         return $this->source;
  234.     }
  235.     public function setSource(?string $source): self
  236.     {
  237.         $this->source = $source;
  238.         return $this;
  239.     }
  240.     public function getRegularizationCount(): int
  241.     {
  242.         return $this->regularizationCount;
  243.     }
  244.     public function setRegularizationCount(int $regularizationCount): self
  245.     {
  246.         $this->regularizationCount = $regularizationCount;
  247.         return $this;
  248.     }
  249.     public function incrementRegularizationCount(): self
  250.     {
  251.         $this->regularizationCount++;
  252.         return $this;
  253.     }
  254.     public function getPreviousStepAmount(): ?int
  255.     {
  256.         return $this->previousStepAmount;
  257.     }
  258.     public function setPreviousStepAmount(?int $previousStepAmount): self
  259.     {
  260.         $this->previousStepAmount = $previousStepAmount;
  261.         return $this;
  262.     }
  263. }