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: namespace Cakestrap\View\Helper;
 16: 
 17: /**
 18:  * This helper provides methods for generating asset paths.
 19:  * Codes are applicable to layout only.
 20:  *
 21:  * <code>
 22:  * <?php
 23:  * //auto render bootstrap styles
 24:  *  echo $this->Cakestrap->Asset()->style();
 25:  *
 26:  * //auto render bootstrap scripts
 27:  *  echo $this->Cakestrap->Asset()->script();
 28:  * ?>
 29:  * </code>
 30:  *
 31:  * @package Cakestrap\View\Helper
 32:  */
 33: 
 34: class AssetHelper extends Basic
 35: {
 36:     /**
 37:      * Asset helpers
 38:      *
 39:      * @var array
 40:      */
 41:     public $helpers       = ['Html'];
 42: 
 43:     /**
 44:      * Url to jquery library without a scheme in order to support http or https.
 45:      *
 46:      * @var string
 47:      */
 48:     protected $_jquery      = '//code.jquery.com/jquery-1.11.3.min.js';
 49: 
 50:     /**
 51:      * Automatically set JS script to an specific Bootstrap helpers.
 52:      *
 53:      * @var array
 54:      */
 55:     protected $_autoScript  = [
 56:         'Alert'    => ['alert'],
 57:         'Dropdown' => ['dropdown'],
 58:         'Modal'    => ['modal'],
 59:         'Tab'      => ['tab'],
 60:         'Collapse' =>  ['collapse', 'transition'],
 61:         'NiceCollapse' =>  ['collapse', 'transition', 'nice-collapse'],
 62:         'NiceModal' =>  ['modal', 'nice-modal'],
 63:     ];
 64: 
 65:     /**
 66:      * An array to handle scripts
 67:      *
 68:      * @var array
 69:      */
 70:     protected $_script      = [];
 71: 
 72:     /**
 73:      * An array to handle styles
 74:      *
 75:      * @var array
 76:      */
 77:     protected $_style       = [];
 78: 
 79:     /**
 80:      * Build CSS style data from an array of  CSS properties.
 81:      *
 82:      * @param array $style
 83:      * @return string $css Styling data.
 84:      */
 85:     public function style($style = [])
 86:     {
 87:         if(!empty($style)) {
 88:             foreach($style as $key=>$value) {
 89:                 $css[] = $this->Html->css($value);
 90:             }
 91: 
 92:             $this->_style =  $css;
 93:         } else {
 94:             $css[]  = $this->Html->css('Cakestrap.bootstrap');
 95:             $css[]  = $this->Html->css('Cakestrap.extend');
 96:             $css[]  = $this->Html->css('Cakestrap.font-awesome');
 97:         }
 98: 
 99:         return implode("", $css) . implode("", $this->_style);
100:     }
101: 
102:     /**
103:      * Build script data from an array of JS properties.
104:      *
105:      * @param array $script
106:      * @return string $script Script data.
107:      */
108:     public function script($script = [])
109:     {
110:         if(!empty($script)) {
111:             foreach($script as $key=>$value) {
112:                 $js[] = $this->Html->script($value);
113:             }
114: 
115:             $this->_script =  implode('', $js);
116:         }
117: 
118:         $js[]     = $this->Html->script($this->_jquery);
119:         $helpers  = $this->_View->helpers()->loaded();
120: 
121:         foreach($helpers as $key=>$value) {
122:             if(isset($this->_autoScript[$value])) {
123:                 foreach($this->_autoScript[$value] as $name) {
124:                     $js[] = $this->Html->script('Cakestrap.' . strtolower($name));
125:                 }
126:             }
127:         }
128: 
129:         $hasNoScript = !$this->_View->get("Cakestrap.script");
130:         if(!$hasNoScript) {
131:             $plugin   = sprintf('%s.%s', $this->request->params["plugin"], strtolower($this->request->params['controller']));
132:             $js[]     = $this->Html->script($plugin);
133:         }
134: 
135:         $script = array_merge($js, $this->_script);
136:         return implode("", $script);
137:     }
138: 
139:     /**
140:      * Create id and class attributes based on controller and  action name.
141:      *
142:      * @param string $classOrId
143:      * @return string
144:      */
145:     public function ident($classOrId = null)
146:     {
147:         $params     = $this->request->params;
148:         $controller = strtolower($params['controller']);
149:         $id     =  sprintf("%s%s",  $controller, ucfirst(strtolower($params['action'])));
150:         $class  =  sprintf("%s-%s", $controller, strtolower($params['action']));
151: 
152:         if($classOrId) {
153:             $class = $classOrId['class'] . "-"  .  strtolower($classOrId['id']);
154:             $id    = $classOrId['class'] . ucwords($classOrId['id']);
155:         }
156: 
157:         return sprintf("class='%s' id='%s'", $class, $id);
158:     }
159: }
API documentation generated by ApiGen