<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Produkty
*
* @ORM\Table(name="produkty", indexes={@ORM\Index(name="IDX_5D7CE2FC75FD0C12", columns={"id_kategoria"})})
* @ORM\Entity
* @ORM\Entity(repositoryClass="App\Repository\ProduktyRepository")
*/
class Produkty
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="nazwa", type="string", length=255, nullable=false)
*/
private $nazwa;
/**
* @var string
*
* @ORM\Column(name="kod", type="string", length=255, nullable=false)
*/
private $kod;
/**
* @var string|null
*
* @ORM\Column(name="opis", type="string", length=2048, nullable=true)
*/
private $opis;
/**
* @var string|null
*
* @ORM\Column(name="opis_txt", type="text", length=0, nullable=true)
*/
private $opisTxt;
/**
* @var bool
*
* @ORM\Column(name="aktywny", type="boolean", nullable=false)
*/
private $aktywny;
/**
* @var string|null
*
* @ORM\Column(name="path", type="string", length=255, nullable=true)
*/
//private $path;
/**
* @var \Kategorie
*
* @ORM\ManyToOne(targetEntity="Kategorie")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_kategoria", referencedColumnName="id")
* })
*/
private $idKategoria;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nazwa
*
* @param string $nazwa
*
* @return Produkty
*/
public function setNazwa($nazwa)
{
$this->nazwa = $nazwa;
return $this;
}
/**
* Get nazwa
*
* @return string
*/
public function getNazwa()
{
return $this->nazwa;
}
/**
* Set kod
*
* @param string $kod
*
* @return Produkty
*/
public function setKod($kod)
{
$this->kod = $kod;
return $this;
}
/**
* Get kod
*
* @return string
*/
public function getKod()
{
return $this->kod;
}
/**
* Set opis
*
* @param string $opis
*
* @return Produkty
*/
public function setOpis($opis)
{
$this->opis = $opis;
return $this;
}
/**
* Get opis
*
* @return string
*/
public function getOpis()
{
return trim($this->opis);
}
/**
* Set opisTxt
*
* @param string $opisTxt
*
* @return Produkty
*/
public function setOpisTxt($opisTxt)
{
$this->opisTxt = $opisTxt;
return $this;
}
/**
* Get opisTxt
*
* @return string
*/
public function getOpisTxt()
{
return $this->opisTxt;
}
/**
* Set idKategoria
*
* @param integer $idKategoria
*
* @return Produkty
*/
public function setIdKategoria($idKategoria)
{
$this->idKategoria = $idKategoria;
return $this;
}
/**
* Get idKategoria
*
* @return integer
*/
public function getIdKategoria()
{
return $this->idKategoria;
}
/**
* Set aktywny
*
* @param boolean $aktywny
*
* @return Produkty
*/
public function setAktywny($aktywny)
{
$this->aktywny = $aktywny;
return $this;
}
/**
* Get aktywny
*
* @return boolean
*/
public function getAktywny()
{
return $this->aktywny;
}
/**
* @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/produkty';
}
/**
* @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()
{
// 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
$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;
}
/**
* @ORM\ManyToOne(targetEntity="Kategorie", inversedBy="produkty")
* @ORM\JoinColumn(name="id_kategoria", referencedColumnName="id")
*/
protected $kategoria;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $formula;
/**
* Set path
*
* @param string $path
*
* @return Produkty
*/
public function setPath($path)
{
$this->path = $path;
return $this;
}
/**
* Get path
* s
* @return string
*/
public function getPath()
{
return $this->path;
}
/**
* Set kategoria
*
* @param \App\Entity\Kategorie $kategoria
*
* @return Produkty
*/
public function setKategoria(\App\Entity\Kategorie $kategoria = null)
{
$this->kategoria = $kategoria;
return $this;
}
/**
* Get kategoria
*
* @return \App\Entity\Kategorie
*/
public function getKategoria()
{
return $this->kategoria;
}
/**
* Set the value of id
*
* @param int $id
*
* @return self
*/
public function setId(int $id)
{
$this->id = $id;
return $this;
}
public function getFormula(): ?int
{
return $this->formula;
}
public function setFormula(?int $formula): self
{
$this->formula = $formula;
return $this;
}
}