src/AppBundle/Entity/ComponenteTipo.php line 15
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Componente.
*
* @ORM\Table(name="componente_tipo")
* @ORM\Entity(repositoryClass="\Doctrine\ORM\EntityRepository")
* @ORM\HasLifecycleCallbacks()
*/
class ComponenteTipo
{
const OPTIONS = [
'banner' => [
'id' => 3,
'name' => 'Banner',
'slug' => 'banner',
],
'carousel' => [
'id' => 1,
'name' => 'Carousel',
'slug' => 'carousel',
],
'categorias' => [
'id' => 2,
'name' => 'Categorias',
'slug' => 'categorias',
],
'cross-selling' => [
'id' => 4,
'name' => 'CrossSelling',
'slug' => 'cross-selling',
],
];
/**
* @var int
*
* @ORM\Column(name="id", type="string", length=2, options={"fixed" = true})
* @ORM\Id
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="texto", type="string")
*/
private $texto;
/**
* @var string
*
* @ORM\Column(name="formulario", type="string")
*/
private $formulario;
/**
* @ORM\OneToMany(targetEntity="Componente", mappedBy="tipo")
*/
protected $componentes;
public function __construct()
{
$this->componentes = new ArrayCollection();
}
/**
* Get the value of id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set the value of id
*
* @param int $id
*
* @return self
*/
public function setId(int $id)
{
$this->id = $id;
return $this;
}
/**
* Get the value of texto
*
* @return string
*/
public function getTexto()
{
return $this->texto;
}
/**
* Set the value of texto
*
* @param string $texto
*
* @return self
*/
public function setTexto(string $texto)
{
$this->texto = $texto;
return $this;
}
/**
* Get the value of formulario
*
* @return string
*/
public function getFormulario()
{
return $this->formulario;
}
/**
* Set the value of formulario
*
* @param string $formulario
*
* @return self
*/
public function setFormulario(string $formulario)
{
$this->formulario = $formulario;
return $this;
}
/**
* Add componente.
*
* @param \AppBundle\Entity\Componente $componente
*
* @return Caracteristica
*/
public function addComponentes(Componente $componente)
{
$this->componentes[] = $componente;
return $this;
}
/**
* Remove componentes.
*
* @param \AppBundle\Entity\Componente $componente
*/
public function removeAgrupadores(Componente $componente)
{
$this->componentes->removeElement($componente);
}
/**
* Get componentes.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getAgrupadores()
{
return $this->componentes;
}
/**
* * De vuelve el nombre de la entidad.
* @return string
*/
public function getName(): string
{
return self::fromOptions($this->getId())['name'];
}
/**
* * De vuelve la entidad en formato array.
* @return array
*/
public function _toArray(): array
{
$response = [
//
];
$response['id'] = $this->getId();
$response['name'] = $this->getName();
return $response;
}
/**
* * De vuelve el tipo de Componente desde las opciones.
* @param int|string $dato
* @return array|null
*/
static public function fromOptions(int|string $dato): ?array
{
foreach (self::OPTIONS as $slug => $tipo) {
if (gettype($dato) == 'string') {
if ($slug == $dato) {
return $tipo;
}
continue;
}
if ($tipo['id'] == $dato) {
return $tipo;
}
}
return null;
}
}