Overview

Namespaces

  • Cakestrap
    • View
      • Helper

Classes

  • Cakestrap\View\Helper\AlertHelper
  • Cakestrap\View\Helper\AssetHelper
  • Cakestrap\View\Helper\BadgeHelper
  • Cakestrap\View\Helper\Basic
  • Cakestrap\View\Helper\ButtonItemsHelper
  • Cakestrap\View\Helper\CakestrapHelper
  • Cakestrap\View\Helper\CallOutHelper
  • Cakestrap\View\Helper\CollapseHelper
  • Cakestrap\View\Helper\DropdownHelper
  • Cakestrap\View\Helper\ListGroupHelper
  • Cakestrap\View\Helper\ModalHelper
  • Cakestrap\View\Helper\PanelHelper
  • Cakestrap\View\Helper\TabHelper
  • Cakestrap\View\Helper\TableHelper
  • Cakestrap\View\Helper\Templates
  • Cakestrap\View\Helper\WellHelper
  • Overview
  • Namespace
  • Class
  1: <?php
  2: /**
  3:  * Copyright (c) CMNWorks
  4:  *
  5:  * Licensed under The MIT License
  6:  * For full copyright and license information, please see the LICENSE.txt
  7:  * Redistributions of files must retain the above copyright notice.
  8:  *
  9:  * @copyright     Copyright (c) CMNWorks Christopher M. Natan
 10:  * @author        Christopher M. Natan
 11:  * @link          http://cmnworks.com
 12:  * @since         1.8.8
 13:  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: 
 16: namespace Cakestrap\View\Helper;
 17: 
 18: /**
 19:  * Add dropdown menus to nearly anything with this simple plugin,
 20:  * including the navbar, tabs, and pills.
 21:  *
 22:  * <code>
 23:  * <?php
 24:  * echo $this->Cakestrap->Dropdown()
 25:  *                      ->title("Select")
 26:  *                      ->item(['Option 1'=>['controller'=>'home', 'action'=>'action1'])
 27:  *                      ->item('Option 2')
 28:  *                      ->item(['Option 3'=>['controller'=>'home', 'action'=>'action3']])
 29:  *                      ->set()
 30:  * ?>
 31:  * </code>
 32:  *
 33:  * @method title(string $title)
 34:  *
 35:  * @package Cakestrap\View\Helper
 36:  * @link http://getbootstrap.com/javascript/#dropdowns
 37:  */
 38: 
 39: class DropdownHelper extends Basic
 40: {
 41:     /**
 42:      * Helpers to use
 43:      *
 44:      * @param array
 45:      */
 46:     public $helpers = ['Html'];
 47: 
 48:     /**
 49:      * An array that contain items
 50:      *
 51:      * @param array
 52:      */
 53:     protected $_items = [];
 54: 
 55:     /**
 56:      * Set all the defined values.
 57:      * This will return the final html template.
 58:      *
 59:      * @return string
 60:      */
 61:     public function set()
 62:     {
 63:         $options    = $this->_setItems();
 64:         $ul         = $this->_stringTemplate->format('ul', ['ul'=>implode("", $options)]);
 65:         $title      = $this->_setTitle();
 66:         $container  = $this->_stringTemplate->format('container', ['container' => $title . $ul]);
 67: 
 68:         return $container;
 69:     }
 70: 
 71:     /**
 72:      * Set the Dropdown item
 73:      *
 74:      * @param string  $item
 75:      * @return object $this
 76:      */
 77:     public function item($item = null)
 78:     {
 79:         $this->_items[] = $item;
 80:         return $this;
 81:     }
 82: 
 83:     /**
 84:      * Set the Dropdown  title
 85:      *
 86:      * @return void
 87:      */
 88:     private function _setTitle()
 89:     {
 90:          return $this->_stringTemplate->format('title', ['title' => $this->title]);
 91:     }
 92: 
 93:     /**
 94:      * Collate the Dropdown helper items
 95:      *
 96:      * @return array $items
 97:      */
 98:     private function _setItems()
 99:     {
100:         $items = [];
101:         foreach($this->_items as $name=>$value) {
102: 
103:             if(!is_array($value)) {
104:                 $name  = $value;
105:                 $value = "#";
106:             } else {
107:                 $name  = key($value);
108:                 $value = $value[$name];
109:             }
110:             $items[] = $this->_stringTemplate->format('li', [
111:                 'li' => $this->Html->link($name, $value)
112:             ]);
113:         }
114: 
115:         return $items;
116:     }
117: }
API documentation generated by ApiGen