src/Entity/PieceJointeTicket.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PieceJointeTicketRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. #[ORM\Entity(repositoryClassPieceJointeTicketRepository::class)]
  6. class PieceJointeTicket
  7. {
  8.     #[ORM\Id]
  9.     #[ORM\GeneratedValue]
  10.     #[ORM\Column]
  11.     private ?int $id null;
  12.     #[ORM\ManyToOne(inversedBy'piecesJointes')]
  13.     #[ORM\JoinColumn(nullablefalse)]
  14.     private ?Ticket $ticket null;
  15.     #[ORM\Column(length255)]
  16.     private ?string $nomFichier null;
  17.     #[ORM\Column(length255)]
  18.     private ?string $cheminFichier null;
  19.     #[ORM\Column(length100nullabletrue)]
  20.     private ?string $typeFichier null;
  21.     #[ORM\Column(nullabletrue)]
  22.     private ?int $tailleFichier null// en octets
  23.     #[ORM\ManyToOne(targetEntityUser::class)]
  24.     #[ORM\JoinColumn(nullablefalse)]
  25.     private ?User $uploadedBy null;
  26.     #[ORM\Column]
  27.     private ?\DateTimeImmutable $uploadedAt null;
  28.     public function __construct()
  29.     {
  30.         $this->uploadedAt = new \DateTimeImmutable();
  31.     }
  32.     public function getId(): ?int
  33.     {
  34.         return $this->id;
  35.     }
  36.     public function getTicket(): ?Ticket
  37.     {
  38.         return $this->ticket;
  39.     }
  40.     public function setTicket(?Ticket $ticket): static
  41.     {
  42.         $this->ticket $ticket;
  43.         return $this;
  44.     }
  45.     public function getNomFichier(): ?string
  46.     {
  47.         return $this->nomFichier;
  48.     }
  49.     public function setNomFichier(string $nomFichier): static
  50.     {
  51.         $this->nomFichier $nomFichier;
  52.         return $this;
  53.     }
  54.     public function getCheminFichier(): ?string
  55.     {
  56.         return $this->cheminFichier;
  57.     }
  58.     public function setCheminFichier(string $cheminFichier): static
  59.     {
  60.         $this->cheminFichier $cheminFichier;
  61.         return $this;
  62.     }
  63.     public function getTypeFichier(): ?string
  64.     {
  65.         return $this->typeFichier;
  66.     }
  67.     public function setTypeFichier(?string $typeFichier): static
  68.     {
  69.         $this->typeFichier $typeFichier;
  70.         return $this;
  71.     }
  72.     public function getTailleFichier(): ?int
  73.     {
  74.         return $this->tailleFichier;
  75.     }
  76.     public function setTailleFichier(?int $tailleFichier): static
  77.     {
  78.         $this->tailleFichier $tailleFichier;
  79.         return $this;
  80.     }
  81.     public function getUploadedBy(): ?User
  82.     {
  83.         return $this->uploadedBy;
  84.     }
  85.     public function setUploadedBy(?User $uploadedBy): static
  86.     {
  87.         $this->uploadedBy $uploadedBy;
  88.         return $this;
  89.     }
  90.     public function getUploadedAt(): ?\DateTimeImmutable
  91.     {
  92.         return $this->uploadedAt;
  93.     }
  94.     public function setUploadedAt(\DateTimeImmutable $uploadedAt): static
  95.     {
  96.         $this->uploadedAt $uploadedAt;
  97.         return $this;
  98.     }
  99.     public function getTailleFormatee(): string
  100.     {
  101.         if (!$this->tailleFichier) {
  102.             return '0 B';
  103.         }
  104.         
  105.         $units = ['B''KB''MB''GB'];
  106.         $taille $this->tailleFichier;
  107.         $unitIndex 0;
  108.         
  109.         while ($taille >= 1024 && $unitIndex count($units) - 1) {
  110.             $taille /= 1024;
  111.             $unitIndex++;
  112.         }
  113.         
  114.         return round($taille2) . ' ' $units[$unitIndex];
  115.     }
  116.     public function __toString(): string
  117.     {
  118.         return $this->nomFichier ?? 'Fichier';
  119.     }
  120. }