src/Entity/BikeLog.php line 31

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\BikeLogRepository;
  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"={"bike_log:read"}},
  15.  *      denormalizationContext={"groups"={"bike_log:write"}},
  16.  *      itemOperations={
  17.  *          "get"={"security"="is_granted('ROLE_USER')"}
  18.  *      },
  19.  *      collectionOperations={
  20.  *          "get"={"security"="is_granted('ROLE_USER')"}
  21.  *      }
  22.  * )
  23.  * @ORM\Entity(repositoryClass=BikeLogRepository::class)
  24.  * @ApiFilter(SearchFilter::class, properties={"user.id": "exact", "company.id": "exact"})
  25.  * @ApiFilter(DateFilter::class, properties={"logDate", "dateStart", "dateEnd"})
  26.  * @ApiFilter(OrderFilter::class)
  27.  */
  28. class BikeLog
  29. {
  30.     /**
  31.      * @ORM\Id
  32.      * @ORM\GeneratedValue
  33.      * @ORM\Column(type="integer")
  34.      * @Groups({"bike_log:read"})
  35.      */
  36.     private $id;
  37.     /**
  38.      * @ORM\ManyToOne(targetEntity=User::class)
  39.      * @ORM\JoinColumn(nullable=false)
  40.      * @Groups({"bike_log:read", "bike_log:write"})
  41.      */
  42.     private $user;
  43.     /**
  44.      * @ORM\ManyToOne(targetEntity=Company::class)
  45.      * @Groups({"bike_log:read", "bike_log:write"})
  46.      */
  47.     private $company;
  48.     /**
  49.      * Distance en mètres (avec décimales)
  50.      * @ORM\Column(type="decimal", precision=10, scale=2, options={"default": "0"})
  51.      * @Groups({"bike_log:read", "bike_log:write"})
  52.      */
  53.     private $distanceAmount = 0;
  54.     /**
  55.      * Date du log (jour normalisé à minuit)
  56.      * @ORM\Column(type="date")
  57.      * @Groups({"bike_log:read", "bike_log:write"})
  58.      */
  59.     private $logDate;
  60.     /**
  61.      * @ORM\Column(type="datetime", nullable=true)
  62.      * @Groups({"bike_log:read", "bike_log:write"})
  63.      */
  64.     private $dateStart;
  65.     /**
  66.      * @ORM\Column(type="datetime", nullable=true)
  67.      * @Groups({"bike_log:read", "bike_log:write"})
  68.      */
  69.     private $dateEnd;
  70.     /**
  71.      * @ORM\Column(type="string", length=50, nullable=true)
  72.      * @Groups({"bike_log:read", "bike_log:write"})
  73.      */
  74.     private $source;
  75.     /**
  76.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  77.      * @Groups({"bike_log:read"})
  78.      */
  79.     private $previousDistanceAmount;
  80.     /**
  81.      * @ORM\Column(type="integer", options={"default": "0"})
  82.      * @Groups({"bike_log:read"})
  83.      */
  84.     private $regularizationCount = 0;
  85.     /**
  86.      * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  87.      * @Gedmo\Timestampable(on="create")
  88.      * @Groups({"bike_log:read"})
  89.      */
  90.     private $createdAt;
  91.     /**
  92.      * @ORM\Column(type="datetime", nullable=true)
  93.      * @Gedmo\Timestampable(on="update")
  94.      * @Groups({"bike_log:read"})
  95.      */
  96.     private $updatedAt;
  97.     public function getId(): ?int 
  98.     { 
  99.         return $this->id; 
  100.     }
  101.     public function getUser(): ?User 
  102.     { 
  103.         return $this->user; 
  104.     }
  105.     
  106.     public function setUser(?User $user): self 
  107.     { 
  108.         $this->user = $user; 
  109.         return $this; 
  110.     }
  111.     public function getCompany(): ?Company 
  112.     { 
  113.         return $this->company; 
  114.     }
  115.     
  116.     public function setCompany(?Company $company): self 
  117.     { 
  118.         $this->company = $company; 
  119.         return $this; 
  120.     }
  121.     public function getDistanceAmount(): float 
  122.     { 
  123.         return (float) $this->distanceAmount; 
  124.     }
  125.     
  126.     public function setDistanceAmount(float $distanceAmount): self 
  127.     { 
  128.         $this->distanceAmount = $distanceAmount; 
  129.         return $this; 
  130.     }
  131.     /**
  132.      * Retourne la distance en kilomètres
  133.      */
  134.     public function getDistanceInKm(): float 
  135.     { 
  136.         return $this->distanceAmount / 1000; 
  137.     }
  138.     public function getLogDate(): ?\DateTimeInterface 
  139.     { 
  140.         return $this->logDate; 
  141.     }
  142.     
  143.     public function setLogDate(\DateTimeInterface $logDate): self 
  144.     { 
  145.         $this->logDate = $logDate; 
  146.         return $this; 
  147.     }
  148.     public function getDateStart(): ?\DateTimeInterface 
  149.     { 
  150.         return $this->dateStart; 
  151.     }
  152.     
  153.     public function setDateStart(?\DateTimeInterface $dateStart): self 
  154.     { 
  155.         $this->dateStart = $dateStart; 
  156.         return $this; 
  157.     }
  158.     public function getDateEnd(): ?\DateTimeInterface 
  159.     { 
  160.         return $this->dateEnd; 
  161.     }
  162.     
  163.     public function setDateEnd(?\DateTimeInterface $dateEnd): self 
  164.     { 
  165.         $this->dateEnd = $dateEnd; 
  166.         return $this; 
  167.     }
  168.     public function getSource(): ?string 
  169.     { 
  170.         return $this->source; 
  171.     }
  172.     
  173.     public function setSource(?string $source): self 
  174.     { 
  175.         $this->source = $source; 
  176.         return $this; 
  177.     }
  178.     public function getPreviousDistanceAmount(): ?float 
  179.     { 
  180.         return $this->previousDistanceAmount ? (float) $this->previousDistanceAmount : null; 
  181.     }
  182.     
  183.     public function setPreviousDistanceAmount(?float $previousDistanceAmount): self 
  184.     { 
  185.         $this->previousDistanceAmount = $previousDistanceAmount; 
  186.         return $this; 
  187.     }
  188.     public function getRegularizationCount(): int 
  189.     { 
  190.         return $this->regularizationCount; 
  191.     }
  192.     
  193.     public function incrementRegularizationCount(): self 
  194.     { 
  195.         $this->regularizationCount++; 
  196.         return $this; 
  197.     }
  198.     public function getCreatedAt(): ?\DateTimeInterface 
  199.     { 
  200.         return $this->createdAt; 
  201.     }
  202.     
  203.     public function setCreatedAt(\DateTimeInterface $createdAt): self 
  204.     { 
  205.         $this->createdAt = $createdAt; 
  206.         return $this; 
  207.     }
  208.     public function getUpdatedAt(): ?\DateTimeInterface 
  209.     { 
  210.         return $this->updatedAt; 
  211.     }
  212.     
  213.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self 
  214.     { 
  215.         $this->updatedAt = $updatedAt; 
  216.         return $this; 
  217.     }
  218. }