예제 #1
0
 /**
  * Recursive function to parse the category-tree in a flat-list
  *
  * @param array $tree
  * @param array $list
  *
  * @return array
  */
 public static function getCategoryList($tree = null, $list = array())
 {
     // Determine if this node has children
     if (isset($tree['children']) && count($tree['children']) > 0) {
         $tree['has_children'] = true;
         $children = $tree['children'];
         unset($tree['children']);
     } else {
         $tree['has_children'] = false;
     }
     // Add non-root categories to the list
     if (isset($tree['level']) && $tree['level'] > 0) {
         $tree['indent'] = '';
         for ($i = 1; $i < $tree['level']; $i++) {
             $tree['indent'] .= '&nbsp; -';
         }
         $list[] = $tree;
     }
     // Parse the children
     if (!empty($children)) {
         foreach ($children as $child) {
             $list = MageBridgeElementHelper::getCategoryList($child, $list);
         }
     }
     return $list;
 }
 public function doCategoryLayout()
 {
     // Initialize some important variables
     $application = JFactory::getApplication();
     $option = JRequest::getCmd('option') . '-element-categories';
     // Set common options
     $this->setTitle('Category');
     $this->setLayout('category');
     // Set the data
     $cache = JFactory::getCache('com_magebridge_admin');
     $cache->setCaching(0);
     $tree = $cache->call(array('MageBridgeElementHelper', 'getCategoryTree'));
     $categories = MageBridgeElementHelper::getCategoryList($tree);
     // Initialize pagination
     $categories = $this->initPagination('categories', $categories);
     $this->assignRef('categories', $categories);
     // Initialize search
     $search = $application->getUserStateFromRequest($option . '.search', 'search', '', 'string');
     $search = JString::strtolower($search);
     // Add a dropdown list for Store Views
     require_once JPATH_COMPONENT . '/elements/store.php';
     $current_store = $application->getUserStateFromRequest($option . '.store', 'store');
     $store = JElementStore::fetchElement('store', $current_store, null, null, 'onChange="document.adminForm.submit();return false;"');
     // Build the lists
     $lists = array();
     $lists['search'] = $search;
     $lists['store'] = $store;
     $this->assignRef('lists', $lists);
 }
예제 #3
0
 /**
  * Initialize the category-layout
  */
 public function doCategoryLayout()
 {
     // Initialize some important variables
     $application = JFactory::getApplication();
     $option = $application->input->getCmd('option') . '-element-categories';
     // Set common options
     $this->setTitle('Category');
     $this->setLayout('category');
     // Initialize search
     $search = $application->getUserStateFromRequest($option . '.search', 'search', '', 'string');
     $search = strtolower($search);
     /** @var JCache $cache */
     $cache = JFactory::getCache('com_magebridge.admin');
     $tree = $cache->call(array('MageBridgeElementHelper', 'getCategoryTree'));
     // If search is active, we use a flat list instead of a tree
     if (empty($search)) {
         $categories = MageBridgeElementHelper::getCategoryList($tree);
     } else {
         $categories = $tree;
     }
     // Initialize pagination
     $this->categories = $this->initPagination('categories', $categories);
     // Add a dropdown list for Store Views
     $current_store = $application->getUserStateFromRequest($option . '.store', 'store');
     require_once JPATH_COMPONENT . '/fields/store.php';
     $field = JFormHelper::loadFieldType('magebridge.store');
     $field->setName('store');
     $field->setValue($current_store);
     $store = $field->getHtmlInput();
     // Build the lists
     $lists = array();
     $lists['search'] = $search;
     $lists['store'] = $store;
     $this->lists = $lists;
 }