getDictionariesList(); $this->addElement( 'multiCheckbox', 'dictionaries', array( 'label' => 'Export Dictionaries', 'multioptions' => array_combine($dictionaries, $dictionaries), 'columns' => 2, ) ); $this->addElement( 'checkboxTree', 'pages', array( 'label' => 'Select Pages', 'required' => true, 'multioptions' => $this->_getPages4MultiSelect(), 'hasLinks' => false ) ); $errorsDecorator = $this->getElement('pages')->getDecorator('Errors'); $errorsDecorator->setOption('placement', \Zend_Form_Decorator_Errors::PREPEND); return $this; } /** * @return array */ protected function _getPages4MultiSelect() { $result = array(); $sitemap = \App_Cms_Obj::getInstance()->getSiteMap(); $this->_prepareSitemap($sitemap, $result); return $result; } /** * @param array $sitemap * @param array $result * @return ExportForm */ protected function _prepareSitemap(array $sitemap, array &$result) { $additional = array(); foreach ($sitemap as $page) { if ('y' === $page['isAdditional']) { $destination = &$additional; } else { $destination = &$result; } $destination[$page['id']] = $this->_getNode($page); if (!empty($page['sub'])) { $destination[$page['id']]['sub'] = array(); $this->_prepareSitemapSub($page['sub'], $destination[$page['id']]['sub']); } } $result = array_merge($result, $additional); return $this; } /** * @param array $sitemap * @param array $result * @return ExportForm */ protected function _prepareSitemapSub(array $sitemap, array &$result) { foreach ($sitemap as $page) { $result[$page['id']] = $this->_getNode($page); if (!empty($page['sub'])) { $result[$page['id']]['sub'] = array(); $this->_prepareSitemapSub($page['sub'], $result[$page['id']]['sub']); } } return $this; } /** * @param array $page * @return array */ protected function _getNode(array $page) { $node = array( 'id' => $page['id'], 'title' => $page['menuTitle'], ); return $node; } protected function _initButtons() { if (!$this->_hasButtons) { return $this; } $this->addElement('submit', 'btnSubmit', array('label' => 'Export', 'attribs' => array('class' => 'btn btn-primary'))); $this->addElement( 'submit', 'btnCancel', array( 'label' => 'Reset', 'attribs' => array( 'class' => 'btn', 'onclick' => "window.location.href = '" . htmlspecialchars($this->getCancelUrl()) . "';", 'helper' => 'formInputButton', ), ) ); $this->addDisplayGroup(array('btnSubmit', 'btnCancel'), 'submitGroup'); return $this; } }