• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/ZendX/JQuery/View/Helper/AccordionContainer.php

00001 <?php
00026 require_once "ZendX/JQuery/View/Helper/UiWidget.php";
00027 
00037 class ZendX_JQuery_View_Helper_AccordionContainer extends ZendX_JQuery_View_Helper_UiWidget
00038 {
00042     protected $_panes = array();
00043 
00047     protected $_elementHtmlTemplate = null;
00048 
00057     public function addPane($id, $name, $content, array $options=array())
00058     {
00059         if(!isset($this->_panes[$id])) {
00060             $this->_panes[$id] = array();
00061         }
00062         if(strlen($name) == 0 && isset($options['title'])) {
00063             $name = $options['title'];
00064         }
00065         $this->_panes[$id][] = array('name' => $name, 'content' => $content, 'options' => $options);
00066         return $this;
00067     }
00068 
00082     public function accordionContainer($id=null, array $params=array(), array $attribs=array())
00083     {
00084         if(0 === func_num_args()) {
00085             return $this;
00086         }
00087 
00088         if(!isset($attribs['id'])) {
00089             $attribs['id'] = $id;
00090         }
00091 
00092         $html = "";
00093         if(isset($this->_panes[$id])) {
00094             foreach($this->_panes[$id] AS $element) {
00095                 $html .= sprintf($this->getElementHtmlTemplate(), $element['name'], $element['content']).PHP_EOL;
00096             }
00097 
00098             if(count($params) > 0) {
00099                 $params = ZendX_JQuery::encodeJson($params);
00100             } else {
00101                 $params = "{}";
00102             }
00103 
00104             $js = sprintf('%s("#%s").accordion(%s);',
00105                 ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(),
00106                 $attribs['id'],
00107                 $params
00108             );
00109             $this->jquery->addOnLoad($js);
00110 
00111             $html = $this->getAccordionTemplate($attribs, $html);
00112         }
00113         return $html;
00114     }
00115 
00121     protected function getAccordionTemplate($attribs, $html)
00122     {
00123         if(version_compare($this->jquery->getUiVersion(), "1.7.0") >= 0) {
00124             $html = '<div'
00125                   . $this->_htmlAttribs($attribs)
00126                   . '>'.PHP_EOL
00127                   . $html
00128                   . '</div>'.PHP_EOL;
00129         } else {
00130             $html = '<ul'
00131                   . $this->_htmlAttribs($attribs)
00132                   . '>'.PHP_EOL
00133                   . $html
00134                   . '</ul>'.PHP_EOL;
00135         }
00136         return $html;
00137     }
00138 
00142     protected function getElementHtmlTemplate()
00143     {
00144         if($this->_elementHtmlTemplate == null) {
00145             if(version_compare($this->jquery->getUiVersion(), "1.7.0") >= 0) {
00146                 $this->_elementHtmlTemplate = '<h3><a href="#">%s</a></h3><div>%s</div>';
00147             } else {
00148                 $this->_elementHtmlTemplate = '<li class="ui-accordion-group"><a href="#" class="ui-accordion-header">%s</a><div class="ui-accordion-content">%s</div></li>';
00149             }
00150         }
00151         return $this->_elementHtmlTemplate;
00152     }
00153 
00160     public function setElementHtmlTemplate($htmlTemplate)
00161     {
00162         if(substr_count($htmlTemplate, '%s') != 2) {
00163             require_once "ZendX/JQuery/View/Exception.php";
00164             throw new ZendX_JQuery_View_Exception(
00165                 "Accordion Container HTML Template requires two sprintf() string replace markers '%s'."
00166             );
00167         }
00168         $this->_elementHtmlTemplate = $htmlTemplate;
00169         return $this;
00170     }
00171 }

Generated on Thu Apr 19 2012 17:01:18 for openbiz by  doxygen 1.7.2