_panes[$id])) { $this->_panes[$id] = array(); } if(strlen($name) == 0 && isset($options['title'])) { $name = $options['title']; } $this->_panes[$id][] = array('name' => $name, 'content' => $content, 'options' => $options); return $this; } /** * Render Accordion with the currently registered elements. * * If no arguments are given, the accordion object is returned so that * chaining the {@link addPane()} function allows to register new elements * for an accordion. * * @link http://docs.jquery.com/UI/Accordion * @param string $id * @param array $params * @param array $attribs * @return string|ZendX_JQuery_View_Helper_AccordionContainer */ public function accordionContainer($id=null, array $params=array(), array $attribs=array()) { if(0 === func_num_args()) { return $this; } if(!isset($attribs['id'])) { $attribs['id'] = $id; } $html = ""; if(isset($this->_panes[$id])) { foreach($this->_panes[$id] AS $element) { $html .= sprintf($this->getElementHtmlTemplate(), $element['name'], $element['content']).PHP_EOL; } if(count($params) > 0) { $params = ZendX_JQuery::encodeJson($params); } else { $params = "{}"; } $js = sprintf('%s("#%s").accordion(%s);', ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(), $attribs['id'], $params ); $this->jquery->addOnLoad($js); $html = $this->getAccordionTemplate($attribs, $html); } return $html; } /** * @param array $attribs * @param string $html * @return string */ protected function getAccordionTemplate($attribs, $html) { if(version_compare($this->jquery->getUiVersion(), "1.7.0") >= 0) { $html = '_htmlAttribs($attribs) . '>'.PHP_EOL . $html . ''.PHP_EOL; } else { $html = '_htmlAttribs($attribs) . '>'.PHP_EOL . $html . ''.PHP_EOL; } return $html; } /** * @return string */ protected function getElementHtmlTemplate() { if($this->_elementHtmlTemplate == null) { if(version_compare($this->jquery->getUiVersion(), "1.7.0") >= 0) { $this->_elementHtmlTemplate = '

%s

%s
'; } else { $this->_elementHtmlTemplate = '
  • %s
    %s
  • '; } } return $this->_elementHtmlTemplate; } /** * Set the accordion element template * * @param string $htmlTemplate * @return ZendX_JQuery_View_Helper_AccordionContainer */ public function setElementHtmlTemplate($htmlTemplate) { if(substr_count($htmlTemplate, '%s') != 2) { require_once "ZendX/JQuery/View/Exception.php"; throw new ZendX_JQuery_View_Exception( "Accordion Container HTML Template requires two sprintf() string replace markers '%s'." ); } $this->_elementHtmlTemplate = $htmlTemplate; return $this; } }