src/Entity/Creation.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Traits\Creatable;
  4. use App\Traits\Deleteable;
  5. use App\Traits\Updateable;
  6. use DateTime;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. /**
  12.  * @ORM\Table(name="`creation`")
  13.  * @ORM\Entity(repositoryClass="App\Repository\CreationRepository")
  14.  * @Gedmo\SoftDeleteable(fieldName="deletedAt")
  15.  */
  16. class Creation
  17. {
  18.     use CreatableUpdateableDeleteable;
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\Column(type="integer")
  22.      * @ORM\GeneratedValue(strategy="AUTO")
  23.      */
  24.     private ?int $id null;
  25.     /**
  26.      * @var ?string
  27.      *
  28.      * @ORM\Column(type="string", nullable=true)
  29.      */
  30.     private ?string $name null;
  31.     /**
  32.      * @var ?array
  33.      *
  34.      * @ORM\Column(type="json", nullable=true)
  35.      */
  36.     private ?array $content null;
  37.     /**
  38.      * @var boolean
  39.      *
  40.      * @ORM\Column(type="boolean")
  41.      */
  42.     private bool $archived;
  43.     /**
  44.      * @var ?integer
  45.      *
  46.      * @ORM\Column(name="quantity", type="integer", nullable=true)
  47.      */
  48.     private ?int $quantity null;
  49.     /**
  50.      * @var ?integer
  51.      *
  52.      * @ORM\Column(name="width", type="integer", nullable=true)
  53.      */
  54.     private ?int $width null;
  55.     /**
  56.      * @var ?integer
  57.      *
  58.      * @ORM\Column(name="height", type="integer", nullable=true)
  59.      */
  60.     private ?int $height null;
  61.     /**
  62.      * @ORM\ManyToOne(targetEntity="App\Entity\Institution", inversedBy="creations", cascade={"persist"})
  63.      */
  64.     private ?Institution $institution null;
  65.     /**
  66.      * @ORM\ManyToOne(targetEntity="App\Entity\Product")
  67.      */
  68.     private ?Product $product null;
  69.     /**
  70.      * @ORM\ManyToMany(targetEntity="App\Entity\ProductFeatureValue")
  71.      */
  72.     private Collection $productFeatureValues;
  73.     /**
  74.      * @ORM\ManyToMany(targetEntity="App\Entity\AttributValue")
  75.      */
  76.     private Collection $attributValues;
  77.     /**
  78.      * @ORM\OneToMany(targetEntity="App\Entity\CreationComment", mappedBy="creation", cascade={"persist", "remove"})
  79.      */
  80.     private Collection $creationComments;
  81.     /**
  82.      * @ORM\ManyToMany(targetEntity="App\Entity\Document", cascade={"persist", "remove"})
  83.      * @ORM\JoinTable(name="`creation_related_document`")
  84.      */
  85.     private Collection $relatedDocuments;
  86.     /**
  87.      * @ORM\OneToMany(targetEntity="App\Entity\CartElement", mappedBy="creation", cascade={"persist", "remove"})
  88.      */
  89.     private Collection $cartElements;
  90.     /**
  91.      * @ORM\OneToMany(targetEntity="App\Entity\Order", mappedBy="creation")
  92.      */
  93.     private Collection $orders;
  94.     /**
  95.      * @ORM\ManyToOne(targetEntity="App\Entity\CreationCategory", inversedBy="creations")
  96.      * @ORM\JoinColumn(name="creation_category_id", referencedColumnName="id")
  97.      */
  98.     private ?CreationCategory $creationCategory null;
  99.     /**
  100.      * @ORM\OneToMany(targetEntity="App\Entity\CreationHistory", mappedBy="creation", cascade={"persist", "remove"})
  101.      * @ORM\OrderBy({"createdAt" = "DESC"})
  102.      */
  103.     private Collection $creationHistories;
  104.     /**
  105.      * @ORM\ManyToOne(targetEntity="App\Entity\Model")
  106.      */
  107.     private ?Model $model null;
  108.     /**
  109.      * @ORM\ManyToOne(targetEntity="App\Entity\Matrix")
  110.      */
  111.     private ?Matrix $matrix null;
  112.     public function __construct()
  113.     {
  114.         $this->archived false;
  115.         $this->creationComments = new ArrayCollection();
  116.         $this->relatedDocuments = new ArrayCollection();
  117.         $this->productFeatureValues = new ArrayCollection();
  118.         $this->attributValues = new ArrayCollection();
  119.         $this->cartElements = new ArrayCollection();
  120.         $this->orders = new ArrayCollection();
  121.         $this->creationHistories = new ArrayCollection();
  122.     }
  123.     public function getId(): ?int
  124.     {
  125.         return $this->id;
  126.     }
  127.     public function getName(): ?string
  128.     {
  129.         return $this->name;
  130.     }
  131.     public function setName(?string $name): self
  132.     {
  133.         $this->name $name;
  134.         return $this;
  135.     }
  136.     public function getContent(): ?array
  137.     {
  138.         return $this->content;
  139.     }
  140.     public function setContent(?array $content): self
  141.     {
  142.         $this->content $content;
  143.         return $this;
  144.     }
  145.     public function getArchived(): ?bool
  146.     {
  147.         return $this->archived;
  148.     }
  149.     public function setArchived(bool $archived): self
  150.     {
  151.         $this->archived $archived;
  152.         return $this;
  153.     }
  154.     public function getQuantity(): ?int
  155.     {
  156.         return $this->quantity;
  157.     }
  158.     public function setQuantity(?int $quantity): self
  159.     {
  160.         $this->quantity $quantity;
  161.         return $this;
  162.     }
  163.     public function getWidth(): ?int
  164.     {
  165.         return $this->width;
  166.     }
  167.     public function setWidth(?int $width): self
  168.     {
  169.         $this->width $width;
  170.         return $this;
  171.     }
  172.     public function getHeight(): ?int
  173.     {
  174.         return $this->height;
  175.     }
  176.     public function setHeight(?int $height): self
  177.     {
  178.         $this->height $height;
  179.         return $this;
  180.     }
  181.     public function getInstitution(): ?Institution
  182.     {
  183.         return $this->institution;
  184.     }
  185.     public function setInstitution(?Institution $institution): self
  186.     {
  187.         $this->institution $institution;
  188.         return $this;
  189.     }
  190.     public function getProduct(): ?Product
  191.     {
  192.         return $this->product;
  193.     }
  194.     public function setProduct(?Product $product): self
  195.     {
  196.         $this->product $product;
  197.         return $this;
  198.     }
  199.     /**
  200.      * @return Collection|ProductFeatureValue[]
  201.      */
  202.     public function getProductFeatureValues(): Collection|array
  203.     {
  204.         return $this->productFeatureValues;
  205.     }
  206.     public function addProductFeatureValue(ProductFeatureValue $productFeatureValue): self
  207.     {
  208.         if (!$this->productFeatureValues->contains($productFeatureValue)) {
  209.             $this->productFeatureValues[] = $productFeatureValue;
  210.         }
  211.         return $this;
  212.     }
  213.     public function removeProductFeatureValue(ProductFeatureValue $productFeatureValue): self
  214.     {
  215.         if ($this->productFeatureValues->contains($productFeatureValue)) {
  216.             $this->productFeatureValues->removeElement($productFeatureValue);
  217.         }
  218.         return $this;
  219.     }
  220.     /**
  221.      * @return Collection<int, AttributValue>
  222.      */
  223.     public function getAttributValues(): Collection
  224.     {
  225.         return $this->attributValues;
  226.     }
  227.     public function addAttributValue(AttributValue $attributValue): self
  228.     {
  229.         if (!$this->attributValues->contains($attributValue)) {
  230.             $this->attributValues[] = $attributValue;
  231.         }
  232.         return $this;
  233.     }
  234.     public function removeAttributValue(AttributValue $attributValue): self
  235.     {
  236.         $this->attributValues->removeElement($attributValue);
  237.         return $this;
  238.     }
  239.     /**
  240.      * @return Collection|CreationComment[]
  241.      */
  242.     public function getCreationComments(): array|Collection
  243.     {
  244.         return $this->creationComments;
  245.     }
  246.     public function addCreationComment(CreationComment $creationComment): self
  247.     {
  248.         if (!$this->creationComments->contains($creationComment)) {
  249.             $this->creationComments[] = $creationComment;
  250.             $creationComment->setCreation($this);
  251.         }
  252.         return $this;
  253.     }
  254.     public function removeCreationComment(CreationComment $creationComment): self
  255.     {
  256.         if ($this->creationComments->contains($creationComment)) {
  257.             $this->creationComments->removeElement($creationComment);
  258.             // set the owning side to null (unless already changed)
  259.             if ($creationComment->getCreation() === $this) {
  260.                 $creationComment->setCreation(null);
  261.             }
  262.         }
  263.         return $this;
  264.     }
  265.     /**
  266.      * @return Collection|Document[]
  267.      */
  268.     public function getRelatedDocuments(): Collection|array
  269.     {
  270.         return $this->relatedDocuments;
  271.     }
  272.     public function addRelatedDocument(Document $relatedDocument): self
  273.     {
  274.         if (!$this->relatedDocuments->contains($relatedDocument)) {
  275.             $this->relatedDocuments[] = $relatedDocument;
  276.         }
  277.         return $this;
  278.     }
  279.     public function removeRelatedDocument(Document $relatedDocument): self
  280.     {
  281.         if ($this->relatedDocuments->contains($relatedDocument)) {
  282.             $this->relatedDocuments->removeElement($relatedDocument);
  283.         }
  284.         return $this;
  285.     }
  286.     /**
  287.      * @return Collection|CartElement[]
  288.      */
  289.     public function getCartElements(): Collection|array
  290.     {
  291.         return $this->cartElements;
  292.     }
  293.     public function addCartElement(CartElement $cartElement): self
  294.     {
  295.         if (!$this->cartElements->contains($cartElement)) {
  296.             $this->cartElements[] = $cartElement;
  297.             $cartElement->setCreation($this);
  298.         }
  299.         return $this;
  300.     }
  301.     public function removeCartElement(CartElement $cartElement): self
  302.     {
  303.         if ($this->cartElements->contains($cartElement)) {
  304.             $this->cartElements->removeElement($cartElement);
  305.             // set the owning side to null (unless already changed)
  306.             if ($cartElement->getCreation() === $this) {
  307.                 $cartElement->setCreation(null);
  308.             }
  309.         }
  310.         return $this;
  311.     }
  312.     /**
  313.      * @return Collection|Order[]
  314.      */
  315.     public function getOrders(): Collection|array
  316.     {
  317.         return $this->orders;
  318.     }
  319.     public function addOrder(Order $order): self
  320.     {
  321.         if (!$this->orders->contains($order)) {
  322.             $this->orders[] = $order;
  323.             $order->setCreation($this);
  324.         }
  325.         return $this;
  326.     }
  327.     public function removeOrder(Order $order): self
  328.     {
  329.         if ($this->orders->contains($order)) {
  330.             $this->orders->removeElement($order);
  331.             // set the owning side to null (unless already changed)
  332.             if ($order->getCreation() === $this) {
  333.                 $order->setCreation(null);
  334.             }
  335.         }
  336.         return $this;
  337.     }
  338.     public function getCreationCategory(): ?CreationCategory
  339.     {
  340.         return $this->creationCategory;
  341.     }
  342.     public function setCreationCategory(?CreationCategory $creationCategory): self
  343.     {
  344.         $this->creationCategory $creationCategory;
  345.         return $this;
  346.     }
  347.     /**
  348.      * @return Collection<int, CreationHistory>
  349.      */
  350.     public function getCreationHistories(): Collection
  351.     {
  352.         return $this->creationHistories;
  353.     }
  354.     public function addCreationHistory(CreationHistory $creationHistory): self
  355.     {
  356.         if (!$this->creationHistories->contains($creationHistory)) {
  357.             $this->creationHistories[] = $creationHistory;
  358.             $creationHistory->setCreation($this);
  359.         }
  360.         return $this;
  361.     }
  362.     public function removeCreationHistory(CreationHistory $creationHistory): self
  363.     {
  364.         if ($this->creationHistories->removeElement($creationHistory)) {
  365.             // set the owning side to null (unless already changed)
  366.             if ($creationHistory->getCreation() === $this) {
  367.                 $creationHistory->setCreation(null);
  368.             }
  369.         }
  370.         return $this;
  371.     }
  372.     public function getModel(): ?Model
  373.     {
  374.         return $this->model;
  375.     }
  376.     public function setModel(?Model $model): self
  377.     {
  378.         $this->model $model;
  379.         return $this;
  380.     }
  381.     public function getMatrix(): ?Matrix
  382.     {
  383.         return $this->matrix;
  384.     }
  385.     public function setMatrix(?Matrix $matrix): self
  386.     {
  387.         $this->matrix $matrix;
  388.         return $this;
  389.     }
  390.     /**
  391.      * @return ArrayCollection
  392.      */
  393.     public function getProductFeaturesValuesIndexed()
  394.     {
  395.         $productFeatureValues = new ArrayCollection();
  396.         foreach ($this->getProduct()->getProductFeatures() as $productFeature) {
  397.             foreach ($this->getProductFeatureValues() as $productFeatureValue) {
  398.                 if (!is_null($productFeatureValue->getProductFeature()->getFeature()->getConstName())) {
  399.                     if ($productFeatureValue->getProductFeature()->getFeature()->getConstName() === $productFeature->getFeature()->getConstName()) {
  400.                         $productFeatureValues->add($productFeatureValue);
  401.                     }
  402.                 } elseif (!is_null($productFeatureValue->getProductFeature()->getFeature()->getPrintComConstName())) {
  403.                     if ($productFeatureValue->getProductFeature()->getFeature()->getPrintComConstName() === $productFeature->getFeature()->getPrintComConstName()) {
  404.                         $productFeatureValues->add($productFeatureValue);
  405.                     }
  406.                 }
  407.             }
  408.         }
  409.         return $productFeatureValues;
  410.     }
  411.     /**
  412.      * @return ProductFeatureValue|mixed|null
  413.      */
  414.     public function getProductFeatureValueFormat()
  415.     {
  416.         $productFeatureValueFormat null;
  417.         foreach ($this->getProductFeatureValues() as $productFeatureValue) {
  418.             if ($productFeatureValue->getProductFeature()->getFeature()->getConstName() === Feature::FORMAT or $productFeatureValue->getProductFeature()->getFeature()->getPrintComConstName() === Feature::SIZE) {
  419.                 $productFeatureValueFormat $productFeatureValue;
  420.                 break;
  421.             }
  422.         }
  423.         return $productFeatureValueFormat;
  424.     }
  425.     /**
  426.      * @return bool
  427.      */
  428.     public function hasFormatVariable()
  429.     {
  430.         $hasFormatVariable false;
  431.         /** @var ProductFeatureValue $productFeatureValue */
  432.         foreach ($this->getProductFeatureValues() as $productFeatureValue) {
  433.             if (($productFeatureValue->getProductFeature()->getFeature()->getConstName() == Feature::FORMAT or $productFeatureValue->getProductFeature()->getFeature()->getPrintComConstName() == Feature::SIZE) and $productFeatureValue->getConstName() == ProductFeatureValue::VARIABLE) {
  434.                 $hasFormatVariable true;
  435.                 break;
  436.             }
  437.         }
  438.         return $hasFormatVariable;
  439.     }
  440.     /**
  441.      * @return DateTime
  442.      */
  443.     public function getExpirationDate()
  444.     {
  445.         $expirationDate = clone $this->getCreatedAt();
  446.         $expirationDate->modify('+ 7 DAYS');
  447.         return $expirationDate;
  448.     }
  449.     /**
  450.      * @return bool
  451.      */
  452.     public function isDeletable(): bool
  453.     {
  454.         $isDeletable true;
  455.         if ($this->getOrders()->count() > 0) {
  456.             $isDeletable false;
  457.         }
  458.         return $isDeletable;
  459.     }
  460.     /**
  461.      * @return bool
  462.      */
  463.     public function isUpdatable(): bool
  464.     {
  465.         $isUpdatable true;
  466.         if (!$this->getProduct()->getBuilderAccess()) {
  467.             $isUpdatable false;
  468.         }
  469.         if ($this->getOrders()->count() > 0) {
  470.             /** @var Order $order */
  471.             foreach ($this->getOrders() as $order) {
  472.                 if (!$order->isMakingDone()) {
  473.                     $isUpdatable false;
  474.                 }
  475.             }
  476.         }
  477.         return $isUpdatable;
  478.     }
  479.     /**
  480.      * @return CreationHistory|false|mixed|null
  481.      */
  482.     public function getLastCreationHistory()
  483.     {
  484.         $creationHistory null;
  485.         if ($this->getCreationHistories()->count() > 0) {
  486.             $creationHistory $this->getCreationHistories()->first();
  487.         }
  488.         return $creationHistory;
  489.     }
  490. }