src/Entity/KinestexLog.php line 40

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\KinestexLogRepository;
  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"={"kinestex_log:read"}},
  15.  *      denormalizationContext={"groups"={"kinestex_log:write"}},
  16.  *      itemOperations={
  17.  *          "get"={"security"="is_granted('ROLE_USER')"},
  18.  *          "put"={"security"="is_granted('ROLE_USER')"},
  19.  *          "delete"={"security"="is_granted('ROLE_USER')"}
  20.  *      },
  21.  *      collectionOperations={
  22.  *          "get"={"security"="is_granted('ROLE_USER')"},
  23.  *          "post"={"security"="is_granted('ROLE_USER')"}
  24.  *      }
  25.  * )
  26.  * @ORM\Entity(repositoryClass=KinestexLogRepository::class)
  27.  * @ApiFilter(SearchFilter::class, properties={
  28.  *     "user.id": "exact", 
  29.  *     "company.id": "exact", 
  30.  *     "exerciseType": "exact",
  31.  *     "kinestexExercise.id": "exact",
  32.  *     "kinestexExercise.kinestexId": "exact"
  33.  * })
  34.  * @ApiFilter(DateFilter::class, properties={"logDate", "createdAt"})
  35.  * @ApiFilter(OrderFilter::class)
  36.  */
  37. class KinestexLog
  38. {
  39.     /**
  40.      * @ORM\Id
  41.      * @ORM\GeneratedValue
  42.      * @ORM\Column(type="integer")
  43.      * @Groups({"kinestex_log:read"})
  44.      */
  45.     private $id;
  46.     /**
  47.      * @ORM\ManyToOne(targetEntity=User::class)
  48.      * @ORM\JoinColumn(nullable=false)
  49.      * @Groups({"kinestex_log:read", "kinestex_log:write"})
  50.      */
  51.     private $user;
  52.     /**
  53.      * @ORM\ManyToOne(targetEntity=Company::class)
  54.      * @Groups({"kinestex_log:read", "kinestex_log:write"})
  55.      */
  56.     private $company;
  57.     /**
  58.      * @ORM\ManyToOne(targetEntity=KinestexExercise::class)
  59.      * @ORM\JoinColumn(nullable=true)
  60.      * @Groups({"kinestex_log:read", "kinestex_log:write"})
  61.      */
  62.     private $kinestexExercise;
  63.     /**
  64.      * Type d'exercice (ex: "repetition", "duration")
  65.      * @ORM\Column(type="string", length=100)
  66.      * @Groups({"kinestex_log:read", "kinestex_log:write"})
  67.      */
  68.     private $exerciseType;
  69.     /**
  70.      * ID de l'exercice KinesteX (legacy, maintenant on utilise la relation)
  71.      * @ORM\Column(type="string", length=100, nullable=true)
  72.      * @Groups({"kinestex_log:read", "kinestex_log:write"})
  73.      */
  74.     private $exerciseId;
  75.     /**
  76.      * Nombre de répétitions effectuées (nullable pour le gainage)
  77.      * @ORM\Column(type="integer", nullable=true)
  78.      * @Groups({"kinestex_log:read", "kinestex_log:write"})
  79.      */
  80.     private $repsCompleted;
  81.     /**
  82.      * Durée en secondes (nullable pour les exercices de répétitions)
  83.      * @ORM\Column(type="integer", nullable=true)
  84.      * @Groups({"kinestex_log:read", "kinestex_log:write"})
  85.      */
  86.     private $durationSeconds;
  87.     /**
  88.      * Calories brûlées
  89.      * @ORM\Column(type="decimal", precision=6, scale=2, nullable=true)
  90.      * @Groups({"kinestex_log:read", "kinestex_log:write"})
  91.      */
  92.     private $caloriesBurned;
  93.     /**
  94.      * Score de précision (0-100)
  95.      * @ORM\Column(type="decimal", precision=5, scale=2, nullable=true)
  96.      * @Groups({"kinestex_log:read", "kinestex_log:write"})
  97.      */
  98.     private $accuracyScore;
  99.     /**
  100.      * Pourcentage de complétion
  101.      * @ORM\Column(type="decimal", precision=5, scale=2, nullable=true)
  102.      * @Groups({"kinestex_log:read", "kinestex_log:write"})
  103.      */
  104.     private $completionPercentage;
  105.     /**
  106.      * Date du log (jour normalisé à minuit)
  107.      * @ORM\Column(type="date")
  108.      * @Groups({"kinestex_log:read", "kinestex_log:write"})
  109.      */
  110.     private $logDate;
  111.     /**
  112.      * Source de données (ex: "kinestex_sdk")
  113.      * @ORM\Column(type="string", length=50, nullable=true)
  114.      * @Groups({"kinestex_log:read", "kinestex_log:write"})
  115.      */
  116.     private $source;
  117.     /**
  118.      * Données brutes JSON de KinesteX
  119.      * @ORM\Column(type="json", nullable=true)
  120.      * @Groups({"kinestex_log:read", "kinestex_log:write"})
  121.      */
  122.     private $rawData = [];
  123.     /**
  124.      * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  125.      * @Gedmo\Timestampable(on="create")
  126.      * @Groups({"kinestex_log:read"})
  127.      */
  128.     private $createdAt;
  129.     /**
  130.      * @ORM\Column(type="datetime", nullable=true)
  131.      * @Gedmo\Timestampable(on="update")
  132.      * @Groups({"kinestex_log:read"})
  133.      */
  134.     private $updatedAt;
  135.     // Getters & Setters existants...
  136.     public function getId(): ?int
  137.     {
  138.         return $this->id;
  139.     }
  140.     public function getUser(): ?User
  141.     {
  142.         return $this->user;
  143.     }
  144.     public function setUser(?User $user): self
  145.     {
  146.         $this->user = $user;
  147.         return $this;
  148.     }
  149.     public function getCompany(): ?Company
  150.     {
  151.         return $this->company;
  152.     }
  153.     public function setCompany(?Company $company): self
  154.     {
  155.         $this->company = $company;
  156.         return $this;
  157.     }
  158.     public function getKinestexExercise(): ?KinestexExercise
  159.     {
  160.         return $this->kinestexExercise;
  161.     }
  162.     public function setKinestexExercise(?KinestexExercise $kinestexExercise): self
  163.     {
  164.         $this->kinestexExercise = $kinestexExercise;
  165.         
  166.         // Auto-populate exerciseId et exerciseType depuis la relation
  167.         if ($kinestexExercise) {
  168.             $this->exerciseId = $kinestexExercise->getKinestexId();
  169.             $this->exerciseType = $kinestexExercise->getType();
  170.         }
  171.         
  172.         return $this;
  173.     }
  174.     public function getExerciseType(): ?string
  175.     {
  176.         return $this->exerciseType;
  177.     }
  178.     public function setExerciseType(string $exerciseType): self
  179.     {
  180.         $this->exerciseType = $exerciseType;
  181.         return $this;
  182.     }
  183.     public function getExerciseId(): ?string
  184.     {
  185.         return $this->exerciseId;
  186.     }
  187.     public function setExerciseId(?string $exerciseId): self
  188.     {
  189.         $this->exerciseId = $exerciseId;
  190.         return $this;
  191.     }
  192.     // ... reste des getters/setters inchangés ...
  193.     public function getRepsCompleted(): ?int
  194.     {
  195.         return $this->repsCompleted;
  196.     }
  197.     public function setRepsCompleted(?int $repsCompleted): self
  198.     {
  199.         $this->repsCompleted = $repsCompleted;
  200.         return $this;
  201.     }
  202.     public function getDurationSeconds(): ?int
  203.     {
  204.         return $this->durationSeconds;
  205.     }
  206.     public function setDurationSeconds(?int $durationSeconds): self
  207.     {
  208.         $this->durationSeconds = $durationSeconds;
  209.         return $this;
  210.     }
  211.     public function getCaloriesBurned(): ?float
  212.     {
  213.         return $this->caloriesBurned ? (float) $this->caloriesBurned : null;
  214.     }
  215.     public function setCaloriesBurned(?float $caloriesBurned): self
  216.     {
  217.         $this->caloriesBurned = $caloriesBurned;
  218.         return $this;
  219.     }
  220.     public function getAccuracyScore(): ?float
  221.     {
  222.         return $this->accuracyScore ? (float) $this->accuracyScore : null;
  223.     }
  224.     public function setAccuracyScore(?float $accuracyScore): self
  225.     {
  226.         $this->accuracyScore = $accuracyScore;
  227.         return $this;
  228.     }
  229.     public function getCompletionPercentage(): ?float
  230.     {
  231.         return $this->completionPercentage ? (float) $this->completionPercentage : null;
  232.     }
  233.     public function setCompletionPercentage(?float $completionPercentage): self
  234.     {
  235.         $this->completionPercentage = $completionPercentage;
  236.         return $this;
  237.     }
  238.     public function getLogDate(): ?\DateTimeInterface
  239.     {
  240.         return $this->logDate;
  241.     }
  242.     public function setLogDate(\DateTimeInterface $logDate): self
  243.     {
  244.         $this->logDate = $logDate;
  245.         return $this;
  246.     }
  247.     public function getSource(): ?string
  248.     {
  249.         return $this->source;
  250.     }
  251.     public function setSource(?string $source): self
  252.     {
  253.         $this->source = $source;
  254.         return $this;
  255.     }
  256.     public function getRawData(): ?array
  257.     {
  258.         return $this->rawData;
  259.     }
  260.     public function setRawData(?array $rawData): self
  261.     {
  262.         $this->rawData = $rawData;
  263.         return $this;
  264.     }
  265.     public function getCreatedAt(): ?\DateTimeInterface
  266.     {
  267.         return $this->createdAt;
  268.     }
  269.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  270.     {
  271.         $this->createdAt = $createdAt;
  272.         return $this;
  273.     }
  274.     public function getUpdatedAt(): ?\DateTimeInterface
  275.     {
  276.         return $this->updatedAt;
  277.     }
  278.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  279.     {
  280.         $this->updatedAt = $updatedAt;
  281.         return $this;
  282.     }
  283. }