/** * Constructor. * * @param array $config Config array. */ public function __construct(array $config=array()) { $config = array_merge($config, array( 'langs' => array('en'), 'flat' => false, 'parseURL' => false, 'sortable' => false, 'dynamicClass' => 'z-tree-dynamic', 'imagesDir' => 'system/Blocks/images/menutree/', )); parent::__construct($config); }
/** * Zikula_View function to load Zikula_tree. * * Example: * {tree $menuArray=$your_content imagesDir='yout/path/to/images/'} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string The results of the module function */ function smarty_function_tree($params, Zikula_View $view) { $menuString = isset($params['menustring']) ? $params['menustring'] : null; $menuArray = isset($params['menuarray']) ? $params['menuarray'] : null; $treeArray = isset($params['treearray']) ? $params['treearray'] : null; $config = isset($params['config']) ? $params['config'] : array(); if (!isset($menuString) && !isset($menuArray) && !isset($treeArray)) { $view->trigger_error(__f('Error! in %1$s: %2$s, %3$s or %4$s parameter must be specified.', array('smarty_function_tree', 'menustring', 'menuarray', 'treearray'))); return false; } unset($params['menustring']); unset($params['menuarray']); unset($params['treearray']); unset($params['config']); $config = array_merge($config, (array) $params); $tree = new Zikula_Tree($config); if (isset($treeArray)) { $tree->setTreeData($treeArray); } elseif (isset($menuArray)) { $tree->loadArrayData($menuArray); } else { $tree->loadStringData($menuString); } if (isset($params['assign'])) { $view->assign($params['assign'], $tree->getHTML()); } else { return $tree->getHTML(); } }
/** * Get the java-script for the tree menu. * * @param array $cats The categories array to represent in the tree. * @param boolean $doReplaceRootCat Whether or not to replace the root category with a localized string (optional) (default=true). * @param boolean $sortable Sets the zikula tree option sortable (optional) (default=false). * @param array $options Options array for Zikula_Tree. * * @return generated tree JS text. */ public static function getCategoryTreeJS($cats, $doReplaceRootCat = true, $sortable = false, array $options = array()) { $leafNodes = array(); foreach ($cats as $i => $c) { if ($doReplaceRootCat && $c['id'] == 1 && $c['name'] == '__SYSTEM__') { $c['name'] = __('Root category'); } $cats[$i] = self::getCategoryTreeJSNode($c); if ($c['is_leaf']) { $leafNodes[] = $c['id']; } } $tree = new Zikula_Tree(); $tree->setOption('id', 'categoriesTree'); $tree->setOption('sortable', $sortable); // disable drag and drop for root category $tree->setOption('disabled', array(1)); $tree->setOption('disabledForDrop', $leafNodes); if (!empty($options)) { $tree->setOptionArray($options); } $tree->loadArrayData($cats); return $tree->getHTML(); }