src/Entity/Produkty.php line 18

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