<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use App\Repository\KinestexExerciseRepository;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* normalizationContext={"groups"={"kinestex_exercise:read"}},
* denormalizationContext={"groups"={"kinestex_exercise:write"}},
* collectionOperations={
* "get"={
* "security"="is_granted('ROLE_USER')",
* "pagination_enabled"=true,
* "pagination_items_per_page"=10,
* "pagination_client_enabled"=true,
* "pagination_client_items_per_page"=true
* },
* "post"={"security"="is_granted('ROLE_ADMIN')"}
* },
* itemOperations={
* "get"={"security"="is_granted('ROLE_USER')"},
* "put"={"security"="is_granted('ROLE_ADMIN')"},
* "delete"={"security"="is_granted('ROLE_ADMIN')"}
* }
* )
* @ApiFilter(SearchFilter::class, properties={
* "name": "ipartial",
* "type": "exact",
* "kinestexId": "ipartial"
* })
* @ApiFilter(BooleanFilter::class, properties={"active"})
* @ORM\Entity(repositoryClass=KinestexExerciseRepository::class)
*/
class KinestexExercise
{
const TYPE_REPETITION = 'repetition';
const TYPE_DURATION = 'duration';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"kinestex_exercise:read", "teamplay_challenge:read", "kinestex_log:read"})
* */
private $id;
/**
* Nom de l'exercice
* @ORM\Column(type="string", length=100)
* @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read", "kinestex_log:read"})
*/
private $name;
/**
* ID de l'exercice dans KinesteX (le token important !)
* @ORM\Column(type="string", length=100, unique=true)
* @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read", "kinestex_log:read"})
*/
private $kinestexId;
/**
* Type d'exercice : repetition ou duration
* @ORM\Column(type="string", length=20)
* @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read", "kinestex_log:read"})
*/
private $type;
/**
* Description de l'exercice
* @ORM\Column(type="text", nullable=true)
* @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read"})
*/
private $description;
/**
* Image de l'exercice
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read"})
*/
private $image;
/**
* Valeur par défaut pour les répétitions (si type = repetition)
* @ORM\Column(type="integer", nullable=true)
* @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read"})
*/
private $defaultRepetitions;
/**
* Valeur par défaut pour la durée en secondes (si type = duration)
* @ORM\Column(type="integer", nullable=true)
* @Groups({"kinestex_exercise:read", "kinestex_exercise:write", "teamplay_challenge:read"})
*/
private $defaultDuration;
/**
* Actif/Inactif
* @ORM\Column(type="boolean", options={"default": true})
* @Groups({"kinestex_exercise:read", "kinestex_exercise:write"})
*/
private $active = true;
/**
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
* @Gedmo\Timestampable(on="create")
* @Groups({"kinestex_exercise:read"})
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Gedmo\Timestampable(on="update")
* @Groups({"kinestex_exercise:read"})
*/
private $updatedAt;
// ... reste du code inchangé ...
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getKinestexId(): ?string
{
return $this->kinestexId;
}
public function setKinestexId(string $kinestexId): self
{
$this->kinestexId = $kinestexId;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getDefaultRepetitions(): ?int
{
return $this->defaultRepetitions;
}
public function setDefaultRepetitions(?int $defaultRepetitions): self
{
$this->defaultRepetitions = $defaultRepetitions;
return $this;
}
public function getDefaultDuration(): ?int
{
return $this->defaultDuration;
}
public function setDefaultDuration(?int $defaultDuration): self
{
$this->defaultDuration = $defaultDuration;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function isRepetitionType(): bool
{
return $this->type === self::TYPE_REPETITION;
}
public function isDurationType(): bool
{
return $this->type === self::TYPE_DURATION;
}
public function __toString(): string
{
return $this->name ?: '';
}
}