src/Entity/KinestexExercise.php line 43

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\BooleanFilter;
  7. use App\Repository\KinestexExerciseRepository;
  8. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  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_exercise:read"}},
  15.  *      denormalizationContext={"groups"={"kinestex_exercise:write"}},
  16.  *      collectionOperations={
  17.  *          "get"={
  18.  *              "security"="is_granted('ROLE_USER')",
  19.  *              "pagination_enabled"=true,
  20.  *              "pagination_items_per_page"=10,
  21.  *              "pagination_client_enabled"=true,
  22.  *              "pagination_client_items_per_page"=true
  23.  *          },
  24.  *          "post"={"security"="is_granted('ROLE_ADMIN')"}
  25.  *      },
  26.  *      itemOperations={
  27.  *          "get"={"security"="is_granted('ROLE_USER')"},
  28.  *          "put"={"security"="is_granted('ROLE_ADMIN')"},
  29.  *          "delete"={"security"="is_granted('ROLE_ADMIN')"}
  30.  *      }
  31.  * )
  32.  * @ApiFilter(SearchFilter::class, properties={
  33.  *     "name": "ipartial",
  34.  *     "type": "exact",
  35.  *     "kinestexId": "ipartial"
  36.  * })
  37.  * @ApiFilter(BooleanFilter::class, properties={"active"})
  38.  * @ORM\Entity(repositoryClass=KinestexExerciseRepository::class)
  39.  */
  40. class KinestexExercise
  41. {
  42.     const TYPE_REPETITION = 'repetition';
  43.     const TYPE_DURATION = 'duration';
  44.     /**
  45.      * @ORM\Id
  46.      * @ORM\GeneratedValue
  47.      * @ORM\Column(type="integer")
  48.      * @Groups({"kinestex_exercise:read", "teamplay_challenge:read", "kinestex_log:read"})     
  49.      * */
  50.     private $id;
  51.     /**
  52.      * Nom de l'exercice
  53.      * @ORM\Column(type="string", length=100)
  54.      * @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read", "kinestex_log:read"})
  55.      */
  56.     private $name;
  57.     /**
  58.      * ID de l'exercice dans KinesteX (le token important !)
  59.      * @ORM\Column(type="string", length=100, unique=true)
  60.      * @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read", "kinestex_log:read"})
  61.      */
  62.     private $kinestexId;
  63.     /**
  64.      * Type d'exercice : repetition ou duration
  65.      * @ORM\Column(type="string", length=20)
  66.      * @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read", "kinestex_log:read"})
  67.      */
  68.     private $type;
  69.     /**
  70.      * Description de l'exercice
  71.      * @ORM\Column(type="text", nullable=true)
  72.      * @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read"})
  73.      */
  74.     private $description;
  75.     /**
  76.      * Image de l'exercice
  77.      * @ORM\Column(type="string", length=255, nullable=true)
  78.      * @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read"})
  79.      */
  80.     private $image;
  81.     /**
  82.      * Valeur par défaut pour les répétitions (si type = repetition)
  83.      * @ORM\Column(type="integer", nullable=true)
  84.      * @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read"})
  85.      */
  86.     private $defaultRepetitions;
  87.     /**
  88.      * Valeur par défaut pour la durée en secondes (si type = duration)
  89.      * @ORM\Column(type="integer", nullable=true)
  90.      * @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read"})
  91.      */
  92.     private $defaultDuration;
  93.     /**
  94.      * Actif/Inactif
  95.      * @ORM\Column(type="boolean", options={"default": true})
  96.      * @Groups({"kinestex_exercise:read", "kinestex_exercise:write"})
  97.      */
  98.     private $active = true;
  99.     /**
  100.      * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  101.      * @Gedmo\Timestampable(on="create")
  102.      * @Groups({"kinestex_exercise:read"})
  103.      */
  104.     private $createdAt;
  105.     /**
  106.      * @ORM\Column(type="datetime", nullable=true)
  107.      * @Gedmo\Timestampable(on="update")
  108.      * @Groups({"kinestex_exercise:read"})
  109.      */
  110.     private $updatedAt;
  111.     // ... reste du code inchangé ...
  112.     public function getId(): ?int
  113.     {
  114.         return $this->id;
  115.     }
  116.     public function getName(): ?string
  117.     {
  118.         return $this->name;
  119.     }
  120.     public function setName(string $name): self
  121.     {
  122.         $this->name = $name;
  123.         return $this;
  124.     }
  125.     public function getKinestexId(): ?string
  126.     {
  127.         return $this->kinestexId;
  128.     }
  129.     public function setKinestexId(string $kinestexId): self
  130.     {
  131.         $this->kinestexId = $kinestexId;
  132.         return $this;
  133.     }
  134.     public function getType(): ?string
  135.     {
  136.         return $this->type;
  137.     }
  138.     public function setType(string $type): self
  139.     {
  140.         $this->type = $type;
  141.         return $this;
  142.     }
  143.     public function getDescription(): ?string
  144.     {
  145.         return $this->description;
  146.     }
  147.     public function setDescription(?string $description): self
  148.     {
  149.         $this->description = $description;
  150.         return $this;
  151.     }
  152.     public function getImage(): ?string
  153.     {
  154.         return $this->image;
  155.     }
  156.     public function setImage(?string $image): self
  157.     {
  158.         $this->image = $image;
  159.         return $this;
  160.     }
  161.     public function getDefaultRepetitions(): ?int
  162.     {
  163.         return $this->defaultRepetitions;
  164.     }
  165.     public function setDefaultRepetitions(?int $defaultRepetitions): self
  166.     {
  167.         $this->defaultRepetitions = $defaultRepetitions;
  168.         return $this;
  169.     }
  170.     public function getDefaultDuration(): ?int
  171.     {
  172.         return $this->defaultDuration;
  173.     }
  174.     public function setDefaultDuration(?int $defaultDuration): self
  175.     {
  176.         $this->defaultDuration = $defaultDuration;
  177.         return $this;
  178.     }
  179.     public function getActive(): ?bool
  180.     {
  181.         return $this->active;
  182.     }
  183.     public function setActive(bool $active): self
  184.     {
  185.         $this->active = $active;
  186.         return $this;
  187.     }
  188.     public function getCreatedAt(): ?\DateTimeInterface
  189.     {
  190.         return $this->createdAt;
  191.     }
  192.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  193.     {
  194.         $this->createdAt = $createdAt;
  195.         return $this;
  196.     }
  197.     public function getUpdatedAt(): ?\DateTimeInterface
  198.     {
  199.         return $this->updatedAt;
  200.     }
  201.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  202.     {
  203.         $this->updatedAt = $updatedAt;
  204.         return $this;
  205.     }
  206.     public function isRepetitionType(): bool
  207.     {
  208.         return $this->type === self::TYPE_REPETITION;
  209.     }
  210.     public function isDurationType(): bool
  211.     {
  212.         return $this->type === self::TYPE_DURATION;
  213.     }
  214.     public function __toString(): string
  215.     {
  216.         return $this->name ?: '';
  217.     }
  218. }