<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\CommandeFormationRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CommandeFormationRepository::class)]
#[ApiResource]
class CommandeFormation
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'commandeFormations')]
private ?Commande $commande = null;
#[ORM\ManyToOne(inversedBy: 'commandeFormations')]
private ?FormationElearning $formation = null;
#[ORM\ManyToOne(inversedBy: 'commandeFormations')]
private ?Pack $pack = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $type = null;
public function getId(): ?int
{
return $this->id;
}
public function getCommande(): ?Commande
{
return $this->commande;
}
public function setCommande(?Commande $commande): self
{
$this->commande = $commande;
return $this;
}
public function getFormation(): ?FormationElearning
{
return $this->formation;
}
public function setFormation(?FormationElearning $formation): self
{
$this->formation = $formation;
return $this;
}
public function getPack(): ?Pack
{
return $this->pack;
}
public function setPack(?Pack $pack): self
{
$this->pack = $pack;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
// Méthode utilitaire pour obtenir l'élément (formation ou pack)
public function getItem()
{
return $this->type === 'pack' ? $this->pack : $this->formation;
}
// Méthode pour obtenir le nom de l'élément
public function getItemName(): ?string
{
if ($this->type === 'pack' && $this->pack) {
return $this->pack->getLibelle();
} elseif ($this->type === 'formation' && $this->formation) {
return $this->formation->getTitre();
}
return null;
}
}