src/AppBundle/Entity/Categoria.php line 19
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\String\Slugger\AsciiSlugger;
/**
* Categoria.
*
* @ORM\Table(name="categoria")
* @ORM\Entity(repositoryClass="AppBundle\Repository\CategoriaRepository")
* @Vich\Uploadable
* @ORM\HasLifecycleCallbacks()
*/
class Categoria
{
const default_color = "#d92617";
const IMAGENES = [
'C10' => '/images/icons/componentes/materias_primas.svg',
'C20' => '/images/icons/componentes/fluidos_sanitarios.svg',
'C30' => '/images/icons/componentes/fluidos_industriales.svg',
'C40' => '/images/icons/componentes/consumibles_industriales.svg',
'C50' => '/images/icons/componentes/arquitectura_construccion.svg',
'C70' => '/images/icons/componentes/ferreteria.svg'
];
/**
* @var int
*
* @ORM\Column(name="id", type="string", length=2, options={"fixed" = true})
* @ORM\Id
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="nombre_es", type="string", length=255)
*/
private $nombreEs;
/**
* @var string
*
* @ORM\Column(name="nombre_en", type="string", length=255)
*/
private $nombreEn;
/**
* @var string
*
* @ORM\Column(name="slug_es", type="string", length=255)
*/
private $slugEs;
/**
* @var string
*
* @ORM\Column(name="slug_en", type="string", length=255)
*/
private $slugEn;
/**
* @var string
*
* @ORM\Column(name="foto", type="string", length=100)
*/
private $foto = "";
/**
* @var bool
*
* @ORM\Column(name="eliminado", type="boolean")
*/
private $eliminado = false;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $imageName = "";
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="categoria_image", fileNameProperty="imageName")
*
* @var File
*/
private $imageFile;
/**
* @ORM\OneToMany(targetEntity="FamiliaCategoria", mappedBy="categoria", cascade={"persist"}, orphanRemoval=true)
*/
protected $familiasCategoria;
/**
* @var \DateTime
* @ORM\Column(name="fecha_ultima_modificacion", type="datetime", nullable=true)
*/
private $fechaUltimaModificacion = null;
/**
* @var int
*
* @ORM\Column(name="orden", type="integer")
*/
private $orden;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
private $folleto = "";
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="categoria_folleto", fileNameProperty="folleto")
*
* @var File
*/
private $folletoFile = "";
/**
* @ORM\Column(type="string", length=7, nullable=true)
*
* @var string
*/
private $color = "";
/**
* @ORM\ManyToMany(targetEntity="Familia", inversedBy="categorias")
* @ORM\JoinTable(name="familia_categoria",
* joinColumns={@ORM\JoinColumn(name="categoria_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="familia_id", referencedColumnName="id")}
* )
*/
protected $familias;
public function __construct()
{
$this->familiasCategoria = new ArrayCollection();
}
/**
* Set id.
*
* @param int $id
*
* @return Categoria
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set nombreEs.
*
* @param string $nombreEs
*
* @return Categoria
*/
public function setNombreEs($nombreEs)
{
$this->nombreEs = $nombreEs;
return $this;
}
/**
* Get nombreEs.
*
* @return string
*/
public function getNombreEs()
{
return $this->nombreEs;
}
/**
* Set nombreEn.
*
* @param string $nombreEn
*
* @return Categoria
*/
public function setNombreEn($nombreEn)
{
$this->nombreEn = $nombreEn;
return $this;
}
/**
* Get nombreEn.
*
* @return string
*/
public function getNombreEn()
{
return $this->nombreEn;
}
/**
* Add familiasCategorium.
*
* @param \AppBundle\Entity\FamiliaCategoria $familiasCategorium
*
* @return Categoria
*/
public function addFamiliasCategorium(\AppBundle\Entity\FamiliaCategoria $familiasCategorium)
{
$this->familiasCategoria[] = $familiasCategorium;
return $this;
}
/**
* Remove familiasCategorium.
*
* @param \AppBundle\Entity\FamiliaCategoria $familiasCategorium
*/
public function removeFamiliasCategorium(\AppBundle\Entity\FamiliaCategoria $familiasCategorium)
{
$this->familiasCategoria->removeElement($familiasCategorium);
}
/**
* Get familiasCategoria.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFamiliasCategoria()
{
return $this->familiasCategoria;
}
/**
* Set slugEs.
*
* @ORM\PreUpdate
* @ORM\PrePersist
*
* @param string $slugEs
*
* @return Categoria
*/
public function setSlugEs($slugEs)
{
$slugify = new AsciiSlugger();
$this->slugEs = $slugify->slug($this->nombreEs)->lower();
return $this;
}
/**
* Get slugEs.
*
* @return string
*/
public function getSlugEs()
{
return $this->slugEs;
}
/**
* Set slugEn.
*
* @ORM\PreUpdate
* @ORM\PrePersist
*
* @param string $slugEn
*
* @return Categoria
*/
public function setSlugEn($slugEn)
{
$slugify = new AsciiSlugger();
$this->slugEn = $slugify->slug($this->nombreEn)->lower();
return $this;
}
/**
* Get slugEn.
*
* @return string
*/
public function getSlugEn()
{
return $this->slugEn;
}
/**
* Set foto.
*
* @param string $foto
*
* @return Categoria
*/
public function setFoto($foto)
{
$this->foto = $foto;
return $this;
}
/**
* Get foto.
*
* @return string
*/
public function getFoto()
{
return $this->foto;
}
/**
* Set eliminado.
*
* @param bool $eliminado
*
* @return Categoria
*/
public function setEliminado($eliminado)
{
$this->eliminado = $eliminado;
return $this;
}
/**
* Get eliminado.
*
* @return bool
*/
public function getEliminado()
{
return $this->eliminado;
}
public function setImageFile(File $image = null)
{
$this->fechaUltimaModificacion = new \DateTime();
$this->imageFile = $image;
return $this;
}
/**
* @return File
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param string $imageName
*
* @return Categoria
*/
public function setImageName($imageName)
{
$this->fechaUltimaModificacion = new \DateTime();
$this->imageName = $imageName;
return $this;
}
/**
* @return string
*/
public function getImageName()
{
return $this->imageName;
}
/**
* @param int $orden
*
* @return Categoria
*/
public function setOrden($orden)
{
$this->orden = $orden;
return $this;
}
/**
* @return int
*/
public function getOrden()
{
return $this->orden;
}
/**
* @ORM\PreUpdate
*/
public function setFechaUltimaModificacion()
{
$this->fechaUltimaModificacion = new \DateTime();
}
/**
* Get fechaUltimaModificacion.
*
* @return \DateTime
*/
public function getFechaUltimaModificacion()
{
return $this->fechaUltimaModificacion;
}
/**
* @return File
*/
public function getfolletoFile()
{
return $this->folletoFile;
}
public function setfolletoFile(File $folletoFile = null)
{
$this->fechaUltimaModificacion = new \DateTime();
$this->folletoFile = $folletoFile;
return $this;
}
/**
* @param string $folleto
*
* @return Categoria
*/
public function setFolleto($folleto)
{
$this->fechaUltimaModificacion = new \DateTime();
$this->folleto = $folleto;
return $this;
}
/**
* @return string
*/
public function getFolleto()
{
return $this->folleto;
}
/**
* @param int $color
*
* @return Categoria
*/
public function setColor($color)
{
$this->color = $color;
return $this;
}
/**
* @return string
*/
public function getColor()
{
if(empty($this->color)){
return self::default_color;
}
return $this->color;
}
/**
* @return Collection
*/
public function getFamilias()
{
return $this->familias;
}
public function nombreFolletoDownload(){
return substr($this->folleto,strpos($this->folleto,'_')+1);
}
}