src/Entity/Kategorie.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. use Symfony\Component\HttpFoundation\File\UploadedFile;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. /**
  8.  * Kategorie
  9.  *
  10.  * @ORM\Table(name="kategorie")
  11.  * @ORM\Entity
  12.  * @ORM\Entity(repositoryClass="App\Repository\KategorieRepository")
  13.  * 
  14.  */
  15. class Kategorie
  16. {
  17.     /**
  18.      * @var int
  19.      *
  20.      * @ORM\Column(name="id", type="integer", nullable=false)
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue(strategy="IDENTITY")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @var string
  27.      *
  28.      * @ORM\Column(name="kategoria", type="string", length=255, nullable=false)
  29.      */
  30.     private $kategoria;
  31.     /**
  32.      * @var int
  33.      *
  34.      * @ORM\Column(name="id_parent", type="integer", nullable=false)
  35.      */
  36.     private $idParent;
  37.     /**
  38.      * @var string
  39.      *
  40.      * @ORM\Column(name="opis", type="text", nullable=false)
  41.      */
  42.     private $opis;
  43.     /**
  44.      * @var string|null
  45.      *
  46.      * @ORM\Column(name="img", type="string", length=255, nullable=true)
  47.      */
  48.     private $img;
  49.     /**
  50.      * @var string|null
  51.      *
  52.      * @ORM\Column(name="path", type="string", length=255, nullable=true)
  53.      */
  54.     //private $path;
  55.  /**
  56.      * Get id
  57.      *
  58.      * @return integer
  59.      */
  60.     public function getId()
  61.     {
  62.         return $this->id;
  63.     }
  64.     /**
  65.      * Set kategoria
  66.      *
  67.      * @param string $kategoria
  68.      *
  69.      * @return Kategorie
  70.      */
  71.     public function setKategoria($kategoria)
  72.     {
  73.         $this->kategoria $kategoria;
  74.         return $this;
  75.     }
  76.     /**
  77.      * Get kategoria
  78.      *
  79.      * @return string
  80.      */
  81.     public function getKategoria()
  82.     {
  83.         return $this->kategoria;
  84.     }
  85.     /**
  86.      * Set idParent
  87.      *
  88.      * @param integer $idParent
  89.      *
  90.      * @return Kategorie
  91.      */
  92.     public function setIdParent($idParent)
  93.     {
  94.         $this->idParent $idParent;
  95.         return $this;
  96.     }
  97.     /**
  98.      * Get idParent
  99.      *
  100.      * @return integer
  101.      */
  102.     public function getIdParent()
  103.     {
  104.         return $this->idParent;
  105.     }
  106.     /**
  107.      * Set img
  108.      *
  109.      * @param string $img
  110.      *
  111.      * @return Kategorie
  112.      */
  113.     public function setImg($img)
  114.     {
  115.         $this->img $img;
  116.         return $this;
  117.     }
  118.     /**
  119.      * Get img
  120.      *
  121.      * @return string
  122.      */
  123.     public function getImg()
  124.     {
  125.         return $this->img;
  126.     }
  127.     
  128.     /**
  129.      * @ORM\Column(type="string", length=255, nullable=true)
  130.      */
  131.     public $path;
  132.     public function getAbsolutePath()
  133.     {
  134.         return null === $this->path
  135.             null
  136.             $this->getUploadRootDir().'/'.$this->path;
  137.     }
  138.     public function getWebPath()
  139.     {
  140.         return null === $this->path
  141.             null
  142.             $this->getUploadDir().'/'.$this->path;
  143.     }
  144.     protected function getUploadRootDir()
  145.     {
  146.         // the absolute directory path where uploaded
  147.         // documents should be saved
  148.         return __DIR__.'/../../public/'.$this->getUploadDir();
  149.     }
  150.     protected function getUploadDir()
  151.     {
  152.         // get rid of the __DIR__ so it doesn't screw up
  153.         // when displaying uploaded doc/image in the view.
  154.         return 'uploads/kategorie';
  155.     }
  156.     
  157.     /**
  158.      * @Assert\File(maxSize="6000000")
  159.      */
  160.     private $file;
  161.     /**
  162.      * Sets file.
  163.      *
  164.      * @param UploadedFile $file
  165.      */
  166.     public function setFile(UploadedFile $file null)
  167.     {
  168.         $this->file $file;
  169.     }
  170.     /**
  171.      * Get file.
  172.      *
  173.      * @return UploadedFile
  174.      */
  175.     public function getFile()
  176.     {
  177.         return $this->file;
  178.     }
  179.     
  180.     public function upload()
  181. {
  182.     //dd($this->getFile());
  183.     // the file property can be empty if the field is not required
  184.     if (null === $this->getFile()) {
  185.         return;
  186.     }
  187.     // use the original file name here but you should
  188.     // sanitize it at least to avoid any security issues
  189.     $name 'image_' date('Y-m-d-H-i-s') . '_' uniqid() .'.'.$this->getFile()->guessExtension();
  190.     // move takes the target directory and then the
  191.     // target filename to move to
  192.     //dd($this->getFile());
  193.     
  194.     $this->getFile()->move(
  195.         $this->getUploadRootDir(),
  196.         $name
  197.     );
  198.     // set the path property to the filename where you've saved the file
  199.     $this->path $name;
  200.     // clean up the file property as you won't need it anymore
  201.     $this->file null;
  202. }
  203.  /**
  204.      * Set opis
  205.      *
  206.      * @param string $opis
  207.      *
  208.      * @return Produkty
  209.      */
  210.     public function setOpis($opis)
  211.     {
  212.         $this->opis $opis;
  213.         return $this;
  214.     }
  215.     /**
  216.      * Get opis
  217.      *
  218.      * @return string
  219.      */
  220.     public function getOpis()
  221.     {
  222.         return $this->opis;
  223.     }
  224.     
  225.     /**
  226.      * @ORM\OneToMany(targetEntity="Produkty", mappedBy="kategoria")
  227.      */
  228.     protected $produkty;
  229.     /**
  230.      * @ORM\Column(type="boolean")
  231.      */
  232.     private $visible;
  233.     public function __construct()
  234.     {
  235.         $this->produkty = new ArrayCollection();
  236.     }
  237.     
  238.     
  239.     /**
  240.      * Set path
  241.      *
  242.      * @param string $path
  243.      *
  244.      * @return Kategorie
  245.      */
  246.     public function setPath($path)
  247.     {
  248.         $this->path $path;
  249.         return $this;
  250.     }
  251.     /**
  252.      * Get path
  253.      *
  254.      * @return string
  255.      */
  256.     public function getPath()
  257.     {
  258.         return $this->path;
  259.     }
  260.     /**
  261.      * Add produkty
  262.      *
  263.      * @param \AppBundle\Entity\Produkty $produkty
  264.      *
  265.      * @return Kategorie
  266.      */
  267.     public function addProdukty(\App\Entity\Produkty $produkty)
  268.     {
  269.         $this->produkty[] = $produkty;
  270.         return $this;
  271.     }
  272.     /**
  273.      * Remove produkty
  274.      *
  275.      * @param \AppBundle\Entity\Produkty $produkty
  276.      */
  277.     public function removeProdukty(\App\Entity\Produkty $produkty)
  278.     {
  279.         $this->produkty->removeElement($produkty);
  280.     }
  281.     /**
  282.      * Get produkty
  283.      *
  284.      * @return \Doctrine\Common\Collections\Collection
  285.      */
  286.     public function getProdukty()
  287.     {
  288.         return $this->produkty;
  289.     }
  290.     public function isVisible(): ?bool
  291.     {
  292.         return $this->visible;
  293.     }
  294.     public function setVisible(bool $visible): self
  295.     {
  296.         $this->visible $visible;
  297.         return $this;
  298.     }
  299. }