src/Entity/Inscription.php line 15
<?php
namespace App\Entity;
use App\Repository\InscriptionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: InscriptionRepository::class)]
#[Vich\Uploadable]
class Inscription
{
const STATUS_DRAFT = 1;
const STATUS_VALID = 2;
const STATUS_FAILED = 3;
const STATUS_WAITING = 4;
const STATUS_REFUSED = 5; // ce status est ajouté pour le caas de refus d'administrateur
const STATUS_PAYMENT_PENDING = "Pending";
const STATUS_PAYMENT_SUCCESS = "Success";
const STATUS_PAYMENT_FAILED = "Failed";
const SEXE_HOMME = 1;
const SEXE_FEMME = 2;
// const CV_MARRIED = 1;
// const CV_SINGLE = 2;
const CV_MR = 1;
const CV_MME = 2;
const CV_MLLE = 3;
const DEVISE_DT = 'DT';
const DEVISE_EURO = 'EURO';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $firstname = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $lastname = null;
#[ORM\ManyToOne(targetEntity: Evenement::class, inversedBy: 'inscriptions', fetch: "EAGER")]
#[ORM\JoinColumn(nullable: false)]
private ?Evenement $evenement = null;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'inscriptions', cascade: ["persist"], fetch: "EAGER")]
#[ORM\JoinColumn(nullable: true)]
private ?User $user = null;
#[ORM\Column(type: Types::SMALLINT)]
private ?int $status = null;
#[ORM\Column(type: 'datetime')]
private $createdAt;
#[ORM\Column(type: 'datetime', nullable: true)]
private $updatedAt;
/**
* @var Line[]|Collection|ArrayCollection
*/
#[ORM\ManyToMany(targetEntity: Line::class, inversedBy: 'inscriptions')]
#[ORM\OrderBy(["date" => "ASC", "time" => "ASC"])]
private Collection $lineList;
#[ORM\Column(length: 255, nullable: true)]
private ?string $qrCode = null;
#[ORM\Column(length: 255)]
private ?string $reference = null;
#[ORM\Column(nullable: true, options: [])] // 'default' => "[]"
private ?array $allowedLines = [];
private $listOfLinesId = [];
/** @var Voucher[]|Collection */
#[ORM\OneToMany(mappedBy: 'inscription', targetEntity: Voucher::class)]
private Collection $vouchers;
#[ORM\Column(length: 100, nullable: true)]
private ?string $devise;
#[ORM\Column(type: 'datetime', nullable: true)]
private $datePayment;
#[ORM\Column(length: 255, nullable: true)]
private ?string $servicePayment = null;
#[ORM\Column(name: "status_payment", type: Types::STRING)]
private ?string $statusPayment = null;
#[ORM\Column(name: "amount_cart", type: Types::FLOAT, nullable: true)]
private ?float $amountCart = null;
#[ORM\Column(name: "amount", type: Types::FLOAT, nullable: true)]
private ?float $amount = null;
#[ORM\Column(name: "discount", type: Types::FLOAT, nullable: true)]
private ?float $discount = null;
#[ORM\Column(name: "amount_payment", type: Types::FLOAT, nullable: true)]
private ?float $amountPayment = null;
#[ORM\Column(name: "data_payment", type: Types::JSON, nullable: true)]
private $dataPayment = [];
#[ORM\Column(name: "data_inscription", type: Types::JSON, nullable: true)]
private $dataInscription = [];
#[ORM\Column(name: "transaction", type: Types::STRING, nullable: true)]
private $transaction = null;
// NOTE: Ce champ indique que l'inscription est validé et nécessite une vérification après une nouvelle transaction d'achat supplémentaire.
#[ORM\Column(name: "need_verification", type: Types::BOOLEAN, nullable: true)]
private ?bool $needVerification = null;
#[ORM\Column(name: "note", type: Types::TEXT, nullable: true)]
private $note = null;
#[ORM\Column(name: "note_admin", type: Types::TEXT, nullable: true)]
private $noteAdmin = null;
// NOTE: This is not a mapped field of entity metadata, just a simple property.
#[Vich\UploadableField(mapping: 'virements', fileNameProperty: 'imageName', size: 'imageSize')]
private ?File $imageFile = null;
#[ORM\Column(nullable: true)]
private ?string $imageName = null;
#[ORM\Column(nullable: true)]
private ?int $imageSize = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $imageUpdatedAt = null;
#[ORM\Column(nullable: true)]
private ?array $emailHistory = null;
#[ORM\OneToMany(targetEntity: PaymentLog::class, mappedBy: 'inscription')]
private Collection $paymentLogs;
#[ORM\Column(nullable: true, options: ['default' => 0])]
private ?int $sentMail = 0;
public function __construct()
{
$this->lineList = new ArrayCollection();
$this->vouchers = new ArrayCollection();
$this->status = self::STATUS_DRAFT;
$this->statusPayment = self::STATUS_PAYMENT_PENDING;
$this->devise = self::DEVISE_DT;
$this->dataPayment = [];
$this->paymentLogs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getTitle(): ?string
{
return $this->user?->getTitle();
}
public function isTitleResidant(): bool
{
// return $this->user?->getTitle() && $this->user?->getTitle() == AppConstants::TITLE_RESIDENT;
if ($this->user) {
return $this->user->isTitleResidant();
}
return false;
}
public function getMail(): ?string
{
return $this->user ? $this->user->getEmail() : null;
}
public function getCivility(): ?int
{
if ($this->user && is_null($this->user->getCivility())) {
if ($this->user?->getSexe() == self::SEXE_HOMME) {
$this->user?->setCivility(self::CV_MR);
} elseif ($this->user?->getSexe() == self::SEXE_FEMME) {
$this->user?->setCivility(self::CV_MME);
}
}
return $this->user?->getCivility();
}
public function getSexe(): ?int
{
return $this->user?->getSexe();
}
public function getCountry(): ?string
{
return $this->user?->getCountry();
}
public function getAdresse(): ?string
{
return $this->user?->getAdresse();
}
public function getCity(): ?string
{
return $this->user?->getCity();
}
public function getPostalCode(): ?int
{
return $this->user?->getPostalCode();
}
public function getWorkplace(): ?string
{
return $this->user?->getWorkplace();
}
public function getMobile(): ?string
{
return $this->user?->getMobile();
}
public function getPhone(): ?string
{
return $this->user?->getPhone();
}
public function getSpeciality(): ?string
{
return $this->user?->getSpeciality();
}
public function getActivity(): ?string
{
return $this->user?->getActivity();
}
public function getStatus(): ?int
{
return $this->status;
}
/**
* function to inspect integer value of status and return the corresponding string status(Draft,Valid,Failed,Waiting or Refused)
* @return string|null
*/
public function getStatusString(): ?string
{
$status = $this->status;
if ($status == 1) {
return "Draft";
}
if ($status == 2) {
return "Valid";
}
if ($status == 3) {
return "Failed";
}
if ($status == 4) {
return "Waiting";
}
return "Refused";
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getEvenement(): ?Evenement
{
return $this->evenement;
}
public function setEvenement(?Evenement $evenement): self
{
$this->evenement = $evenement;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection<int, Line>
*/
public function getLineList(): Collection
{
return $this->lineList;
}
public function addLineList(Line $lineList): self
{
if (!$this->lineList->contains($lineList)) {
$this->lineList->add($lineList);
}
return $this;
}
public function removeLineList(Line $lineList): self
{
$this->lineList->removeElement($lineList);
return $this;
}
public function getQrCode(): ?string
{
return $this->qrCode;
}
public function setQrCode(?string $qrCode): self
{
$this->qrCode = $qrCode;
return $this;
}
public function getQRCodeData(): string
{
$data = [
$this->reference,
$this->evenement ? $this->evenement->getId() : 0,
$this->id ? $this->id : 0,
$this->firstname,
$this->lastname,
$this->user?->getEmail() ?: "",
"event_parent_id=" . ($this->evenement && $this->evenement->getParent() && $this->evenement->getParent()->getId() ? $this->evenement->getParent()->getId() : ""),
// $this->adresse,
// $this->city,
// $this->postalCode,
];
return implode("#", $data);
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getListOfLinesId()
{
$data = [];
/** @var Line $line */
foreach ($this->lineList as $line) {
$data[] = $line->getId();
}
$this->listOfLinesId = $data;
return $data;
}
/**
* @return Collection<int, Voucher>
*/
public function getVouchers(): Collection
{
return $this->vouchers;
}
public function addVoucher(Voucher $voucher): self
{
if (!$this->vouchers->contains($voucher)) {
$this->vouchers->add($voucher);
$voucher->setInscription($this);
}
return $this;
}
public function removeVoucher(Voucher $voucher): self
{
if ($this->vouchers->removeElement($voucher)) {
// set the owning side to null (unless already changed)
if ($voucher->getInscription() === $this) {
$voucher->setInscription(null);
}
}
return $this;
}
/**
* Get the value of devise
*/
public function getDevise(): ?string
{
return $this->devise;
}
/**
* Set the value of devise
*
* @return self
*/
public function setDevise(?string $devise): self
{
$this->devise = $devise;
return $this;
}
public function getDatePayment(): ?\DateTimeInterface
{
return $this->datePayment;
}
public function setDatePayment(?\DateTimeInterface $datePayment): self
{
$this->datePayment = $datePayment;
return $this;
}
public function getServicePayment(): ?string
{
return $this->servicePayment;
}
public function setServicePayment(string $servicePayment): self
{
$this->servicePayment = $servicePayment;
return $this;
}
/**
* Get the value of statusPayment
*/
public function getStatusPayment()
{
return $this->statusPayment;
}
/**
* Set the value of statusPayment
*
* @return self
*/
public function setStatusPayment($statusPayment): self
{
$this->statusPayment = $statusPayment;
return $this;
}
public function getAmountCart()
{
return $this->amountCart;
}
public function setAmountCart($amountCart): self
{
$this->amountCart = $amountCart;
return $this;
}
public function calculPayment(): float
{
$amount = 0;
if ($this->lineList) {
foreach ($this->lineList as $line) {
if ($line) {
if ($this->devise == self::DEVISE_DT) {
$amount += $this->isTitleResidant() ? $line->getPriceResidant() : $line->getPrice();
} else if ($this->devise == self::DEVISE_EURO) {
$amount += $this->isTitleResidant() ? $line->getPriceResidantEuro() : $line->getPriceEuro();
}
}
}
}
$this->amount = $amount;
# voucher
$discount = 0;
if ($this->vouchers) {
foreach ($this->vouchers as $voucher) {
if ($voucher) {
# TYPE_UNLIMITED / TYPE_LIMITED
if ($voucher->getPrice() && $voucher->getType() == Voucher::TYPE_LIMITED) {
$discount += $voucher->getPrice();
$amount -= $voucher->getPrice();
} elseif ($voucher->getType() == Voucher::TYPE_UNLIMITED) {
$discount += $amount;
$amount -= $amount;
}
}
}
}
$this->discount = $discount;
$this->amountPayment = $amount;
return $amount;
}
public function updatePlacesReserved()
{
if ($this->status == self::STATUS_VALID) {
foreach ($this->lineList as $line) {
if ($line->getNumberOfPlaces() && $line->getNumberOfPlacesReserved() < $line->getNumberOfPlaces()) {
$place = $line->getNumberOfPlacesReserved();
if (is_null($place)) {
$place = 0;
}
$line->setNumberOfPlacesReserved($place + 1);
}
}
}
}
public function updatePlacesUnReserved()
{
if (in_array($this->status, [self::STATUS_WAITING, self::STATUS_DRAFT])) {
foreach ($this->lineList as $line) {
if ($line->getNumberOfPlaces() && $line->getNumberOfPlacesReserved() <= $line->getNumberOfPlaces()) {
$place = $line->getNumberOfPlacesReserved();
if (is_null($place)) {
$place = 0;
}
if ($place > 0) {
$line->setNumberOfPlacesReserved($place - 1);
}
}
}
}
}
public function updateVouchersUsed()
{
if ($this->status == self::STATUS_VALID) {
if ($this->getVouchers()) {
// foreach ($inscription->getVouchers()->getValues() as $value) {
foreach ($this->getVouchers() as $voucher) {
$voucher->setUsed(true);
}
}
}
}
public function getAmount(): ?float
{
return $this->amount;
}
public function setAmount(?float $amount): self
{
$this->amount = $amount;
return $this;
}
public function getAmountPayment(): ?float
{
return $this->amountPayment;
}
public function setAmountPayment(?float $amountPayment): self
{
$this->amountPayment = $amountPayment;
return $this;
}
/**
* Get the value of user
*/
public function getUser(): ?User
{
return $this->user;
}
/**
* Set the value of user
*/
public function setUser(?User $user): self
{
$this->user = $user;
if ($user) {
if ($user->getCountry() && $user->getCountry() == "TN") {
$this->setDevise(Inscription::DEVISE_DT);
} else {
$this->setDevise(Inscription::DEVISE_EURO);
}
if (!$this->getFirstname() && $user->getFirstname()) {
$this->setFirstname($user->getFirstname());
}
if (!$this->getLastname() && $user->getLastname()) {
$this->setLastname($user->getLastname());
}
}
return $this;
}
/**
* Get the value of dataPayment
*
* @return array|null
*/
public function getDataPayment()
{
if (is_null($this->dataPayment)) {
$this->dataPayment = [];
}
return $this->dataPayment;
}
/**
* Set the value of dataPayment
*
* @param array|null $dataPayment
*/
public function setDataPayment($dataPayment, bool $merge = false): self
{
if (is_null($this->dataPayment)) {
$this->dataPayment = [];
}
if (key_exists('action', $this->dataPayment) || key_exists('reference', $this->dataPayment) || key_exists('service', $this->dataPayment)) {
$this->dataPayment = [0 => $this->dataPayment];
}
if (!is_array($this->dataPayment)) {
$this->dataPayment = [0 => $this->dataPayment];
}
// if ($merge) {
// $this->dataPayment = array_merge($this->dataPayment, $dataPayment);
// } else {
$this->dataPayment[] = $dataPayment;
// }
return $this;
}
/**
* Get the value of discount
*
* @return float|null
*/
public function getDiscount()
{
return $this->discount;
}
/**
* Set the value of discount
*
* @param float|null $discount
*
* @return self
*/
public function setDiscount($discount): self
{
$this->discount = $discount;
return $this;
}
public function hasNeedVerification(): ?bool
{
return $this->getNeedVerification();
}
public function getNeedVerification(): ?bool
{
return $this->needVerification;
}
public function setNeedVerification(?bool $needVerification = null): self
{
$this->needVerification = $needVerification;
return $this;
}
/**
* Get the value of note
*/
public function getNote()
{
return $this->note;
}
/**
* Set the value of note
*
* @return self
*/
public function setNote($note): self
{
$this->note = $note;
return $this;
}
/**
* Get the value of noteAdmin
*/
public function getnoteAdmin()
{
return $this->noteAdmin;
}
/**
* Set the value of noteAdmin
*
* @return self
*/
public function setnoteAdmin($noteAdmin): self
{
$this->noteAdmin = $noteAdmin;
return $this;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->imageUpdatedAt = new \DateTimeImmutable();
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageSize(?int $imageSize): void
{
$this->imageSize = $imageSize;
}
public function getImageSize(): ?int
{
return $this->imageSize;
}
public function getImageUpdatedAt(): ?\DateTimeImmutable
{
return $this->imageUpdatedAt;
}
public function getEmailHistory(): ?array
{
if (is_null($this->emailHistory)) {
$this->emailHistory = [];
}
return $this->emailHistory;
}
public function setEmailHistory(?array $emailHistory = []): static
{
if (is_null($emailHistory)) {
$emailHistory = [];
}
$this->emailHistory = $emailHistory;
return $this;
}
/**
* @param int $id line_id
* @return int
* returns the index of the email_history array where are the email details for a specific line_id
*/
public function getEmailHistoryWithLineId(int $id)
{
$j = 0;
$emailHistory = $this->getEmailHistory();
foreach ($emailHistory as $email) {
if ($email['line_id'] == $id) {
break;
}
$j++;
}
if ($j == count($emailHistory)) {
return -1;
} else {
return $j;
}
}
/**
* @return Collection<int, PaymentLog>
*/
public function getPaymentLogs(): Collection
{
return $this->paymentLogs;
}
public function addPaymentLog(PaymentLog $paymentLog): static
{
if (!$this->paymentLogs->contains($paymentLog)) {
$this->paymentLogs->add($paymentLog);
$paymentLog->setInscription($this);
}
return $this;
}
public function removePaymentLog(PaymentLog $paymentLog): static
{
if ($this->paymentLogs->removeElement($paymentLog)) {
// set the owning side to null (unless already changed)
if ($paymentLog->getInscription() === $this) {
$paymentLog->setInscription(null);
}
}
return $this;
}
/**
* Get the value of transaction
*/
public function getTransaction(): ?string
{
return $this->transaction;
}
/**
* Set the value of transaction
*
* @return self
*/
public function setTransaction(?string $transaction)
{
$this->transaction = $transaction;
return $this;
}
/**
* Get the value of dataInscription
*/
public function getDataInscription()
{
if (is_null($this->dataInscription)) {
$this->dataInscription = [];
}
return array_unique($this->dataInscription);
}
/**
* Set the value of dataInscription
*/
public function setDataInscription($dataInscription): self
{
if (is_null($dataInscription)) {
$dataInscription = [];
}
$this->dataInscription = array_unique(array_filter($dataInscription));
return $this;
}
public function addDataInscription($item): self
{
if (is_null($this->dataInscription)) {
$this->dataInscription = [];
}
if (is_array($this->dataInscription)) {
$this->dataInscription[] = $item;
$this->dataInscription = array_unique(array_filter($this->dataInscription));
}
return $this;
}
public function getSentMail()
{
if (is_null($this->sentMail)) {
$this->sentMail = 0;
}
return $this->sentMail;
}
public function setSentMail($sentMail): self
{
$this->sentMail = $sentMail;
return $this;
}
public function incrementSentMail()
{
$this->getSentMail();
return $this->sentMail++;
}
public function ableToSend(): bool
{
$this->getSentMail();
return $this->sentMail < 2;
}
public function getAllowedLines()
{
return $this->allowedLines;
}
public function setAllowedLines($allowedLines)
{
$this->allowedLines = array_unique(array_filter($allowedLines));
return $this;
}
public function addAllowedLines($line_id = null)
{
if ($line_id) {
$this->allowedLines[] = $line_id;
$this->allowedLines = array_unique(array_filter($this->allowedLines));
}
return $this;
}
}