<?phpnamespace App\Entity;use App\Repository\PieceJointeTicketRepository;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: PieceJointeTicketRepository::class)]class PieceJointeTicket{ #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\ManyToOne(inversedBy: 'piecesJointes')] #[ORM\JoinColumn(nullable: false)] private ?Ticket $ticket = null; #[ORM\Column(length: 255)] private ?string $nomFichier = null; #[ORM\Column(length: 255)] private ?string $cheminFichier = null; #[ORM\Column(length: 100, nullable: true)] private ?string $typeFichier = null; #[ORM\Column(nullable: true)] private ?int $tailleFichier = null; // en octets #[ORM\ManyToOne(targetEntity: User::class)] #[ORM\JoinColumn(nullable: false)] private ?User $uploadedBy = null; #[ORM\Column] private ?\DateTimeImmutable $uploadedAt = null; public function __construct() { $this->uploadedAt = new \DateTimeImmutable(); } public function getId(): ?int { return $this->id; } public function getTicket(): ?Ticket { return $this->ticket; } public function setTicket(?Ticket $ticket): static { $this->ticket = $ticket; return $this; } public function getNomFichier(): ?string { return $this->nomFichier; } public function setNomFichier(string $nomFichier): static { $this->nomFichier = $nomFichier; return $this; } public function getCheminFichier(): ?string { return $this->cheminFichier; } public function setCheminFichier(string $cheminFichier): static { $this->cheminFichier = $cheminFichier; return $this; } public function getTypeFichier(): ?string { return $this->typeFichier; } public function setTypeFichier(?string $typeFichier): static { $this->typeFichier = $typeFichier; return $this; } public function getTailleFichier(): ?int { return $this->tailleFichier; } public function setTailleFichier(?int $tailleFichier): static { $this->tailleFichier = $tailleFichier; return $this; } public function getUploadedBy(): ?User { return $this->uploadedBy; } public function setUploadedBy(?User $uploadedBy): static { $this->uploadedBy = $uploadedBy; return $this; } public function getUploadedAt(): ?\DateTimeImmutable { return $this->uploadedAt; } public function setUploadedAt(\DateTimeImmutable $uploadedAt): static { $this->uploadedAt = $uploadedAt; return $this; } public function getTailleFormatee(): string { if (!$this->tailleFichier) { return '0 B'; } $units = ['B', 'KB', 'MB', 'GB']; $taille = $this->tailleFichier; $unitIndex = 0; while ($taille >= 1024 && $unitIndex < count($units) - 1) { $taille /= 1024; $unitIndex++; } return round($taille, 2) . ' ' . $units[$unitIndex]; } public function __toString(): string { return $this->nomFichier ?? 'Fichier'; }}