src/Entity/ImportFile.php line 20

  1. <?php
  2. namespace App\Entity;
  3. use DateTimeImmutable;
  4. use DateTimeInterface;
  5. use App\Enum\ImportFileType;
  6. use App\Enum\ImportFileStatus;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  12. use Gedmo\Timestampable\Traits\TimestampableEntity;
  13. use Symfony\Component\HttpFoundation\File\UploadedFile;
  14. #[ORM\Entity(repositoryClass'App\Repository\ImportFileRepository')]
  15. #[Vich\Uploadable]
  16. class ImportFile
  17. {
  18.     use TimestampableEntity;
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column(type'integer')]
  22.     private $id;
  23.     #[ORM\Column(type'string'length255nullabletrue)]
  24.     private $file;
  25.     #[ORM\Column(type'integer')]
  26.     private $total 0;
  27.     #[ORM\Column(type'integer')]
  28.     private $done 0;
  29.     #[ORM\Column(length255)]
  30.     private ImportFileType $type;
  31.     #[ORM\Column(length255)]
  32.     private ImportFileStatus $status ImportFileStatus::STATUS_NEW;
  33.     #[ORM\Column(type'integer')]
  34.     private $processed 0;
  35.     #[ORM\Column(type'integer')]
  36.     private $success 0;
  37.     #[ORM\Column(type'integer')]
  38.     private $failed 0;
  39.     #[ORM\Column(type'datetime'nullabletrue)]
  40.     private $started_at;
  41.     #[ORM\Column(type'datetime'nullabletrue)]
  42.     private $completed_at;
  43.     #[ORM\Column(type'json'nullabletrue)]
  44.     private $errors = [];
  45.     #[ORM\Column(type'json'nullabletrue)]
  46.     private $data = [];
  47.     public $dataFormatted;
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function getFile(): ?string
  53.     {
  54.         return $this->file;
  55.     }
  56.     public function setFile(?string $file): self
  57.     {
  58.         $this->file $file;
  59.         return $this;
  60.     }
  61.     #[Vich\UploadableField(mapping"import_file"fileNameProperty"file")]
  62.     private $uploadedFile;
  63.     #[ORM\ManyToOne(inversedBy'importFiles')]
  64.     private ?User $user null;
  65.     #[ORM\OneToMany(mappedBy'importFile'targetEntityOrder::class)]
  66.     private Collection $orders;
  67.     public function __construct()
  68.     {
  69.         $this->orders = new ArrayCollection();
  70.     }
  71.     public function getTotal(): ?int
  72.     {
  73.         return $this->total;
  74.     }
  75.     public function setTotal(int $total): self
  76.     {
  77.         $this->total $total;
  78.         return $this;
  79.     }
  80.     public function getDone(): ?int
  81.     {
  82.         return $this->done;
  83.     }
  84.     public function setDone(int $done): self
  85.     {
  86.         $this->done $done;
  87.         return $this;
  88.     }
  89.     public function getStatus(): ?ImportFileStatus
  90.     {
  91.         return $this->status;
  92.     }
  93.     public function setStatus(ImportFileStatus $status): self
  94.     {
  95.         $this->status $status;
  96.         return $this;
  97.     }
  98.     public function getData(): ?array
  99.     {
  100.         return $this->data;
  101.     }
  102.     public function setData(?array $data): self
  103.     {
  104.         $this->data $data;
  105.         return $this;
  106.     }
  107.     /**
  108.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  109.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  110.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  111.      * must be able to accept an instance of 'File' as the bundle will inject one here
  112.      * during Doctrine hydration.
  113.      *
  114.      * @param File|UploadedFile|null $uploadedFile
  115.      */
  116.     public function setUploadedFile(?File $uploadedFile null): void
  117.     {
  118.         $this->uploadedFile $uploadedFile;
  119.         if (null !== $uploadedFile) {
  120.             // It is required that at least one field changes if you are using doctrine
  121.             // otherwise the event listeners won't be called and the file is lost
  122.             $this->updatedAt = new DateTimeImmutable();
  123.         }
  124.     }
  125.     /**
  126.      * @return File|null
  127.      */
  128.     public function getUploadedFile(): ?File
  129.     {
  130.         return $this->uploadedFile;
  131.     }
  132.     /**
  133.      * @return mixed
  134.      */
  135.     public function getType(): ImportFileType
  136.     {
  137.         return $this->type;
  138.     }
  139.     /**
  140.      * @param mixed $type
  141.      */
  142.     public function setType(ImportFileType $type): void
  143.     {
  144.         $this->type $type;
  145.     }
  146.     public function getProcessed(): ?int
  147.     {
  148.         return $this->processed;
  149.     }
  150.     public function setProcessed(int $processed): self
  151.     {
  152.         $this->processed $processed;
  153.         return $this;
  154.     }
  155.     public function getSuccess(): ?int
  156.     {
  157.         return $this->success;
  158.     }
  159.     public function setSuccess(int $success): self
  160.     {
  161.         $this->success $success;
  162.         return $this;
  163.     }
  164.     public function getFailed(): ?int
  165.     {
  166.         return $this->failed;
  167.     }
  168.     public function setFailed(int $failed): self
  169.     {
  170.         $this->failed $failed;
  171.         return $this;
  172.     }
  173.     public function getStartedAt(): ?DateTimeInterface
  174.     {
  175.         return $this->started_at;
  176.     }
  177.     public function setStartedAt(?DateTimeInterface $started_at): self
  178.     {
  179.         $this->started_at $started_at;
  180.         return $this;
  181.     }
  182.     public function getCompletedAt(): ?DateTimeInterface
  183.     {
  184.         return $this->completed_at;
  185.     }
  186.     public function setCompletedAt(?DateTimeInterface $completed_at): self
  187.     {
  188.         $this->completed_at $completed_at;
  189.         return $this;
  190.     }
  191.     public function getErrors(): ?array
  192.     {
  193.         return $this->errors;
  194.     }
  195.     public function setErrors(?array $errors): self
  196.     {
  197.         $this->errors $errors;
  198.         return $this;
  199.     }
  200.     public function getUser(): ?User
  201.     {
  202.         return $this->user;
  203.     }
  204.     public function setUser(?User $user): static
  205.     {
  206.         $this->user $user;
  207.         return $this;
  208.     }
  209.     public function __toString(): string
  210.     {
  211.         return $this->file;
  212.     }
  213.     /**
  214.      * @return Collection<int, Order>
  215.      */
  216.     public function getOrders(): Collection
  217.     {
  218.         return $this->orders;
  219.     }
  220.     public function addOrder(Order $order): static
  221.     {
  222.         if (!$this->orders->contains($order)) {
  223.             $this->orders->add($order);
  224.             $order->setImportFile($this);
  225.         }
  226.         return $this;
  227.     }
  228.     public function removeOrder(Order $order): static
  229.     {
  230.         if ($this->orders->removeElement($order)) {
  231.             // set the owning side to null (unless already changed)
  232.             if ($order->getImportFile() === $this) {
  233.                 $order->setImportFile(null);
  234.             }
  235.         }
  236.         return $this;
  237.     }
  238. }