src/Entity/SubProduct.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
  4. use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
  5. use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
  6. use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
  7. use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
  8. use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
  9. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  10. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  11. use App\Model\LangParamInterface;
  12. use App\Model\LangParamRelationInterface;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Doctrine\ORM\Query\Parameter;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. use Symfony\Component\HttpFoundation\File\UploadedFile;
  19. use Symfony\Component\HttpFoundation\File\File;
  20. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  21. /**
  22.  * @ORM\Entity
  23.  * @ORM\Table(name="sub_product")
  24.  */
  25. class SubProduct implements TranslatableInterfaceBlameableInterfaceTimestampableInterfaceSoftDeletableInterface  {
  26.     use BlameableTrait;
  27.     use TimestampableTrait;
  28.     use TranslatableTrait;
  29.     use SoftDeletableTrait;
  30.     
  31.     
  32.     
  33.     /**
  34.      * @ORM\Id
  35.      * @ORM\Column(type="integer")
  36.      * @ORM\GeneratedValue(strategy="AUTO")
  37.      */
  38.     protected $id;
  39.     /**
  40.      * Obsługa tłumaczeń
  41.      * @param $method
  42.      * @param $arguments
  43.      * @return mixed
  44.      */
  45.     public function __call($method$arguments)
  46.     {
  47.         return $this->proxyCurrentLocaleTranslation($method$arguments);
  48.     }
  49.     public function getName()
  50.     {
  51.         return $this->translate()->getName();
  52.     }
  53.     public function getPrice()
  54.     {
  55.         return $this->translate()->getPrice();
  56.     }
  57.     public function getRebate()
  58.     {
  59.         return $this->translate()->getRebate();
  60.     }
  61.     /**
  62.      * @ORM\ManyToOne(targetEntity="App\Entity\Product", cascade={"all"}, inversedBy="subProducts")
  63.      * @ORM\JoinColumn(name="product_id", referencedColumnName="id")
  64.      */
  65.     protected $product;
  66.     /**
  67.      * @Doctrine\ORM\Mapping\Column(name="active", type="boolean", options={"default"=0}, nullable=true)
  68.      */
  69.     protected $active;
  70.     /**
  71.      * @ORM\OneToMany(targetEntity="App\Entity\CartProduct", mappedBy="subProduct")
  72.      * @Doctrine\ORM\Mapping\OrderBy({"id" = "DESC"})
  73.      */
  74.     protected $carts;
  75.     /**
  76.      * @ORM\OneToMany(targetEntity="App\Entity\OrderProduct", mappedBy="subProduct")
  77.      * @Doctrine\ORM\Mapping\OrderBy({"id" = "DESC"})
  78.      */
  79.     protected $orders;
  80.     /**
  81.      *
  82.      * note This is not a mapped field of entity metadata, just a simple property.
  83.      *
  84.      * @var File $imageFile
  85.      */
  86.     protected $imageFile;
  87.     /**
  88.      * @ORM\Column(type="string", length=255, name="image_name", nullable=true)
  89.      * @var string $imageName
  90.      */
  91.     protected $imageName;
  92.     /**
  93.      * @var \DateTime
  94.      *
  95.      * @ORM\Column(name="sold_time", type="datetime", nullable=true)
  96.      */
  97.     private $soldTime;
  98.     /**
  99.      * @var \DateTime
  100.      *
  101.      * @ORM\Column(name="add_to_cart_time", type="datetime", nullable=true)
  102.      */
  103.     private $addToCartTime;
  104.     public function __construct()
  105.     {
  106.         $this->carts = new ArrayCollection();
  107.         $this->orders = new ArrayCollection();
  108.     }
  109.     public function getId(): ?int
  110.     {
  111.         return $this->id;
  112.     }
  113.     public function getProduct(): ?Product
  114.     {
  115.         return $this->product;
  116.     }
  117.     public function setProduct(?Product $product): self
  118.     {
  119.         $this->product $product;
  120.         return $this;
  121.     }
  122.     public function getActive(): ?bool
  123.     {
  124.         return $this->active;
  125.     }
  126.     public function setActive(?bool $active): self
  127.     {
  128.         $this->active $active;
  129.         return $this;
  130.     }
  131.     public function getSoldTime(): ?\DateTimeInterface
  132.     {
  133.         return $this->soldTime;
  134.     }
  135.     public function setSoldTime(?\DateTimeInterface $soldTime): self
  136.     {
  137.         $this->soldTime $soldTime;
  138.         return $this;
  139.     }
  140.     public function setImageFile(File $image null)
  141.     {
  142.         $this->imageFile $image;
  143.         if ($image) {
  144.             try {
  145.                 $fileName md5(uniqid()).'.'.$image->guessExtension();
  146.                 // Move the file to the directory where brochures are stored
  147.                 $brochuresDir getcwd().'/images/product/';
  148.                 $image->move($brochuresDir$fileName);
  149.                 // Update the 'brochure' property to store the PDF file name
  150.                 // instead of its contents
  151.                 $this->setImageName($fileName);
  152.                 $this->updatedAt = new \DateTime('now');
  153.             } catch (\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException $e) {
  154.             }
  155.         }
  156.         return $this;
  157.     }
  158.     /**
  159.      * @return File
  160.      */
  161.     public function getImageFile()
  162.     {
  163.         return $this->imageFile;
  164.     }
  165.     /**
  166.      * @param string $imageName
  167.      */
  168.     public function setImageName($imageName)
  169.     {
  170.         $this->imageName $imageName;
  171.     }
  172.     /**
  173.      * @return string
  174.      */
  175.     public function getImageName()
  176.     {
  177.         return $this->imageName;
  178.     }
  179.     /**
  180.      * @return Collection|CartProduct[]
  181.      */
  182.     public function getCarts(): Collection
  183.     {
  184.         return $this->carts;
  185.     }
  186.     public function addCart(CartProduct $cart): self
  187.     {
  188.         if (!$this->carts->contains($cart)) {
  189.             $this->carts[] = $cart;
  190.             $cart->setSubProduct($this);
  191.         }
  192.         return $this;
  193.     }
  194.     public function removeCart(CartProduct $cart): self
  195.     {
  196.         if ($this->carts->removeElement($cart)) {
  197.             // set the owning side to null (unless already changed)
  198.             if ($cart->getSubProduct() === $this) {
  199.                 $cart->setSubProduct(null);
  200.             }
  201.         }
  202.         return $this;
  203.     }
  204.     /**
  205.      * @return Collection|OrderProduct[]
  206.      */
  207.     public function getOrders(): Collection
  208.     {
  209.         return $this->orders;
  210.     }
  211.     public function addOrder(OrderProduct $order): self
  212.     {
  213.         if (!$this->orders->contains($order)) {
  214.             $this->orders[] = $order;
  215.             $order->setSubProduct($this);
  216.         }
  217.         return $this;
  218.     }
  219.     public function removeOrder(OrderProduct $order): self
  220.     {
  221.         if ($this->orders->removeElement($order)) {
  222.             // set the owning side to null (unless already changed)
  223.             if ($order->getSubProduct() === $this) {
  224.                 $order->setSubProduct(null);
  225.             }
  226.         }
  227.         return $this;
  228.     }
  229.     /**
  230.      * @return \DateTime
  231.      */
  232.     public function getAddToCartTime()
  233.     {
  234.         return $this->addToCartTime;
  235.     }
  236.     /**
  237.      * @param \DateTime $addToCartTime
  238.      */
  239.     public function setAddToCartTime(\DateTime $addToCartTime)
  240.     {
  241.         $this->addToCartTime $addToCartTime;
  242.     }
  243. }