Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file TMenuItem.php

Documentation is available at TMenuItem.php

  1. <?php
  2. namespace Adianti\Widget\Menu;
  3.  
  4. use Adianti\Core\AdiantiCoreApplication;
  5. use Adianti\Widget\Menu\TMenu;
  6. use Adianti\Widget\Base\TElement;
  7. use Adianti\Widget\Util\TImage;
  8.  
  9. /**
  10.  * MenuItem Widget
  11.  *
  12.  * @version    7.4
  13.  * @package    widget
  14.  * @subpackage menu
  15.  * @author     Pablo Dall'Oglio
  16.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  17.  * @license    http://www.adianti.com.br/framework-license
  18.  */
  19. class TMenuItem extends TElement
  20. {
  21.     private $label;
  22.     private $action;
  23.     private $image;
  24.     private $menu;
  25.     private $level;
  26.     private $link;
  27.     private $linkClass;
  28.     private $classLink;
  29.     private $menu_transformer;
  30.     private $tagLabel;
  31.     private $classIcon;
  32.     
  33.     /**
  34.      * Class constructor
  35.      * @param $label  The menu label
  36.      * @param $action The menu action
  37.      * @param $image  The menu image
  38.      */
  39.     public function __construct($label$action$image NULL$level 0$menu_transformer null)
  40.     {
  41.         parent::__construct('li');
  42.         $this->label     $label;
  43.         $this->action    $action;
  44.         $this->level     $level;
  45.         $this->link      new TElement('a');
  46.         $this->linkClass 'dropdown-toggle';
  47.  
  48.         $this->menu_transformer $menu_transformer;
  49.  
  50.         if ($image)
  51.         {
  52.             $this->image $image;
  53.         }
  54.     }
  55.     
  56.     /**
  57.      * Returns the action
  58.      */
  59.     public function getAction()
  60.     {
  61.         return $this->action;
  62.     }
  63.     
  64.     /**
  65.      * Set the action
  66.      */
  67.     public function setAction($action)
  68.     {
  69.         $this->action $action;
  70.     }
  71.     
  72.     /**
  73.      * Returns the label
  74.      */
  75.     public function getLabel()
  76.     {
  77.         return $this->label;
  78.     }
  79.     
  80.     /**
  81.      * Set the label
  82.      */
  83.     public function setLabel($label)
  84.     {
  85.         $this->label $label;
  86.     }
  87.     
  88.     /**
  89.      * Returns the image
  90.      */
  91.     public function getImage()
  92.     {
  93.         return $this->image;
  94.     }
  95.     
  96.     /**
  97.      * Set the image
  98.      */
  99.     public function setImage($image)
  100.     {
  101.         $this->image $image;
  102.     }
  103.     
  104.     /**
  105.      * Set link class
  106.      */
  107.     public function setLinkClass($class)
  108.     {
  109.         $this->linkClass $class;
  110.     }
  111.     
  112.     /**
  113.      * Define the submenu for the item
  114.      * @param $menu A TMenu object
  115.      */
  116.     public function setMenu(TMenu $menu)
  117.     {
  118.         $this->{'class''dropdown-submenu';
  119.         $this->menu $menu;
  120.     }
  121.  
  122.     /**
  123.      * Set link class Item
  124.      */
  125.     public function setClassLink($class)
  126.     {
  127.         $this->classLink $class;
  128.     }
  129.  
  130.     /**
  131.      * Set icon class Item
  132.      */
  133.     public function setClassIcon($class)
  134.     {
  135.         $this->classIcon $class;
  136.     }
  137.  
  138.     /**
  139.      * Set tag label
  140.      */
  141.     public function setTagLabel($tag)
  142.     {
  143.         $this->tagLabel $tag;
  144.     }
  145.     
  146.     /**
  147.      * Shows the widget at the screen
  148.      */
  149.     public function show()
  150.     {
  151.         if ($this->action)
  152.         {
  153.             $action str_replace('#''&'$this->action);
  154.  
  155.             // Controll if menu.xml contains a short url e.g. \home  -> back slash is the char controll
  156.             if (substr($action,0,1== '\\')
  157.             {
  158.                 $this->link->{'href'substr($action1);
  159.                 $this->link->{'generator''adianti';
  160.             }
  161.             elseif ((substr($action,0,7== 'http://'or (substr($action,0,8== 'https://'))
  162.             {
  163.                 $this->link->{'href'$action;
  164.                 $this->link->{'target''_blank';
  165.             }
  166.             else
  167.             {
  168.                 if ($router AdiantiCoreApplication::getRouter())
  169.                 {
  170.                     $this->link->{'href'$router("class={$action}"true);
  171.                 }
  172.                 else
  173.                 {
  174.                     $this->link->{'href'"index.php?class={$action}";
  175.                 }
  176.                 $this->link->{'generator''adianti';
  177.             }
  178.         }
  179.         else
  180.         {
  181.             $this->link->{'href''#';
  182.         }
  183.         
  184.         if (isset($this->image))
  185.         {
  186.             $image new TImage($this->image);
  187.  
  188.             if ($this->classIcon)
  189.             {
  190.                 $image->{'class'.= " {$this->classIcon}";
  191.             }
  192.  
  193.             $this->link->add($image);
  194.         }
  195.         
  196.         $label new TElement($this->tagLabel ?? 'span');
  197.         if (substr($this->label03== '_t{')
  198.         {
  199.             $label->add(_t(substr($this->label,3,-1)));
  200.         }
  201.         else
  202.         {
  203.             $label->add($this->label);
  204.         }
  205.         
  206.         if (!empty($this->label))
  207.         {
  208.             $this->link->add($label);
  209.             $this->add($this->link);
  210.         }
  211.         
  212.         if ($this->classLink)
  213.         {
  214.             $this->link->{'class'$this->classLink;
  215.         }
  216.  
  217.         if ($this->menu instanceof TMenu)
  218.         {
  219.             $this->link->{'class'$this->linkClass;
  220.             if (strstr($this->linkClass'dropdown'))
  221.             {
  222.                 $this->link->{'data-toggle'"dropdown";
  223.             }
  224.             
  225.             if ($this->level == 0)
  226.             {
  227.                 $caret new TElement('b');
  228.                 $caret->{'class''caret';
  229.                 $caret->add('');
  230.                 $this->link->add($caret);
  231.             }
  232.  
  233.             if (!empty($this->menu_transformer))
  234.             {
  235.                 $this->link = call_user_func($this->menu_transformer$this->link);
  236.             }
  237.  
  238.             parent::add($this->menu);
  239.         }
  240.         
  241.         parent::show();
  242.     }
  243. }