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:  * Flexible plugin that utilizes a handful of
 20:  * classes for easy toggle behavior.
 21:  *
 22:  * <code>
 23:  * <?php
 24:  * echo $this->Cakestrap->Tab()
 25:  *                      ->nav('Tab 1')
 26:  *                      ->content("This Tab 1  needs your attention, but it's not super important.")
 27:  *                      ->prepare($isActive = true)
 28:  *
 29:  *                      ->nav('Tab 2')
 30:  *                      ->content("This Tab 2 needs your attention, but it's not super important.")
 31:  *                      ->prepare()
 32:  *
 33:  *                      ->set()
 34:  *
 35:  * ?>
 36:  * </code>
 37:  *
 38:  * @method content(string $content)
 39:  * @method nav(string $nav)
 40:  *
 41:  * @package Cakestrap\View\Helper
 42:  */
 43: 
 44: class TabHelper extends Basic
 45: {
 46:     /**
 47:      * Mark the content as new set
 48:      *
 49:      * @var array
 50:      */
 51:     protected $_prepare    = [];
 52: 
 53:     /**
 54:      * Contain active string value
 55:      *
 56:      * @var string
 57:      */
 58:     protected $_active     = null;
 59:     protected $_target;
 60: 
 61:     /**
 62:      * Set all defined values.
 63:      * This will return the final html template.
 64:      *
 65:      * @return string
 66:      */
 67:     public function set()
 68:     {
 69:         if(empty($this->_prepare)) {
 70:             $this->_setNav();
 71:             $this->_setTab();
 72:         }
 73: 
 74:         $this->_addToContainer();
 75:         return $this->_container;
 76:     }
 77: 
 78:     /**
 79:      * Prepare the template content
 80:      *
 81:      * @param boolean $isActive Set item active or inactive
 82:      * @return object $this
 83:      */
 84:     public function prepare($isActive = false)
 85:     {
 86:         $this->_active = ($isActive ? 'active' : null);
 87:         $this->_setNav();
 88:         $this->_setTab();
 89: 
 90:         $content = $this->_contents();
 91:         $this->_prepare['nav'][]  = $content['nav'];
 92:         $this->_prepare['tab'][]  = $content['tab'];
 93: 
 94:         $this->_reset();
 95:         return $this;
 96:     }
 97: 
 98:     /**
 99:      * Now we need to reset the values to support multiple
100:      * tab helper in a page.
101:      *
102:      * @return void
103:      */
104:     protected function _reset()
105:     {
106:         $this->_contents = [];
107:         $this->_active   = null;
108:     }
109: 
110:     /**
111:      * Add collapse items to parent container
112:      *
113:      * @return void
114:      */
115:     protected function _addToContainer()
116:     {
117:         if(empty($this->_prepare)) {
118:             $contents = $this->_contentss();
119:             $prepare  = $this->_stringTemplate->format('prepare', ['prepare'=>$contents]);
120:         } else {
121:             $prepare[]  = $this->_prepare;
122:         }
123: 
124:         $nav = $this->_insertNavContent();
125:         $tab = $this->_insertTabContent();
126:         $this->_container = $this->_stringTemplate->format('container', ['container'=>$nav . $tab]);
127:     }
128: 
129:     /**
130:      * Set nav template
131:      *
132:      * @return void
133:      */
134:     protected function _setNav()
135:     {
136:         $this->_target    = str_replace(" ", '', strtolower($this->nav));
137:         $this->_contents['nav'] = $this->_stringTemplate->format('nav', [
138:             'nav'=>$this->nav,
139:             'target'=>$this->_target,
140:             'active'=>$this->_active
141:         ]);
142:     }
143: 
144:     /**
145:      * Set tab template
146:      *
147:      * @return void
148:      */
149:     protected function _setTab()
150:     {
151:         $this->_contents['tab'] = $this->_stringTemplate->format('tab', [
152:             'tab'=>$this->content,
153:             'target'=>$this->_target,
154:             'active'=>$this->_active
155:         ]);
156:     }
157: 
158:     /**
159:      * Insert nav content
160:      *
161:      * @return string $navContent
162:      */
163:     protected function _insertNavContent()
164:     {
165:         $navContent =  $this->_stringTemplate->format('navcontent', ['navcontent'=>implode("", $this->_prepare['nav'])]);
166:         return $navContent;
167:     }
168: 
169:     /**
170:      * Insert tab content
171:      *
172:      * @return string $tabContent
173:      */
174:     protected function _insertTabContent()
175:     {
176:         $tabContent =  $this->_stringTemplate->format('tabcontent', ['tabcontent'=>implode("", $this->_prepare['tab'])]);
177:         return $tabContent;
178:     }
179: 
180:     /**
181:      * Tab contents
182:      *
183:      * @return array $contents
184:      */
185:     protected function _contents()
186:     {
187:         return $this->_contents;
188:     }
189: }
API documentation generated by ApiGen