src/Entity/HousingCertificate.php line 15

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\HousingCertificateRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. #[ORM\Entity(repositoryClassHousingCertificateRepository::class)]
  11. #[Vich\Uploadable]
  12. class HousingCertificate
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\ManyToOne(targetEntityUser::class, inversedBy'housingCertificates')]
  19.     #[ORM\JoinColumn(nullablefalse)]
  20.     private ?User $user null;
  21.     #[ORM\Column(length255nullabletrue)]
  22.     private ?string $city null;
  23.     #[ORM\Column(length255nullabletrue)]
  24.     private ?string $nationality null;
  25.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  26.     private ?\DateTimeInterface $refusedAt null;
  27.     #[ORM\Column(length255nullabletrue)]
  28.     private ?string $countryDelivery null;
  29.     #[ORM\Column(length255nullabletrue)]
  30.     private ?string $issuingConsulate null;
  31.     #[ORM\Column(length255nullabletrue)]
  32.     private ?string $type null;
  33.     #[Vich\UploadableField(mapping"departureCertificate_housing_file"fileNameProperty"departureCertificateName")]
  34.     private ?File $pictureCertificate null;
  35.     #[ORM\Column(length255nullabletrue)]
  36.     private ?string $departureCertificateName null;
  37.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  38.     private ?\DateTimeInterface $uploadedAt null;
  39.     #[ORM\Column(nullabletrue)]
  40.     private ?bool $isBlock null;
  41.     #[ORM\Column(length255nullabletrue)]
  42.     private ?string $civility null;
  43.     #[ORM\Column(type"boolean"nullabletrue)]
  44.     private ?bool $approved false;
  45.     #[ORM\Column(length255nullabletrue)]
  46.     private ?string $lastName null;
  47.     #[ORM\Column(length255nullabletrue)]
  48.     private ?string $firstName null;
  49.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  50.     private ?\DateTimeInterface $birthDate null;
  51.     #[ORM\Column(length255nullabletrue)]
  52.     private ?string $passportNumber null;
  53.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  54.     private ?\DateTimeInterface $startDate null;
  55.     #[ORM\Column(nullabletrue)]
  56.     private ?bool $isPaid null;
  57.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  58.     private ?\DateTimeInterface $createdAt null;
  59.     #[ORM\ManyToMany(targetEntityResidence::class, inversedBy'housingCertificates')]
  60.     private Collection $residence;
  61.     #[ORM\ManyToMany(targetEntityBuilding::class, inversedBy'housingCertificates')]
  62.     private Collection $building;
  63.     #[ORM\Column(length255)]
  64.     private ?string $identifierString null;
  65.     #[ORM\Column(length255nullabletrue)]
  66.     private ?string $school null;
  67.     #[ORM\Column(length255nullabletrue)]
  68.     private ?string $numberId null;
  69.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  70.     private ?\DateTimeInterface $passportExpiryAt null;
  71.     #[ORM\Column(length255nullabletrue)]
  72.     private ?string $email null;
  73.     #[ORM\Column(nullabletrue)]
  74.     private ?int $idFirstBuilding null;
  75.     #[ORM\Column]
  76.     private ?bool $notCB null;
  77.     #[ORM\Column(nullabletrue)]
  78.     private ?bool $asPaymentArrival null;
  79.     #[ORM\Column(nullablefalse)]
  80.     private ?bool $isSendToConsulat false;
  81.     #[ORM\Column(length255nullabletrue)]
  82.     private ?string $linkId null;
  83.     #[ORM\Column(length255nullabletrue)]
  84.     private ?string $source null;
  85.     #[ORM\OneToMany(mappedBy'housingCertificate'targetEntityDocument::class)]
  86.     private Collection $documents;
  87.     #[ORM\Column(type'boolean'nullabletrue)]
  88.     private ?bool $isCredit null;
  89.     public function getIsCredit(): ?bool
  90.     {
  91.         return $this->isCredit;
  92.     }
  93.     public function setIsCredit(?bool $isCredit): self
  94.     {
  95.         $this->isCredit $isCredit;
  96.         return $this;
  97.     }
  98.     public function __construct()
  99.     {
  100.         $this->createdAt = new \DateTime();
  101.         $this->residence = new ArrayCollection();
  102.         $this->building = new ArrayCollection();
  103.         $this->documents = new ArrayCollection();
  104.     }
  105.     public function getExportData(): array
  106.     {
  107.         return [
  108.             [
  109.                 'ID' => $this->id,
  110.                 'User' => $this->user $this->user->getFullName() : '',
  111.                 'City' => $this->city,
  112.                 'Nationality' => $this->nationality,
  113.                 'Refused At' => $this->refusedAt $this->refusedAt->format('d/m/Y') : '',
  114.                 'Country Delivery' => $this->countryDelivery,
  115.                 'Issuing Consulate' => $this->issuingConsulate,
  116.                 'Type' => $this->type,
  117.                 'Is Block' => $this->isBlock 'Yes' 'No',
  118.                 'Civility' => $this->civility,
  119.                 'Last Name' => $this->lastName,
  120.                 'First Name' => $this->firstName,
  121.                 'Birth Date' => $this->birthDate $this->birthDate->format('d/m/Y') : '',
  122.                 'Passport Number' => $this->passportNumber,
  123.                 'Start Date' => $this->startDate $this->startDate->format('d/m/Y') : '',
  124.                 'Is Paid' => $this->isPaid 'Yes' 'No',
  125.                 'Created At' => $this->createdAt $this->createdAt->format('d/m/Y') : '',
  126.                 'Residence' => implode(', '$this->residence->map(fn ($res) => $res->getName())->toArray()),
  127.                 'Building' => implode(', '$this->building->map(fn ($build) => $build->getName())->toArray()),
  128.                 'Identifier String' => $this->identifierString,
  129.                 'School' => $this->school,
  130.                 'Number ID' => $this->numberId,
  131.                 'Passport Expiry At' => $this->passportExpiryAt $this->passportExpiryAt->format('d/m/Y') : '',
  132.                 'Email' => $this->email,
  133.                 'ID First Building' => $this->idFirstBuilding,
  134.                 'Not CB' => $this->notCB 'Yes' 'No',
  135.                 'As Payment Arrival' => $this->asPaymentArrival 'Yes' 'No',
  136.             ]
  137.         ];
  138.     }
  139.     // Add the exportToCSV method
  140.     public function exportToCSV($filename): void
  141.     {
  142.         $exportData $this->getExportData();
  143.         $file fopen($filename'w');
  144.         fputcsv($filearray_keys($exportData[0])); // Write the CSV header
  145.         foreach ($exportData as $data) {
  146.             fputcsv($file$data); // Write each row of data
  147.         }
  148.         fclose($file);
  149.     }
  150.     public function getLinkId(): ?string
  151.     {
  152.         return $this->linkId;
  153.     }
  154.     public function setLinkId(?string $linkId): self
  155.     {
  156.         $this->linkId $linkId;
  157.         return $this;
  158.     }
  159.     public function getSource(): ?string
  160.     {
  161.         return $this->source;
  162.     }
  163.     public function setSource(?string $source): self
  164.     {
  165.         $this->source $source;
  166.         return $this;
  167.     }
  168.     public function getId(): ?int
  169.     {
  170.         return $this->id;
  171.     }
  172.     public function getUser(): ?User
  173.     {
  174.         return $this->user;
  175.     }
  176.     public function setUser(?User $user): self
  177.     {
  178.         $this->user $user;
  179.         return $this;
  180.     }
  181.     public function getCity(): ?string
  182.     {
  183.         return $this->city;
  184.     }
  185.     public function setCity(?string $city): self
  186.     {
  187.         $this->city $city;
  188.         return $this;
  189.     }
  190.     public function getNationality(): ?string
  191.     {
  192.         return $this->nationality;
  193.     }
  194.     public function setNationality(?string $nationality): self
  195.     {
  196.         $this->nationality $nationality;
  197.         return $this;
  198.     }
  199.     public function getRefusedAt(): ?\DateTimeInterface
  200.     {
  201.         return $this->refusedAt;
  202.     }
  203.     public function setRefusedAt(?\DateTimeInterface $refusedAt): self
  204.     {
  205.         $this->refusedAt $refusedAt;
  206.         return $this;
  207.     }
  208.     public function getCountryDelivery(): ?string
  209.     {
  210.         return $this->countryDelivery;
  211.     }
  212.     public function setCountryDelivery(?string $countryDelivery): self
  213.     {
  214.         $this->countryDelivery $countryDelivery;
  215.         return $this;
  216.     }
  217.     public function getIssuingConsulate(): ?string
  218.     {
  219.         return $this->issuingConsulate;
  220.     }
  221.     public function setIssuingConsulate(?string $issuingConsulate): self
  222.     {
  223.         $this->issuingConsulate $issuingConsulate;
  224.         return $this;
  225.     }
  226.     public function getType(): ?string
  227.     {
  228.         return $this->type;
  229.     }
  230.     public function setType(?string $type): self
  231.     {
  232.         $this->type $type;
  233.         return $this;
  234.     }
  235.     public function getDepartureCertificateName(): ?string
  236.     {
  237.         return $this->departureCertificateName;
  238.     }
  239.     public function setDepartureCertificateName(?string $departureCertificateName): self
  240.     {
  241.         $this->departureCertificateName $departureCertificateName;
  242.         return $this;
  243.     }
  244.     /**
  245.      * @return File|null
  246.      */
  247.     public function getPictureCertificate(): ?File
  248.     {
  249.         return $this->pictureCertificate;
  250.     }
  251.     /**
  252.      * @param File|null $pictureCertificate
  253.      */
  254.     public function setPictureCertificate(?File $pictureCertificate): void
  255.     {
  256.         $this->pictureCertificate $pictureCertificate;
  257.         if ($pictureCertificate) {
  258.             $this->uploadedAt = new \DateTime('now');
  259.         }
  260.     }
  261.     public function isApproved(): bool
  262.     {
  263.         return $this->approved;
  264.     }
  265.     public function approve(): void
  266.     {
  267.         $this->approved true;
  268.     }
  269.     public function getUploadedAt(): ?\DateTimeInterface
  270.     {
  271.         return $this->uploadedAt;
  272.     }
  273.     public function setUploadedAt(?\DateTimeInterface $uploadedAt): self
  274.     {
  275.         $this->uploadedAt $uploadedAt;
  276.         return $this;
  277.     }
  278.     public function isIsBlock(): ?bool
  279.     {
  280.         return $this->isBlock;
  281.     }
  282.     public function setIsBlock(?bool $isBlock): self
  283.     {
  284.         $this->isBlock $isBlock;
  285.         return $this;
  286.     }
  287.     public function getCivility(): ?string
  288.     {
  289.         return $this->civility;
  290.     }
  291.     public function setCivility(?string $civility): self
  292.     {
  293.         $this->civility $civility;
  294.         return $this;
  295.     }
  296.     public function getLastName(): ?string
  297.     {
  298.         return $this->lastName;
  299.     }
  300.     public function setLastName(?string $lastName): self
  301.     {
  302.         $this->lastName $lastName;
  303.         return $this;
  304.     }
  305.     public function getFirstName(): ?string
  306.     {
  307.         return $this->firstName;
  308.     }
  309.     public function setFirstName(?string $firstName): self
  310.     {
  311.         $this->firstName $firstName;
  312.         return $this;
  313.     }
  314.     public function getBirthDate(): ?\DateTimeInterface
  315.     {
  316.         return $this->birthDate;
  317.     }
  318.     public function setBirthDate(?\DateTimeInterface $birthDate): self
  319.     {
  320.         $this->birthDate $birthDate;
  321.         return $this;
  322.     }
  323.     public function getPassportNumber(): ?string
  324.     {
  325.         return $this->passportNumber;
  326.     }
  327.     public function setPassportNumber(?string $passportNumber): self
  328.     {
  329.         $this->passportNumber $passportNumber;
  330.         return $this;
  331.     }
  332.     public function getStartDate(): ?\DateTimeInterface
  333.     {
  334.         return $this->startDate;
  335.     }
  336.     public function setStartDate(?\DateTimeInterface $startDate): self
  337.     {
  338.         $this->startDate $startDate;
  339.         return $this;
  340.     }
  341.     public function isIsPaid(): ?bool
  342.     {
  343.         return $this->isPaid;
  344.     }
  345.     public function setIsPaid(?bool $isPaid): self
  346.     {
  347.         $this->isPaid $isPaid;
  348.         return $this;
  349.     }
  350.     public function getCreatedAt(): ?\DateTimeInterface
  351.     {
  352.         return $this->createdAt;
  353.     }
  354.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  355.     {
  356.         $this->createdAt $createdAt;
  357.         return $this;
  358.     }
  359.     /**
  360.      * @return Collection<int, Residence>
  361.      */
  362.     public function getResidence(): Collection
  363.     {
  364.         return $this->residence;
  365.     }
  366.     public function addResidence(Residence $residence): self
  367.     {
  368.         if (!$this->residence->contains($residence)) {
  369.             $this->residence->add($residence);
  370.         }
  371.         return $this;
  372.     }
  373.     public function removeResidence(Residence $residence): self
  374.     {
  375.         $this->residence->removeElement($residence);
  376.         return $this;
  377.     }
  378.     /**
  379.      * @return Collection<int, Building>
  380.      */
  381.     public function getBuilding(): Collection
  382.     {
  383.         return $this->building;
  384.     }
  385.     public function addBuilding(Building $building): self
  386.     {
  387.         if (!$this->building->contains($building)) {
  388.             $this->building->add($building);
  389.         }
  390.         return $this;
  391.     }
  392.     public function removeBuilding(Building $building): self
  393.     {
  394.         $this->building->removeElement($building);
  395.         return $this;
  396.     }
  397.     public function getIdentifierString(): ?string
  398.     {
  399.         return $this->identifierString;
  400.     }
  401.     public function setIdentifierString(string $identifierString): self
  402.     {
  403.         $this->identifierString $identifierString;
  404.         return $this;
  405.     }
  406.     public function getSchool(): ?string
  407.     {
  408.         return $this->school;
  409.     }
  410.     public function setSchool(?string $school): self
  411.     {
  412.         $this->school strtoupper($school);
  413.         return $this;
  414.     }
  415.     public function getNumberId(): ?string
  416.     {
  417.         return $this->numberId;
  418.     }
  419.     public function setNumberId(?string $numberId): self
  420.     {
  421.         $this->numberId $numberId;
  422.         return $this;
  423.     }
  424.     public function getPassportExpiryAt(): ?\DateTimeInterface
  425.     {
  426.         return $this->passportExpiryAt;
  427.     }
  428.     public function setPassportExpiryAt(?\DateTimeInterface $passportExpiryAt): self
  429.     {
  430.         $this->passportExpiryAt $passportExpiryAt;
  431.         return $this;
  432.     }
  433.     public function getEmail(): ?string
  434.     {
  435.         return $this->email;
  436.     }
  437.     public function setEmail(?string $email): self
  438.     {
  439.         $this->email $email;
  440.         return $this;
  441.     }
  442.     public function getIdFirstBuilding(): ?int
  443.     {
  444.         return $this->idFirstBuilding;
  445.     }
  446.     public function setIdFirstBuilding(?int $idFirstBuilding): self
  447.     {
  448.         $this->idFirstBuilding $idFirstBuilding;
  449.         return $this;
  450.     }
  451.     public function isNotCB(): ?bool
  452.     {
  453.         return $this->notCB;
  454.     }
  455.     public function setNotCB(bool $notCB): self
  456.     {
  457.         $this->notCB $notCB;
  458.         return $this;
  459.     }
  460.     public function isAsPaymentArrival(): ?bool
  461.     {
  462.         return $this->asPaymentArrival;
  463.     }
  464.     public function setAsPaymentArrival(?bool $asPaymentArrival): self
  465.     {
  466.         $this->asPaymentArrival $asPaymentArrival;
  467.         return $this;
  468.     }
  469.     public function isIsSendToConsulat(): ?bool
  470.     {
  471.         return $this->isSendToConsulat;
  472.     }
  473.     public function setIsSendToConsulat(?bool $isSendToConsulat): self
  474.     {
  475.         $this->isSendToConsulat $isSendToConsulat;
  476.         return $this;
  477.     }
  478.     /**
  479.      * @return Collection<int, Document>
  480.      */
  481.     public function getDocuments(): Collection
  482.     {
  483.         return $this->documents;
  484.     }
  485.     public function addDocument(Document $document): self
  486.     {
  487.         if (!$this->documents->contains($document)) {
  488.             $this->documents[] = $document;
  489.             $document->setHousingCertificate($this);
  490.         }
  491.     
  492.         return $this;
  493.     }
  494.     public function removeDocument(Document $document): self
  495.     {
  496.         if ($this->documents->removeElement($document)) {
  497.             // set the owning side to null (unless already changed)
  498.             if ($document->getHousingCertificate() === $this) {
  499.                 $document->setHousingCertificate(null);
  500.             }
  501.         }
  502.         return $this;
  503.     }
  504. }