src/Entity/RunLog.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  8. use App\Repository\RunLogRepository;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. /**
  13.  * @ApiResource(
  14.  *      normalizationContext={"groups"={"run_log:read"}},
  15.  *      denormalizationContext={"groups"={"run_log:write"}},
  16.  *      itemOperations={
  17.  *          "get"={"security"="is_granted('ROLE_ADMIN') or object.getUser() == user"}
  18.  *      },
  19.  *      collectionOperations={
  20.  *          "get"={"security"="is_granted('ROLE_USER')"}
  21.  *      }
  22.  * )
  23.  * @ORM\Entity(repositoryClass=RunLogRepository::class)
  24.  * @ORM\Table(uniqueConstraints={
  25.  *     @ORM\UniqueConstraint(name="uniq_run_log_source_external_id", columns={"source", "external_id"})
  26.  * })
  27.  * @ApiFilter(SearchFilter::class, properties={"user.id": "exact", "company.id": "exact"})
  28.  * @ApiFilter(DateFilter::class, properties={"logDate", "dateStart", "dateEnd"})
  29.  * @ApiFilter(OrderFilter::class)
  30.  */
  31. class RunLog
  32. {
  33.     /**
  34.      * @ORM\Id
  35.      * @ORM\GeneratedValue
  36.      * @ORM\Column(type="integer")
  37.      * @Groups({"run_log:read"})
  38.      */
  39.     private $id;
  40.     /**
  41.      * @ORM\ManyToOne(targetEntity=User::class)
  42.      * @ORM\JoinColumn(nullable=false)
  43.      * @Groups({"run_log:read", "run_log:write"})
  44.      */
  45.     private $user;
  46.     /**
  47.      * @ORM\ManyToOne(targetEntity=Company::class)
  48.      * @Groups({"run_log:read", "run_log:write"})
  49.      */
  50.     private $company;
  51.     /**
  52.      * Distance en mètres (avec décimales)
  53.      * @ORM\Column(type="decimal", precision=10, scale=2, options={"default": "0"})
  54.      * @Groups({"run_log:read", "run_log:write"})
  55.      */
  56.     private $distanceAmount = 0;
  57.     /**
  58.      * Date du log (jour normalisé à minuit)
  59.      * @ORM\Column(type="date")
  60.      * @Groups({"run_log:read", "run_log:write"})
  61.      */
  62.     private $logDate;
  63.     /**
  64.      * @ORM\Column(type="datetime", nullable=true)
  65.      * @Groups({"run_log:read", "run_log:write"})
  66.      */
  67.     private $dateStart;
  68.     /**
  69.      * @ORM\Column(type="datetime", nullable=true)
  70.      * @Groups({"run_log:read", "run_log:write"})
  71.      */
  72.     private $dateEnd;
  73.     /**
  74.      * @ORM\Column(type="string", length=50, nullable=true)
  75.      * @Groups({"run_log:read", "run_log:write"})
  76.      */
  77.     private $source;
  78.     /**
  79.      * Identifiant de l'activité chez la source externe (id Strava) : une ligne par activité (#3369).
  80.      * Null pour une activité de l'app (source app_tracking). Unique avec source ; pas de clé étrangère
  81.      * vers strava_activity : la ligne survit à la déconnexion de Strava.
  82.      * @ORM\Column(type="bigint", nullable=true)
  83.      * @Groups({"run_log:read"})
  84.      */
  85.     private $externalId;
  86.     /**
  87.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  88.      * @Groups({"run_log:read"})
  89.      */
  90.     private $previousDistanceAmount;
  91.     /**
  92.      * @ORM\Column(type="integer", options={"default": "0"})
  93.      * @Groups({"run_log:read"})
  94.      */
  95.     private $regularizationCount = 0;
  96.     /**
  97.      * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  98.      * @Gedmo\Timestampable(on="create")
  99.      * @Groups({"run_log:read"})
  100.      */
  101.     private $createdAt;
  102.     /**
  103.      * @ORM\Column(type="datetime", nullable=true)
  104.      * @Gedmo\Timestampable(on="update")
  105.      * @Groups({"run_log:read"})
  106.      */
  107.     private $updatedAt;
  108.     public function getId(): ?int
  109.     {
  110.         return $this->id;
  111.     }
  112.     public function getUser(): ?User
  113.     {
  114.         return $this->user;
  115.     }
  116.     
  117.     public function setUser(?User $user): self
  118.     {
  119.         $this->user = $user;
  120.         return $this;
  121.     }
  122.     public function getCompany(): ?Company
  123.     {
  124.         return $this->company;
  125.     }
  126.     
  127.     public function setCompany(?Company $company): self
  128.     {
  129.         $this->company = $company;
  130.         return $this;
  131.     }
  132.     public function getDistanceAmount(): float
  133.     {
  134.         return (float) $this->distanceAmount;
  135.     }
  136.     
  137.     public function setDistanceAmount(float $distanceAmount): self
  138.     {
  139.         $this->distanceAmount = $distanceAmount;
  140.         return $this;
  141.     }
  142.     /**
  143.      * Retourne la distance en kilomètres
  144.      */
  145.     public function getDistanceInKm(): float
  146.     {
  147.         return $this->distanceAmount / 1000;
  148.     }
  149.     public function getLogDate(): ?\DateTimeInterface
  150.     {
  151.         return $this->logDate;
  152.     }
  153.     
  154.     public function setLogDate(\DateTimeInterface $logDate): self
  155.     {
  156.         $this->logDate = $logDate;
  157.         return $this;
  158.     }
  159.     public function getDateStart(): ?\DateTimeInterface
  160.     {
  161.         return $this->dateStart;
  162.     }
  163.     
  164.     public function setDateStart(?\DateTimeInterface $dateStart): self
  165.     {
  166.         $this->dateStart = $dateStart;
  167.         return $this;
  168.     }
  169.     public function getDateEnd(): ?\DateTimeInterface
  170.     {
  171.         return $this->dateEnd;
  172.     }
  173.     
  174.     public function setDateEnd(?\DateTimeInterface $dateEnd): self
  175.     {
  176.         $this->dateEnd = $dateEnd;
  177.         return $this;
  178.     }
  179.     public function getSource(): ?string
  180.     {
  181.         return $this->source;
  182.     }
  183.     
  184.     public function setSource(?string $source): self
  185.     {
  186.         $this->source = $source;
  187.         return $this;
  188.     }
  189.     public function getExternalId(): ?int
  190.     {
  191.         return $this->externalId === null ? null : (int) $this->externalId;
  192.     }
  193.     public function setExternalId(?int $externalId): self
  194.     {
  195.         $this->externalId = $externalId === null ? null : (string) $externalId;
  196.         return $this;
  197.     }
  198.     public function getPreviousDistanceAmount(): ?float
  199.     {
  200.         return $this->previousDistanceAmount ? (float) $this->previousDistanceAmount : null;
  201.     }
  202.     
  203.     public function setPreviousDistanceAmount(?float $previousDistanceAmount): self
  204.     {
  205.         $this->previousDistanceAmount = $previousDistanceAmount;
  206.         return $this;
  207.     }
  208.     public function getRegularizationCount(): int
  209.     {
  210.         return $this->regularizationCount;
  211.     }
  212.     
  213.     public function incrementRegularizationCount(): self
  214.     {
  215.         $this->regularizationCount++;
  216.         return $this;
  217.     }
  218.     public function getCreatedAt(): ?\DateTimeInterface
  219.     {
  220.         return $this->createdAt;
  221.     }
  222.     
  223.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  224.     {
  225.         $this->createdAt = $createdAt;
  226.         return $this;
  227.     }
  228.     public function getUpdatedAt(): ?\DateTimeInterface
  229.     {
  230.         return $this->updatedAt;
  231.     }
  232.     
  233.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  234.     {
  235.         $this->updatedAt = $updatedAt;
  236.         return $this;
  237.     }
  238. }