private function getCategory(&$menu, $id_category, $id_lang = false, $id_shop = false, $is_child_item = false)
 {
     $id_lang = $id_lang ? (int) $id_lang : (int) Context::getContext()->language->id;
     $category = new Category((int) $id_category, (int) $id_lang);
     if ($category->level_depth > 1) {
         $category_link = $category->getLink();
     } else {
         $category_link = $this->context->link->getPageLink('index');
     }
     if (is_null($category->id)) {
         return;
     }
     $children = Category::getChildren((int) $id_category, (int) $id_lang, true, (int) $id_shop);
     $selected = $this->page_name == 'category' && (int) Tools::getValue('id_category') == $id_category ? 'active ' : '';
     $is_intersected = array_intersect($category->getGroups(), $this->user_groups);
     $class = $selected . ($is_child_item ? $this->_subItemClass : $this->_itemClass);
     $head = $is_child_item ? $this->_subItemHead : $this->_itemHead;
     $tail = $is_child_item ? $this->_subItemTail : $this->_itemTail;
     // filter the categories that the user is allowed to see and browse
     if (!empty($is_intersected)) {
         $menu .= $head . '<li class="' . $class . '">';
         $menu .= '<a href="' . $category_link . '"><span>' . $category->name . '</span></a>';
         if (count($children) && ($this->_showAll !== 'one level' || $this->_showAllResponsive !== 'one level')) {
             $menu .= $this->_subMenuHead . '<ul class="' . $this->_subMenuClass . '">';
             foreach ($children as $child) {
                 $this->getCategory($menu, (int) $child['id_category'], (int) $id_lang, (int) $child['id_shop'], true);
             }
             $menu .= '</ul>' . $this->_subMenuTail;
         }
         $menu .= '</li>' . $tail;
     }
 }
Example #2
0
 private function getCategory($id_category, $id_lang = false, $id_shop = false)
 {
     $id_lang = $id_lang ? (int) $id_lang : (int) Context::getContext()->language->id;
     $category = new Category((int) $id_category, (int) $id_lang);
     if ($category->level_depth > 1) {
         $category_link = $category->getLink();
     } else {
         $category_link = $this->context->link->getPageLink('index');
     }
     if (is_null($category->id)) {
         return;
     }
     $children = Category::getChildren((int) $id_category, (int) $id_lang, true, (int) $id_shop);
     $selected = $this->page_name == 'category' && (int) Tools::getValue('id_category') == $id_category ? ' class="sfHoverForce"' : '';
     $is_intersected = array_intersect($category->getGroups(), $this->user_groups);
     // filter the categories that the user is allowed to see and browse
     if (!empty($is_intersected)) {
         $this->_menu .= '<li ' . $selected . '>';
         $this->_menu .= '<a href="' . $category_link . '">' . $category->name . '</a>';
         if (count($children)) {
             $this->_menu .= '<ul>';
             foreach ($children as $child) {
                 $this->getCategory((int) $child['id_category'], (int) $id_lang, (int) $child['id_shop']);
             }
             $this->_menu .= '</ul>';
         }
         $this->_menu .= '</li>';
     }
 }
Example #3
0
 private function getCategory($id_category, $id_lang = false, $id_shop = false)
 {
     $id_lang = $id_lang ? (int) $id_lang : (int) Context::getContext()->language->id;
     $category = new Category((int) $id_category, (int) $id_lang);
     if ($category->level_depth > 1) {
         $category_link = $category->getLink();
     } else {
         $category_link = $this->context->link->getPageLink('index');
     }
     if (is_null($category->id)) {
         return;
     }
     $children = Category::getChildren((int) $id_category, (int) $id_lang, true, (int) $id_shop);
     $selected = $this->page_name == 'category' && (int) Tools::getValue('id_category') == $id_category ? ' class="sfHoverForce"' : '';
     $is_intersected = array_intersect($category->getGroups(), $this->user_groups);
     // filter the categories that the user is allowed to see and browse
     if (!empty($is_intersected)) {
         $this->_menu .= '<li ' . $selected . '>';
         $this->_menu .= '<a href="' . Tools::HtmlEntitiesUTF8($category_link) . '" title="' . $category->name . '">' . $category->name . '</a>';
         if (count($children)) {
             $this->_menu .= '<ul>';
             foreach ($children as $child) {
                 $this->getCategory((int) $child['id_category'], (int) $id_lang, (int) $child['id_shop']);
             }
             if ($category->level_depth == 2) {
                 $files = scandir(_PS_CAT_IMG_DIR_);
                 $this->_menu .= '<li id="category-thumbnail">';
                 foreach ($files as $file) {
                     if (preg_match('/' . $category->id . '-([0-9])?_thumb.jpg/i', $file) === 1) {
                         $this->_menu .= '<div><img src="' . Tools::getShopDomain(true, true) . __PS_BASE_URI__ . basename(_PS_IMG_DIR_) . '/' . basename(_PS_CAT_IMG_DIR_) . '/' . $file . '" alt="' . $category->name . '" class="imgm" /></div>';
                     }
                 }
                 $this->_menu .= '</li>';
             }
             $this->_menu .= '</ul>';
         }
         $this->_menu .= '</li>';
     }
 }
Example #4
0
 private function getCategory($id_category, $id_lang = false, $id_shop = false)
 {
     $id_lang = $id_lang ? (int) $id_lang : (int) Context::getContext()->language->id;
     $category = new Category((int) $id_category, (int) $id_lang);
     if ($category->level_depth > 1) {
         $category_link = $category->getLink();
     } else {
         $category_link = $this->context->link->getPageLink('index');
     }
     if (is_null($category->id)) {
         return;
     }
     $children = Category::getChildren((int) $id_category, (int) $id_lang, true, (int) $id_shop);
     $selected = $this->page_name == 'category' && (int) Tools::getValue('id_category') == $id_category ? ' active ' : '';
     $is_intersected = array_intersect($category->getGroups(), $this->user_groups);
     // filter the categories that the user is allowed to see and browse
     if (!empty($is_intersected)) {
         $this->_menu .= '<li class="' . $selected;
         $add_data = '';
         if ($category->level_depth == 1) {
             $this->_menu .= 'dropdown">';
             $add_data = ' class="dropdown-toggle" data-toggle="dropdown"';
         } elseif ($category->level_depth > 1 && count($children)) {
             $this->_menu .= 'dropdown-submenu">';
         } else {
             $this->_menu .= '">';
         }
         $this->_menu .= '<a' . $add_data . ' href="' . $category_link . '">' . $category->name;
         if (count($children)) {
             $this->_menu .= '<b class="caret"></b>';
         }
         $this->_menu .= '</a>';
         if (count($children)) {
             $this->_menu .= '<ul class="dropdown-menu">';
             foreach ($children as $child) {
                 $this->getCategory((int) $child['id_category'], (int) $id_lang, (int) $child['id_shop']);
             }
             $this->_menu .= '</ul>';
         }
         $this->_menu .= '</li>';
     }
 }