/** * Helper-method to return a specified root-category from a tree * * @access public * @param array $tree * @param int $root_id * @return array */ public static function setRoot($tree = null, $root_id = null) { // If no root-category is configured, just return all children if (!$root_id > 0) { return $tree['children']; } // If the current level contains the configured root-category, return it's children if (isset($tree['category_id']) && $tree['category_id'] == $root_id) { return $tree['children']; } // Loop through the children to find the configured root-category if (isset($tree['children']) && is_array($tree['children']) && count($tree['children']) > 0) { foreach ($tree['children'] as $item) { $subtree = modMageBridgeMenuHelper::setRoot($item, $root_id); if (!empty($subtree)) { return $subtree; } } } return array(); }
/** * Joomla! module MageBridge: Catalog Menu * * @author Yireo (info@yireo.com) * @package MageBridge * @copyright Copyright 2015 * @license GNU Public License * @link http://www.yireo.com */ // No direct access defined('_JEXEC') or die('Restricted access'); // Import the MageBridge autoloader require_once JPATH_SITE . '/components/com_magebridge/helpers/loader.php'; require_once dirname(__FILE__) . '/helper.php'; // Read the parameters $root = $params->get('root', 0); $levels = $params->get('levels', 2); $startLevel = $params->get('startlevel', 1); if ($startLevel < 1) { $startLevel = 1; } $endLevel = $startLevel + $levels - 1; $layout = $params->get('layout', 'default'); // Call the helper $catalog_tree = modMageBridgeMenuHelper::build($params); // Load the catalog-tree $rootLevel = !empty($catalog_tree['level']) ? $catalog_tree['level'] : 0; $catalog_tree = modMageBridgeMenuHelper::setRoot($catalog_tree, $root); $catalog_tree = modMageBridgeMenuHelper::parseTree($catalog_tree, $rootLevel + $startLevel, $rootLevel + $endLevel); // Show the template require JModuleHelper::getLayoutPath('mod_magebridge_menu', $layout);