File indexing completed on 2024-12-29 05:27:35
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Dojo 0017 * @subpackage View 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** Zend_Dojo_View_Helper_Dijit */ 0024 // require_once 'Zend/Dojo/View/Helper/Dijit.php'; 0025 0026 /** 0027 * Abstract class for Dojo Slider dijits 0028 * 0029 * @uses Zend_Dojo_View_Helper_Dijit 0030 * @package Zend_Dojo 0031 * @subpackage View 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 abstract class Zend_Dojo_View_Helper_Slider extends Zend_Dojo_View_Helper_Dijit 0036 { 0037 /** 0038 * Dojo module to use 0039 * @var string 0040 */ 0041 protected $_module = 'dijit.form.Slider'; 0042 0043 /** 0044 * Required slider parameters 0045 * @var array 0046 */ 0047 protected $_requiredParams = array('minimum', 'maximum', 'discreteValues'); 0048 0049 /** 0050 * Slider type -- vertical or horizontal 0051 * @var string 0052 */ 0053 protected $_sliderType; 0054 0055 /** 0056 * dijit.form.Slider 0057 * 0058 * @param int $id 0059 * @param mixed $value 0060 * @param array $params Parameters to use for dijit creation 0061 * @param array $attribs HTML attributes 0062 * @return string 0063 */ 0064 public function prepareSlider($id, $value = null, array $params = array(), array $attribs = array()) 0065 { 0066 $this->_sliderType = strtolower($this->_sliderType); 0067 0068 // Prepare two items: a hidden element to store the value, and the slider 0069 $hidden = $this->_renderHiddenElement($id, $value); 0070 $hidden = preg_replace('/(name=")([^"]*)"/', 'id="$2" $1$2"', $hidden); 0071 0072 foreach ($this->_requiredParams as $param) { 0073 if (!array_key_exists($param, $params)) { 0074 // require_once 'Zend/Dojo/View/Exception.php'; 0075 throw new Zend_Dojo_View_Exception('prepareSlider() requires minimally the "minimum", "maximum", and "discreteValues" parameters'); 0076 } 0077 } 0078 0079 $content = ''; 0080 $attribs['value'] = $value; 0081 0082 if (!array_key_exists('onChange', $attribs)) { 0083 $attribs['onChange'] = "dojo.byId('" . $id . "').value = arguments[0];"; 0084 } 0085 0086 $id = str_replace('][', '-', $id); 0087 $id = str_replace(array('[', ']'), '-', $id); 0088 $id = rtrim($id, '-'); 0089 $id .= '-slider'; 0090 0091 switch ($this->_sliderType) { 0092 case 'horizontal': 0093 if (array_key_exists('topDecoration', $params)) { 0094 $content .= $this->_prepareDecoration('topDecoration', $id, $params['topDecoration']); 0095 unset($params['topDecoration']); 0096 } 0097 0098 if (array_key_exists('bottomDecoration', $params)) { 0099 $content .= $this->_prepareDecoration('bottomDecoration', $id, $params['bottomDecoration']); 0100 unset($params['bottomDecoration']); 0101 } 0102 0103 if (array_key_exists('leftDecoration', $params)) { 0104 unset($params['leftDecoration']); 0105 } 0106 0107 if (array_key_exists('rightDecoration', $params)) { 0108 unset($params['rightDecoration']); 0109 } 0110 break; 0111 case 'vertical': 0112 if (array_key_exists('leftDecoration', $params)) { 0113 $content .= $this->_prepareDecoration('leftDecoration', $id, $params['leftDecoration']); 0114 unset($params['leftDecoration']); 0115 } 0116 0117 if (array_key_exists('rightDecoration', $params)) { 0118 $content .= $this->_prepareDecoration('rightDecoration', $id, $params['rightDecoration']); 0119 unset($params['rightDecoration']); 0120 } 0121 0122 if (array_key_exists('topDecoration', $params)) { 0123 unset($params['topDecoration']); 0124 } 0125 0126 if (array_key_exists('bottomDecoration', $params)) { 0127 unset($params['bottomDecoration']); 0128 } 0129 break; 0130 default: 0131 // require_once 'Zend/Dojo/View/Exception.php'; 0132 throw new Zend_Dojo_View_Exception('Invalid slider type; slider must be horizontal or vertical'); 0133 } 0134 0135 return $hidden . $this->_createLayoutContainer($id, $content, $params, $attribs); 0136 } 0137 0138 /** 0139 * Prepare slider decoration 0140 * 0141 * @param string $position 0142 * @param string $id 0143 * @param array $decInfo 0144 * @return string 0145 */ 0146 protected function _prepareDecoration($position, $id, $decInfo) 0147 { 0148 if (!in_array($position, array('topDecoration', 'bottomDecoration', 'leftDecoration', 'rightDecoration'))) { 0149 return ''; 0150 } 0151 0152 if (!is_array($decInfo) 0153 || !array_key_exists('labels', $decInfo) 0154 || !is_array($decInfo['labels']) 0155 ) { 0156 return ''; 0157 } 0158 0159 $id .= '-' . $position; 0160 0161 if (!array_key_exists('dijit', $decInfo)) { 0162 $dijit = 'dijit.form.' . ucfirst($this->_sliderType) . 'Rule'; 0163 } else { 0164 $dijit = $decInfo['dijit']; 0165 if ('dijit.form.' != substr($dijit, 0, 10)) { 0166 $dijit = 'dijit.form.' . $dijit; 0167 } 0168 } 0169 0170 $params = array(); 0171 $attribs = array(); 0172 $labels = $decInfo['labels']; 0173 if (array_key_exists('params', $decInfo)) { 0174 $params = $decInfo['params']; 0175 } 0176 if (array_key_exists('attribs', $decInfo)) { 0177 $attribs = $decInfo['attribs']; 0178 } 0179 0180 $containerParams = null; 0181 if (array_key_exists('container', $params)) { 0182 $containerParams = $params['container']; 0183 unset($params['container']); 0184 } 0185 0186 if (array_key_exists('labels', $params)) { 0187 $labelsParams = $params['labels']; 0188 unset($params['labels']); 0189 } else { 0190 $labelsParams = $params; 0191 } 0192 0193 if (null === $containerParams) { 0194 $containerParams = $params; 0195 } 0196 0197 $containerAttribs = null; 0198 if (array_key_exists('container', $attribs)) { 0199 $containerAttribs = $attribs['container']; 0200 unset($attribs['container']); 0201 } 0202 0203 if (array_key_exists('labels', $attribs)) { 0204 $labelsAttribs = $attribs['labels']; 0205 unset($attribs['labels']); 0206 } else { 0207 $labelsAttribs = $attribs; 0208 } 0209 0210 if (null === $containerAttribs) { 0211 $containerAttribs = $attribs; 0212 } 0213 0214 $containerParams['container'] = $position; 0215 $labelsParams['container'] = $position; 0216 0217 $labelList = $this->_prepareLabelsList($id, $labelsParams, $labelsAttribs, $labels); 0218 0219 $dijit = 'dijit.form.' . ucfirst($this->_sliderType) . 'Rule'; 0220 $containerAttribs['id'] = $id; 0221 $containerAttribs = $this->_prepareDijit($containerAttribs, $containerParams, 'layout', $dijit); 0222 $containerHtml = '<div' . $this->_htmlAttribs($containerAttribs) . "></div>\n"; 0223 0224 switch ($position) { 0225 case 'topDecoration': 0226 case 'leftDecoration': 0227 return $labelList . $containerHtml; 0228 case 'bottomDecoration': 0229 case 'rightDecoration': 0230 return $containerHtml . $labelList; 0231 } 0232 } 0233 0234 /** 0235 * Prepare slider label list 0236 * 0237 * @param string $id 0238 * @param array $params 0239 * @param array $attribs 0240 * @param array $labels 0241 * @return string 0242 */ 0243 protected function _prepareLabelsList($id, array $params, array $attribs, array $labels) 0244 { 0245 $attribs['id'] = $id . '-labels'; 0246 $dijit = 'dijit.form.' . ucfirst($this->_sliderType) . 'RuleLabels'; 0247 $attribs = $this->_prepareDijit($attribs, $params, 'layout', $dijit); 0248 0249 return $this->view->htmlList($labels, true, $attribs); 0250 } 0251 }