src/Entity/RefusedVisa.php line 14

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RefusedVisaRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\HttpFoundation\File\File;
  7. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  8. use League\Csv\Writer;
  9. #[ORM\Entity(repositoryClassRefusedVisaRepository::class)]
  10. #[Vich\Uploadable]
  11. class RefusedVisa
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\ManyToOne(inversedBy'refusedVisas')]
  18.     private ?User $user null;
  19.     #[ORM\Column(length255nullabletrue)]
  20.     private ?string $city null;
  21.     #[ORM\Column(length255nullabletrue)]
  22.     private ?string $nationality null;
  23.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  24.     private ?\DateTimeInterface $refusedAt null;
  25.     #[ORM\Column(length255nullabletrue)]
  26.     private ?string $countryDelivery null;
  27.     #[ORM\Column(length255nullabletrue)]
  28.     private ?string $issuingConsulate null;
  29.     #[ORM\Column(length255nullabletrue)]
  30.     private ?string $type null;
  31.     #[Vich\UploadableField(mapping"departureCertificate_file"fileNameProperty"departureCertificateName")]
  32.     private ?File $pictureCertificate null;
  33.     #[ORM\Column(length255nullabletrue)]
  34.     private ?string $departureCertificateName null;
  35.     #[Vich\UploadableField(mapping"denialNotification_file"fileNameProperty"denialNotificationName")]
  36.     private ?File $pictureNotification null;
  37.     #[ORM\Column(length255nullabletrue)]
  38.     private ?string $denialNotificationName null;
  39.     #[ORM\Column(type'datetime'nullabletrue)]
  40.     private ?\DateTimeInterface $uploadedAt null;
  41.     public function __construct()
  42.     {
  43.         $this->uploadedAt = new \DateTime();
  44.     }
  45.     public function getExportData(): array
  46.     {
  47.         return [
  48.             [
  49.                 'ID' => $this->id,
  50.                 'Nom et Prénom' => $this->user,
  51.                 'Nationalité' => $this->nationality,
  52.                 'Type' => $this->type,
  53.                 'City' => $this->city,
  54.                 'Refusé le' => $this->refusedAt $this->refusedAt->format('d/m/Y') : '',
  55.                 'Pays de Délivrance du Visa' => $this->countryDelivery,
  56.                 'Consulat' => $this->issuingConsulate,
  57.                 'Certificat de Départ' => $this->departureCertificateName "https://roomlers.com/images/files/" $this->departureCertificateName '',
  58.                 'Certificat de Refus' => $this->denialNotificationName "https://roomlers.com/images/files/" $this->denialNotificationName '',
  59.                 'Ajouté le' => $this->uploadedAt $this->uploadedAt->format('d/m/Y H:i:s') : '',
  60.             ]
  61.         ];
  62.     }
  63.     
  64.     public function exportToCSV($filename): void
  65.     {
  66.         $exportData $this->getExportData();
  67.     
  68.         $file fopen($filename'w');
  69.         fputcsv($filearray_keys($exportData[0])); // Write the CSV header
  70.     
  71.         foreach ($exportData as $data) {
  72.             fputcsv($file$data); // Write each row of data
  73.         }
  74.     
  75.         fclose($file);
  76.     }
  77.     
  78.     public function getId(): ?int
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function getUser(): ?User
  83.     {
  84.         return $this->user;
  85.     }
  86.     public function setUser(?User $user): self
  87.     {
  88.         $this->user $user;
  89.         return $this;
  90.     }
  91.     public function getCity(): ?string
  92.     {
  93.         return $this->city;
  94.     }
  95.     public function setCity(?string $city): self
  96.     {
  97.         $this->city $city;
  98.         return $this;
  99.     }
  100.     public function getNationality(): ?string
  101.     {
  102.         return $this->nationality;
  103.     }
  104.     public function setNationality(?string $nationality): self
  105.     {
  106.         $this->nationality $nationality;
  107.         return $this;
  108.     }
  109.     public function getRefusedAt(): ?\DateTimeInterface
  110.     {
  111.         return $this->refusedAt;
  112.     }
  113.     public function setRefusedAt(?\DateTimeInterface $refusedAt): self
  114.     {
  115.         $this->refusedAt $refusedAt;
  116.         return $this;
  117.     }
  118.     public function getCountryDelivery(): ?string
  119.     {
  120.         return $this->countryDelivery;
  121.     }
  122.     public function setCountryDelivery(?string $countryDelivery): self
  123.     {
  124.         $this->countryDelivery $countryDelivery;
  125.         return $this;
  126.     }
  127.     public function getIssuingConsulate(): ?string
  128.     {
  129.         return $this->issuingConsulate;
  130.     }
  131.     public function setIssuingConsulate(?string $issuingConsulate): self
  132.     {
  133.         $this->issuingConsulate $issuingConsulate;
  134.         return $this;
  135.     }
  136.     public function getType(): ?string
  137.     {
  138.         return $this->type;
  139.     }
  140.     public function setType(?string $type): self
  141.     {
  142.         $this->type $type;
  143.         return $this;
  144.     }
  145.     public function getDepartureCertificateName(): ?string
  146.     {
  147.         return $this->departureCertificateName;
  148.     }
  149.     public function setDepartureCertificateName(?string $departureCertificateName): self
  150.     {
  151.         $this->departureCertificateName $departureCertificateName;
  152.         return $this;
  153.     }
  154.     public function getDenialNotificationName(): ?string
  155.     {
  156.         return $this->denialNotificationName;
  157.     }
  158.     public function setDenialNotificationName(?string $denialNotificationName): self
  159.     {
  160.         $this->denialNotificationName $denialNotificationName;
  161.         return $this;
  162.     }
  163.     /**
  164.      * @return File|null
  165.      */
  166.     public function getPictureCertificate(): ?File
  167.     {
  168.         return $this->pictureCertificate;
  169.     }
  170.     /**
  171.      * @param File|null $pictureCertificate
  172.      */
  173.     public function setPictureCertificate(?File $pictureCertificate): void
  174.     {
  175.         $this->pictureCertificate $pictureCertificate;
  176.         if ($pictureCertificate) {
  177.             $this->uploadedAt = new \DateTime('now');
  178.         }
  179.     }
  180.     /**
  181.      * @return File|null
  182.      */
  183.     public function getPictureNotification(): ?File
  184.     {
  185.         return $this->pictureNotification;
  186.     }
  187.     /**
  188.      * @param File|null $pictureNotification
  189.      */
  190.     public function setPictureNotification(?File $pictureNotification): void
  191.     {
  192.         $this->pictureNotification $pictureNotification;
  193.         if ($pictureNotification) {
  194.             $this->uploadedAt = new \DateTime('now');
  195.         }
  196.     }
  197.     /**
  198.      * @return \DateTimeInterface|null
  199.      */
  200.     public function getUploadedAt(): ?\DateTimeInterface
  201.     {
  202.         return $this->uploadedAt;
  203.     }
  204.     /**
  205.      * @param \DateTimeInterface|null $uploadedAt
  206.      */
  207.     public function setUploadedAt(?\DateTimeInterface $uploadedAt): void
  208.     {
  209.         $this->uploadedAt $uploadedAt;
  210.     }
  211. }