src/Entity/MenuItem.php line 19

  1. <?php
  2. namespace App\Entity;
  3. use Gedmo\Mapping\Annotation as Gedmo;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use A2lix\TranslationFormBundle\Util\Knp\KnpTranslatable;
  6. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  7. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  8. /**
  9.  * 
  10.  * @ORM\Table(name="menu_item")
  11.  * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\MaterializedPathRepository")
  12.  * @ORM\Entity(repositoryClass="App\Repository\MenuItemRepository")   
  13.  * @Gedmo\Tree(type="materializedPath")
  14.  * @ORM\HasLifecycleCallbacks()
  15.  */
  16. class MenuItem implements TranslatableInterface
  17. {
  18.     
  19.     /* Begin Translatable */
  20.     
  21.     use TranslatableTrait;
  22.     
  23.     public function __call($method$arguments)
  24.     {
  25.         return $this->proxyCurrentLocaleTranslation($method$arguments);
  26.     }
  27.     protected $titulo;
  28.     public function getTitulo()
  29.     {
  30.          return $this->translate()->getTitulo();
  31.     }   
  32.     
  33.     /* End Translatable */    
  34.     
  35.     /**
  36.      * @var integer
  37.      *
  38.      * @ORM\Column(name="id", type="integer")      
  39.      * @ORM\Id
  40.      * @ORM\GeneratedValue
  41.      * @Gedmo\TreePathSource      
  42.      */
  43.     private $id;
  44.     /**
  45.      * @Gedmo\TreePath(separator=":", startsWithSeparator=true, endsWithSeparator=false,appendId=false)
  46.      * @ORM\Column(name="path", type="string", length=3000, nullable=true )
  47.      */
  48.     private $path;
  49.     /**
  50.      * @Gedmo\TreeParent
  51.      * @ORM\ManyToOne(targetEntity="MenuItem", inversedBy="children")
  52.      * @ORM\JoinColumns({
  53.      *   @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
  54.      * })
  55.      * @Gedmo\SortableGroup            
  56.      */
  57.     private $parent;
  58.     /**
  59.      * @Gedmo\TreeLevel
  60.      * @ORM\Column(name="lvl", type="integer", nullable=true)
  61.      */
  62.     private $level;
  63.     /**
  64.      * @ORM\OneToMany(targetEntity="MenuItem", mappedBy="parent")
  65.      */
  66.     private $children;
  67.     
  68.     /**
  69.      * @Gedmo\SortablePosition
  70.      * @ORM\Column(name="position", type="integer")
  71.      */
  72.     private $position;    
  73.     
  74.     /**
  75.      * @ORM\ManyToOne(targetEntity="Menu", inversedBy="items", cascade={"persist"})
  76.      * @ORM\JoinColumn(name="menu_id", referencedColumnName="id")
  77.      * @Gedmo\SortableGroup  
  78.      */
  79.     private $menu;  
  80.     
  81.     /**
  82.      * @var string
  83.      *
  84.      * @ORM\ManyToOne(targetEntity="App\Entity\Imagen")
  85.      * @ORM\JoinColumn(name="imagen_id", nullable=true) 
  86.      */
  87.     protected $imagen;      
  88.     
  89.     /**
  90.      * @ORM\Column(name="tipo", type="string", length=64)
  91.      */
  92.     private $tipo;       
  93.     
  94.     /**
  95.      * @ORM\Column(name="target", type="string", length=20)
  96.      */
  97.     private $target
  98.    
  99.     
  100.     /**
  101.      * @ORM\Column(name="contenido", type="integer", nullable=true)
  102.      */    
  103.     private $contenido;
  104.     
  105.     /**
  106.      * @var boolean
  107.      *
  108.      * @ORM\Column(name="activo", type="boolean", options={"default":1})
  109.      */
  110.     private $activo;
  111.     
  112.     
  113.     public function __construct() {
  114.         $this->target "_self";
  115.     }    
  116.     
  117.     
  118.     public function getProductos() {
  119.         return $this->productos;
  120.     }
  121.     
  122.     public function getId()
  123.     {
  124.         return $this->id;
  125.     }
  126.     public function setParent(MenuItem $parent null)
  127.     {
  128.         $this->parent $parent;
  129.         
  130.         return $this;
  131.     }
  132.     public function getParent()
  133.     {
  134.         return $this->parent;
  135.     }
  136.     public function setPath($path)
  137.     {
  138.         $this->path $path;
  139.         
  140.         return $this;
  141.     }
  142.     public function getPath()
  143.     {
  144.         return $this->path;
  145.     }
  146.     public function getLevel()
  147.     {
  148.         return $this->level;
  149.     }
  150.     
  151.     public function setPosition($position)
  152.     {
  153.         $this->position $position;
  154.         
  155.         return $this;
  156.     }
  157.     public function getPosition()
  158.     {
  159.         return $this->position;
  160.     }   
  161.     
  162.     public function setMenu(Menu $menu)
  163.     {
  164.         $this->menu $menu;
  165.         
  166.         return $this;
  167.     }
  168.     public function getMenu()
  169.     {
  170.         return $this->menu;
  171.     }     
  172.     
  173.     /**
  174.      * Set imagen
  175.      *
  176.      * @param media $imagen
  177.      * @return Media
  178.      */
  179.     public function setImagen($imagen)
  180.     {
  181.         $this->imagen $imagen;
  182.     
  183.         return $this;
  184.     }
  185.     /**
  186.      * Get imagen
  187.      *
  188.      * @return media 
  189.      */
  190.     public function getImagen()
  191.     {
  192.         return $this->imagen;
  193.     }         
  194.     
  195.     /**
  196.      * Set tipo
  197.      *
  198.      * @param string $tipo
  199.      * @return MenuItem
  200.      */
  201.     public function setTipo($tipo)
  202.     {
  203.         $this->tipo $tipo;
  204.     
  205.         return $this;
  206.     }
  207.     /**
  208.      * Get tipo
  209.      *
  210.      * @return string 
  211.      */
  212.     public function getTipo()
  213.     {
  214.         return $this->tipo;
  215.     }    
  216.     
  217.     /**
  218.      * Set target
  219.      *
  220.      * @param string $target
  221.      * @return MenuItem
  222.      */
  223.     public function setTarget($target)
  224.     {
  225.         $this->target $target;
  226.     
  227.         return $this;
  228.     }
  229.     /**
  230.      * Get target
  231.      *
  232.      * @return string 
  233.      */
  234.     public function getTarget()
  235.     {
  236.         return $this->target;
  237.     }   
  238.     
  239.     
  240.     /**
  241.      * Set contenido
  242.      *
  243.      * @param object $contenido
  244.      * @return MenuItem
  245.      */
  246.     public function setContenido($contenido)
  247.     {
  248.         $this->contenido $contenido;
  249.     
  250.         return $this;
  251.     }
  252.     /**
  253.      * Get contenido
  254.      *
  255.      * @return object 
  256.      */
  257.     public function getContenido()
  258.     {
  259.         return $this->contenido;
  260.     }    
  261.     
  262.     public static function getTipoLista()
  263.     {
  264.         return array_merge(Contenido::getTipoLista(), array(
  265.                  'Familia',
  266.                  'Enlace',
  267.                  'Vacio',                                  
  268.                 ));
  269.     }    
  270.     
  271.     
  272.     public function __toString()
  273.     {
  274.         return str_repeat('-',($this->getLevel() * 3)).' '.$this->getTitulo();
  275.     }     
  276.     
  277.     /**
  278.      * Set activo
  279.      *
  280.      * @param boolean $activo
  281.      * @return Pais
  282.      */
  283.     public function setActivo($activo)
  284.     {
  285.         $this->activo $activo;
  286.     
  287.         return $this;
  288.     }
  289.     /**
  290.      * Get activo
  291.      *
  292.      * @return boolean 
  293.      */
  294.     public function getActivo()
  295.     {
  296.         return $this->activo;
  297.     }  
  298.     
  299. }