src/Entity/DictionaryImport.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Eg\Admin\User;
  4. use App\Repository\DictionaryImportRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. #[ORM\Entity(repositoryClass: DictionaryImportRepository::class)]
  7. class DictionaryImport
  8. {
  9.     public const TYPE_ZONES_AND_STREETS = 'zones_and_streets';
  10.     public const TYPE_COUNTRIES = 'countries';
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue(strategy: 'IDENTITY')]
  13.     #[ORM\Column(type: 'integer')]
  14.     private $id;
  15.     #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'dictionaryImports')]
  16.     #[ORM\JoinColumn(nullable: false)]
  17.     private $createdBy;
  18.     #[ORM\Column(type: 'integer')]
  19.     private $insertedRecords;
  20.     #[ORM\Column(type: 'integer')]
  21.     private $updatedRecords;
  22.     #[ORM\Column(type: 'datetimetz_immutable')]
  23.     private $createdAt;
  24.     #[ORM\Column(type: 'string', length: 80)]
  25.     private $type;
  26.     public static function createZonesAndStreetsImport(User $user, int $insertedRecords, int $updatedRecords): self
  27.     {
  28.         $import = new self();
  29.         $import->setCreatedBy($user)
  30.             ->setInsertedRecords($insertedRecords)
  31.             ->setUpdatedRecords($updatedRecords)
  32.             ->setType(self::TYPE_ZONES_AND_STREETS);
  33.         return $import;
  34.     }
  35.     public static function createCountriesImport(User $user, int $insertedRecords, int $updatedRecords): self
  36.     {
  37.         $import = new self();
  38.         $import->setCreatedBy($user)
  39.             ->setInsertedRecords($insertedRecords)
  40.             ->setUpdatedRecords($updatedRecords)
  41.             ->setType(self::TYPE_COUNTRIES);
  42.         return $import;
  43.     }
  44.     public function __construct()
  45.     {
  46.         $this->createdAt = new \DateTimeImmutable();
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function getCreatedBy(): ?User
  53.     {
  54.         return $this->createdBy;
  55.     }
  56.     public function setCreatedBy(User $createdBy): self
  57.     {
  58.         $this->createdBy = $createdBy;
  59.         return $this;
  60.     }
  61.     public function getInsertedRecords(): ?int
  62.     {
  63.         return $this->insertedRecords;
  64.     }
  65.     public function setInsertedRecords(int $insertedRecords): self
  66.     {
  67.         $this->insertedRecords = $insertedRecords;
  68.         return $this;
  69.     }
  70.     public function getUpdatedRecords(): ?int
  71.     {
  72.         return $this->updatedRecords;
  73.     }
  74.     public function setUpdatedRecords(int $updatedRecords): self
  75.     {
  76.         $this->updatedRecords = $updatedRecords;
  77.         return $this;
  78.     }
  79.     public function getCreatedAt(): ?\DateTimeImmutable
  80.     {
  81.         return $this->createdAt;
  82.     }
  83.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  84.     {
  85.         $this->createdAt = $createdAt;
  86.         return $this;
  87.     }
  88.     public function getType(): ?string
  89.     {
  90.         return $this->type;
  91.     }
  92.     public function setType(string $type): self
  93.     {
  94.         if (!\in_array($type, [self::TYPE_ZONES_AND_STREETS, self::TYPE_COUNTRIES], true)) {
  95.             throw new \InvalidArgumentException('Invalid import type: ' . $type);
  96.         }
  97.         $this->type = $type;
  98.         return $this;
  99.     }
  100. }