<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Kategorie
*
* @ORM\Table(name="kategorie")
* @ORM\Entity
* @ORM\Entity(repositoryClass="App\Repository\KategorieRepository")
*
*/
class Kategorie
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="kategoria", type="string", length=255, nullable=false)
*/
private $kategoria;
/**
* @var int
*
* @ORM\Column(name="id_parent", type="integer", nullable=false)
*/
private $idParent;
/**
* @var string
*
* @ORM\Column(name="opis", type="text", nullable=false)
*/
private $opis;
/**
* @var string|null
*
* @ORM\Column(name="img", type="string", length=255, nullable=true)
*/
private $img;
/**
* @var string|null
*
* @ORM\Column(name="path", type="string", length=255, nullable=true)
*/
//private $path;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set kategoria
*
* @param string $kategoria
*
* @return Kategorie
*/
public function setKategoria($kategoria)
{
$this->kategoria = $kategoria;
return $this;
}
/**
* Get kategoria
*
* @return string
*/
public function getKategoria()
{
return $this->kategoria;
}
/**
* Set idParent
*
* @param integer $idParent
*
* @return Kategorie
*/
public function setIdParent($idParent)
{
$this->idParent = $idParent;
return $this;
}
/**
* Get idParent
*
* @return integer
*/
public function getIdParent()
{
return $this->idParent;
}
/**
* Set img
*
* @param string $img
*
* @return Kategorie
*/
public function setImg($img)
{
$this->img = $img;
return $this;
}
/**
* Get img
*
* @return string
*/
public function getImg()
{
return $this->img;
}
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
public $path;
public function getAbsolutePath()
{
return null === $this->path
? null
: $this->getUploadRootDir().'/'.$this->path;
}
public function getWebPath()
{
return null === $this->path
? null
: $this->getUploadDir().'/'.$this->path;
}
protected function getUploadRootDir()
{
// the absolute directory path where uploaded
// documents should be saved
return __DIR__.'/../../public/'.$this->getUploadDir();
}
protected function getUploadDir()
{
// get rid of the __DIR__ so it doesn't screw up
// when displaying uploaded doc/image in the view.
return 'uploads/kategorie';
}
/**
* @Assert\File(maxSize="6000000")
*/
private $file;
/**
* Sets file.
*
* @param UploadedFile $file
*/
public function setFile(UploadedFile $file = null)
{
$this->file = $file;
}
/**
* Get file.
*
* @return UploadedFile
*/
public function getFile()
{
return $this->file;
}
public function upload()
{
//dd($this->getFile());
// the file property can be empty if the field is not required
if (null === $this->getFile()) {
return;
}
// use the original file name here but you should
// sanitize it at least to avoid any security issues
$name = 'image_' . date('Y-m-d-H-i-s') . '_' . uniqid() .'.'.$this->getFile()->guessExtension();
// move takes the target directory and then the
// target filename to move to
//dd($this->getFile());
$this->getFile()->move(
$this->getUploadRootDir(),
$name
);
// set the path property to the filename where you've saved the file
$this->path = $name;
// clean up the file property as you won't need it anymore
$this->file = null;
}
/**
* Set opis
*
* @param string $opis
*
* @return Produkty
*/
public function setOpis($opis)
{
$this->opis = $opis;
return $this;
}
/**
* Get opis
*
* @return string
*/
public function getOpis()
{
return $this->opis;
}
/**
* @ORM\OneToMany(targetEntity="Produkty", mappedBy="kategoria")
*/
protected $produkty;
/**
* @ORM\Column(type="boolean")
*/
private $visible;
public function __construct()
{
$this->produkty = new ArrayCollection();
}
/**
* Set path
*
* @param string $path
*
* @return Kategorie
*/
public function setPath($path)
{
$this->path = $path;
return $this;
}
/**
* Get path
*
* @return string
*/
public function getPath()
{
return $this->path;
}
/**
* Add produkty
*
* @param \AppBundle\Entity\Produkty $produkty
*
* @return Kategorie
*/
public function addProdukty(\App\Entity\Produkty $produkty)
{
$this->produkty[] = $produkty;
return $this;
}
/**
* Remove produkty
*
* @param \AppBundle\Entity\Produkty $produkty
*/
public function removeProdukty(\App\Entity\Produkty $produkty)
{
$this->produkty->removeElement($produkty);
}
/**
* Get produkty
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProdukty()
{
return $this->produkty;
}
public function isVisible(): ?bool
{
return $this->visible;
}
public function setVisible(bool $visible): self
{
$this->visible = $visible;
return $this;
}
}