src/Entity/ProductParameterValueGroup.php line 27

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 Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Symfony\Component\HttpFoundation\File\File;
  16. /**
  17.  * @Doctrine\ORM\Mapping\Entity
  18.  * @Doctrine\ORM\Mapping\Table(name="product_parameter_value_group")
  19.  */
  20. class ProductParameterValueGroup implements TranslatableInterfaceBlameableInterfaceTimestampableInterfaceSoftDeletableInterface  {
  21.     use BlameableTrait;
  22.     use TimestampableTrait;
  23.     use TranslatableTrait;
  24.     use SoftDeletableTrait;
  25.     
  26.     
  27.     
  28.     /**
  29.      * @Doctrine\ORM\Mapping\Id
  30.      * @Doctrine\ORM\Mapping\Column(type="integer")
  31.      * @Doctrine\ORM\Mapping\GeneratedValue(strategy="AUTO")
  32.      */
  33.     protected $id;
  34.     /**
  35.      * @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\ProductParameterValue", mappedBy="group", cascade={"all"})
  36.      * @Doctrine\ORM\Mapping\OrderBy({"id" = "DESC"})
  37.      */
  38.     protected $values;
  39.     /**
  40.      * @Doctrine\ORM\Mapping\ManyToOne(targetEntity="App\Entity\ProductParameter", inversedBy="groupValues", fetch="EAGER")
  41.      */
  42.     private $parameter;
  43.     /**
  44.      * @var string
  45.      *
  46.      * @ORM\Column(name="path", type="string", length=128, nullable=true)
  47.      */
  48.     private $path;
  49.     /**
  50.      * @var boolean
  51.      *
  52.      * @Doctrine\ORM\Mapping\Column(name="cart", type="boolean", nullable=true)
  53.      */
  54.     private $cart;
  55.     /**
  56.      * @var boolean
  57.      *
  58.      * @Doctrine\ORM\Mapping\Column(name="visible", type="boolean", nullable=true)
  59.      */
  60.     private $visible;
  61.     /**
  62.      * Obsługa tłumaczeń
  63.      * @param $method
  64.      * @param $arguments
  65.      * @return mixed
  66.      */
  67.     public function getValuesByParameter($parameterId) {
  68.         $values = new ArrayCollection();
  69.         foreach ($this->getVisibleValues() as $value) {
  70.             if ($value->getParameter()->getId() == $parameterId) {
  71.                 $values->add($value);
  72.             }
  73.         }
  74.         return $values;
  75.     }
  76.     public function customTrans($params$idCompare) {
  77.         return array_filter($params, function($e) use ($idCompare) {
  78.             return (isset($e['id'])) && $e['id'] == $idCompare;
  79.         });
  80.     }
  81.     public function __call($method$arguments)
  82.     {
  83.         return $this->proxyCurrentLocaleTranslation($method$arguments);
  84.     }
  85.     public function getName()
  86.     {
  87.         return $this->translate()->getName();
  88.     }
  89.     public function getDescription() {
  90.         return $this->translate()->getDescription();
  91.     }
  92.     public function __construct()
  93.     {
  94.         $this->values = new ArrayCollection();
  95.     }
  96.     public function getId(): ?int
  97.     {
  98.         return $this->id;
  99.     }
  100.     
  101.     public function getVisibleValues() {
  102.         $c = new ArrayCollection();
  103.         /** @var $value ProductParameterValue */
  104.         foreach ($this->getValues() as $value) {
  105.             if ($value->getVisible()) {
  106.                 $c->add($value);
  107.             }
  108.         }
  109.         return $c;
  110.     }
  111.     /**
  112.      * @return Collection|ProductParameterValue[]
  113.      */
  114.     public function getValues(): Collection
  115.     {
  116.         return $this->values;
  117.     }
  118.     public function addValue(ProductParameterValue $value): self
  119.     {
  120.         if (!$this->values->contains($value)) {
  121.             $this->values[] = $value;
  122.             $value->setGroup($this);
  123.         }
  124.         return $this;
  125.     }
  126.     public function removeValue(ProductParameterValue $value): self
  127.     {
  128.         if ($this->values->contains($value)) {
  129.             $this->values->removeElement($value);
  130.             // set the owning side to null (unless already changed)
  131.             if ($value->getGroup() === $this) {
  132.                 $value->setGroup(null);
  133.             }
  134.         }
  135.         return $this;
  136.     }
  137.     public function getParameter(): ?ProductParameter
  138.     {
  139.         return $this->parameter;
  140.     }
  141.     public function setParameter(?ProductParameter $parameter): self
  142.     {
  143.         $this->parameter $parameter;
  144.         return $this;
  145.     }
  146.     /**
  147.      *
  148.      * note This is not a mapped field of entity metadata, just a simple property.
  149.      *
  150.      * @var File $imageFile
  151.      */
  152.     protected $imageFile;
  153.     /**
  154.      * @ORM\Column(type="string", length=255, name="image_name", nullable=true)
  155.      * @var string $imageName
  156.      */
  157.     protected $imageName;
  158.     public function setImageFile(File $image null)
  159.     {
  160.         $this->imageFile $image;
  161.         if ($image) {
  162.             $fileName md5(uniqid()).'.'.$image->guessExtension();
  163.             // Move the file to the directory where brochures are stored
  164.             $brochuresDir getcwd().'/images/parameter_groups/';
  165.             $image->move($brochuresDir$fileName);
  166.             // Update the 'brochure' property to store the PDF file name
  167.             // instead of its contents
  168.             $this->setImageName($fileName);
  169.             $this->updatedAt = new \DateTime('now');
  170.         }
  171.         return $this;
  172.     }
  173.     /**
  174.      * @return File
  175.      */
  176.     public function getImageFile()
  177.     {
  178.         return $this->imageFile;
  179.     }
  180.     /**
  181.      * @param string $imageName
  182.      */
  183.     public function setImageName($imageName)
  184.     {
  185.         $this->imageName $imageName;
  186.     }
  187.     /**
  188.      * @return string
  189.      */
  190.     public function getImageName()
  191.     {
  192.         return $this->imageName;
  193.     }
  194.     public function getCart(): ?bool
  195.     {
  196.         return $this->cart;
  197.     }
  198.     public function setCart(?bool $cart): self
  199.     {
  200.         $this->cart $cart;
  201.         return $this;
  202.     }
  203.     public function getVisible(): ?bool
  204.     {
  205.         return $this->visible;
  206.     }
  207.     public function setVisible(?bool $visible): self
  208.     {
  209.         $this->visible $visible;
  210.         return $this;
  211.     }
  212.     public function getPath(): ?string
  213.     {
  214.         return $this->path;
  215.     }
  216.     public function setPath(?string $path): self
  217.     {
  218.         $this->path $path;
  219.         return $this;
  220.     }
  221. }