src/Cms/ImportBundle/Entity/ImportState.php line 24

Open in your IDE?
  1. <?php
  2. namespace Cms\ImportBundle\Entity;
  3. use Cms\TenantBundle\Entity\TenantedEntity;
  4. use DateTimeInterface;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * Tracks and idividual import action for a given Import.
  8.  * For example, for imports that are able to be modified or updated, the newer sheet will involve creating a new ImportState entry.
  9.  * This also allows imports to be reverted and such.
  10.  *
  11.  * Class ImportState
  12.  * @package Cms\ImportBundle\Entity
  13.  *
  14.  * @ORM\Entity(
  15.  *     repositoryClass = "Cms\ImportBundle\Doctrine\ImportStateRepository"
  16.  * )
  17.  * @ORM\Table(
  18.  *     name = "cms__import__import_state"
  19.  * )
  20.  */
  21. class ImportState extends TenantedEntity
  22. {
  23.     /**
  24.      * Link back to the Import entity for which this ImportState is for.
  25.      *
  26.      * @var Import
  27.      *
  28.      * @ORM\ManyToOne(
  29.      *     targetEntity = "Cms\ImportBundle\Entity\Import"
  30.      * )
  31.      * @ORM\JoinColumn(
  32.      *     name = "import",
  33.      *     referencedColumnName = "id",
  34.      *     onDelete = "CASCADE",
  35.      *     nullable = false,
  36.      * )
  37.      */
  38.     protected $import;
  39.     /**
  40.      * The time at which the state was uploaded.
  41.      * As new states are made on an upload of a document, this field should effectively never be NULL.
  42.      *
  43.      * @var DateTimeInterface|null
  44.      *
  45.      * @ORM\Column(
  46.      *     type = "datetime",
  47.      *     nullable = true,
  48.      * )
  49.      */
  50.     protected $uploadedAt null;
  51.     /**
  52.      * The type of the uploaded file, such as Excel, CSV, etc.
  53.      * As new states are made on an upload of a document, this field should effectively never be NULL.
  54.      *
  55.      * @var string|null
  56.      *
  57.      * @ORM\Column(
  58.      *     type = "string",
  59.      *     nullable = true,
  60.      * )
  61.      */
  62.     protected $uploadedType null;
  63.     /**
  64.      * The original filename of the uploaded document.
  65.      * As new states are made on an upload of a document, this field should effectively never be NULL.
  66.      *
  67.      * @var string|null
  68.      *
  69.      * @ORM\Column(
  70.      *     type = "string",
  71.      *     nullable = true,
  72.      * )
  73.      */
  74.     protected $uploadedFilename null;
  75.     /**
  76.      * Tracks the column names of the uploaded file.
  77.      * They should be properly numerically indexed.
  78.      *
  79.      * @var array
  80.      *
  81.      * @ORM\Column(
  82.      *     type = "json",
  83.      *     nullable = false,
  84.      * )
  85.      */
  86.     protected $uploadedColumns = [];
  87.     /**
  88.      * The mappings from the Import column names to the column names in the sheet that was uploaded.
  89.      * If the mapping value for the Import is NULL, it means that the field should simply be ignored in the import, meaning existing data will be left untouched on existing entries in the system.
  90.      * If the mapping value for the Import is FALSE, it means that the field should be wiped in the import, meaning the existing data will be cleared from the existing entity.
  91.      * Otherwise, the mapping value should be a string which is the name of the column in the sheet.
  92.      * When creating a new state the mappings should be copied from the latest ImportState entity.
  93.      *
  94.      * @var array
  95.      *
  96.      * @ORM\Column(
  97.      *     type = "json",
  98.      *     nullable = false,
  99.      * )
  100.      */
  101.     protected $mappings = [];
  102.     /**
  103.      * The time at which the state was processed.
  104.      * If this is NULL, it means that the state has not yet been processed properly.
  105.      *
  106.      * @var DateTimeInterface|null
  107.      *
  108.      * @ORM\Column(
  109.      *     type = "datetime",
  110.      *     nullable = true,
  111.      * )
  112.      */
  113.     protected $processedAt null;
  114.     /**
  115.      * The number of milliseconds it took for the import to process.
  116.      *
  117.      * @var int
  118.      *
  119.      * @ORM\Column(
  120.      *     type = "integer",
  121.      *     nullable = false,
  122.      *     options = {
  123.      *         "default" = 0,
  124.      *     },
  125.      * )
  126.      */
  127.     protected $processedTime 0;
  128.     /**
  129.      * @return Import
  130.      */
  131.     public function getImport(): Import
  132.     {
  133.         return $this->import;
  134.     }
  135.     /**
  136.      * @param Import $import
  137.      * @return $this
  138.      */
  139.     public function setImport(Import $import): self
  140.     {
  141.         $this->import $import;
  142.         return $this;
  143.     }
  144.     /**
  145.      * @return bool
  146.      */
  147.     public function isUploaded(): bool
  148.     {
  149.         return ($this->getUploadedAt() instanceof DateTimeInterface);
  150.     }
  151.     /**
  152.      * @return DateTimeInterface|null
  153.      */
  154.     public function getUploadedAt(): ?DateTimeInterface
  155.     {
  156.         return $this->uploadedAt;
  157.     }
  158.     /**
  159.      * @param DateTimeInterface $uploadedAt
  160.      * @return $this
  161.      */
  162.     public function setUploadedAt(DateTimeInterface $uploadedAt): self
  163.     {
  164.         $this->uploadedAt $uploadedAt;
  165.         return $this;
  166.     }
  167.     /**
  168.      * @return string|
  169.      * null
  170.      */
  171.     public function getUploadedType(): ?string
  172.     {
  173.         return $this->uploadedType;
  174.     }
  175.     /**
  176.      * @param string $uploadedType
  177.      * @return $this
  178.      */
  179.     public function setUploadedType(string $uploadedType): self
  180.     {
  181.         $this->uploadedType $uploadedType;
  182.         return $this;
  183.     }
  184.     /**
  185.      * @return string|null
  186.      */
  187.     public function getUploadedFilename(): ?string
  188.     {
  189.         return $this->uploadedFilename;
  190.     }
  191.     /**
  192.      * @param string $uploadedFilename
  193.      * @return $this
  194.      */
  195.     public function setUploadedFilename(string $uploadedFilename): self
  196.     {
  197.         $this->uploadedFilename $uploadedFilename;
  198.         return $this;
  199.     }
  200.     /**
  201.      * @return array|string[]
  202.      */
  203.     public function getUploadedColumns(): array
  204.     {
  205.         return $this->uploadedColumns;
  206.     }
  207.     /**
  208.      * @param array|string[] $uploadedColumns
  209.      * @return $this
  210.      */
  211.     public function setUploadedColumns(array $uploadedColumns): self
  212.     {
  213.         $this->uploadedColumns $uploadedColumns;
  214.         return $this;
  215.     }
  216.     /**
  217.      * @return array|string[]
  218.      */
  219.     public function getDisplayableColumns(): array
  220.     {
  221.         // TODO: can we just sort the other method call?
  222.         $columns $this->getUploadedColumns();
  223.         sort($columns);
  224.         return $columns;
  225.     }
  226.     /**
  227.      * @return bool
  228.      */
  229.     public function hasMappings(): bool
  230.     {
  231.         return ( ! empty($this->getMappings()));
  232.     }
  233.     /**
  234.      * @return bool
  235.      */
  236.     public function isMapped(): bool
  237.     {
  238.         return $this->hasMappings();
  239.     }
  240.     /**
  241.      * @return array
  242.      */
  243.     public function getMappings(): array
  244.     {
  245.         ksort($this->mappings);
  246.         return $this->mappings;
  247.     }
  248.     /**
  249.      * @param array $mappings
  250.      * @return $this
  251.      */
  252.     public function setMappings(array $mappings): self
  253.     {
  254.         $this->mappings $mappings;
  255.         ksort($this->mappings);
  256.         return $this;
  257.     }
  258.     /**
  259.      * @return bool
  260.      */
  261.     public function isProcessed(): bool
  262.     {
  263.         return ($this->getProcessedAt() instanceof DateTimeInterface);
  264.     }
  265.     /**
  266.      * @return DateTimeInterface|null
  267.      */
  268.     public function getProcessedAt(): ?DateTimeInterface
  269.     {
  270.         return $this->processedAt;
  271.     }
  272.     /**
  273.      * @param DateTimeInterface|null $processedAt
  274.      * @return $this
  275.      */
  276.     public function setProcessedAt(?DateTimeInterface $processedAt): self
  277.     {
  278.         $this->processedAt $processedAt;
  279.         return $this;
  280.     }
  281.     /**
  282.      * @return int
  283.      */
  284.     public function getProcessedTime(): int
  285.     {
  286.         return $this->processedTime;
  287.     }
  288.     /**
  289.      * @param int $processedTime
  290.      * @return $this
  291.      */
  292.     public function setProcessedTime(int $processedTime): self
  293.     {
  294.         $this->processedTime $processedTime;
  295.         return $this;
  296.     }
  297. }