<?php
namespace App\Entity;
use App\Repository\WorkoutTemplateRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: WorkoutTemplateRepository::class)]
#[ORM\HasLifecycleCallbacks]
class WorkoutTemplate
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $description = null;
#[ORM\Column(nullable: true)]
private ?array $exercises = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $versionHash = null;
#[ORM\Column(nullable: true)]
private ?int $calories = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $image = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $targetArea = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $level = null;
#[ORM\Column(type: "json")]
private array $equipment = [];
#[ORM\Column(nullable: true)]
private ?int $moduleType = null;
public function __construct()
{
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): static
{
$this->description = $description;
return $this;
}
public function getExercises()
{
return json_encode($this->exercises);
}
public function setExercises($exercises): static
{
$this->exercises = json_decode(json_encode($exercises), true);
return $this;
}
public function __toString(): string
{
return $this->getName() . ' (' . $this->getId() . ')';
}
public function getVersionHash(): ?string
{
return $this->versionHash;
}
public function setVersionHash(?string $versionHash): static
{
$this->versionHash = $versionHash;
return $this;
}
#[ORM\PrePersist]
#[ORM\PreUpdate]
public function updateVersionHash(): void
{
$data = $this->serializePropertiesForHash();
$this->versionHash = md5($data);
}
private function serializePropertiesForHash(): string
{
return serialize([
$this->name,
$this->description,
$this->exercises
]);
}
public function getCalories(): ?int
{
return $this->calories;
}
public function setCalories(?int $calories): static
{
$this->calories = $calories;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): static
{
$this->image = $image;
return $this;
}
public function getTargetArea(): ?string
{
return $this->targetArea;
}
public function setTargetArea(?string $targetArea): static
{
$this->targetArea = $targetArea;
return $this;
}
public function getLevel(): ?string
{
return $this->level;
}
public function setLevel(?string $level): static
{
$this->level = $level;
return $this;
}
public function getEquipment(): array
{
return $this->equipment;
}
public function setEquipment(array $equipment): static
{
$this->equipment = $equipment;
return $this;
}
public function getModuleType(): ?int
{
return $this->moduleType;
}
public function setModuleType(?int $moduleType): static
{
$this->moduleType = $moduleType;
return $this;
}
}