Ejemplo n.º 1
0
function recurseTree($nestArry)
{
    if (is_array($nestArry)) {
        echo "<div>\n";
        foreach ($nestArry as $nest) {
            echo "<div>Name: " . $nest['comment'] . "</div>\n";
            echo "<div style='padding-left: 50px;'>Subcomments: \n";
            recurseTree($nest['subcomments']);
            echo "</div>\n";
        }
        echo "</div>\n";
    }
}
Ejemplo n.º 2
0
 function getTreeAllCategories($filter = array(), $order = null, $orderDir = null)
 {
     $db = JFactory::getDBO();
     $user = JFactory::getUser();
     $lang = JSFactory::getLang();
     $query = "SELECT ordering, category_id, category_parent_id, `" . $lang->get('name') . "` as name, `" . $lang->get('short_description') . "` as short_description, `" . $lang->get('description') . "` as description, category_publish, category_image FROM `#__jshopping_categories`\n                  ORDER BY category_parent_id, " . $this->_allCategoriesOrder($order, $orderDir);
     extract(js_add_trigger(get_defined_vars(), "before"));
     $db->setQuery($query);
     $all_cats = $db->loadObjectList();
     $categories = array();
     if (count($all_cats)) {
         foreach ($all_cats as $key => $category) {
             $category->isPrev = 0;
             $category->isNext = 0;
             if (isset($all_cats[$key - 1]) && $category->category_parent_id == $all_cats[$key - 1]->category_parent_id) {
                 $category->isPrev = 1;
             }
             if (isset($all_cats[$key + 1]) && $category->category_parent_id == $all_cats[$key + 1]->category_parent_id) {
                 $category->isNext = 1;
             }
             if (!$category->category_parent_id) {
                 recurseTree($category, 0, $all_cats, $categories, 0);
             }
         }
     }
     if (count($categories)) {
         if (isset($filter['text_search']) && !empty($filter['text_search'])) {
             $originalCategories = $categories;
             $filter['text_search'] = strtolower($filter['text_search']);
             foreach ($categories as $key => $category) {
                 if (strpos(strtolower($category->name), $filter['text_search']) === false && strpos(strtolower($category->short_description), $filter['text_search']) === false && strpos(strtolower($category->description), $filter['text_search']) === false) {
                     unset($categories[$key]);
                 }
             }
             if (count($categories)) {
                 foreach ($categories as $key => $category) {
                     $categories[$key]->name = "<span class = 'jshop_green'>" . $categories[$key]->name . "</span>";
                     $category_parent_id = $category->category_parent_id;
                     $i = 0;
                     while ($category_parent_id || $i < 1000) {
                         foreach ($originalCategories as $originalKey => $originalCategory) {
                             if ($originalCategory->category_id == $category_parent_id) {
                                 $categories[$originalKey] = $originalCategory;
                                 $category_parent_id = $originalCategory->category_parent_id;
                                 break;
                             }
                         }
                         $i++;
                     }
                 }
                 ksort($categories);
             }
         }
         foreach ($categories as $key => $category) {
             $category->space = '';
             for ($i = 0; $i < $category->level; $i++) {
                 $category->space .= '<span class = "gi">|—</span>';
             }
         }
     }
     return $categories;
 }
Ejemplo n.º 3
0
function buildTreeCategory($publish = 1, $is_select = 1, $access = 1)
{
    $jshopConfig = JSFactory::getConfig();
    $db = JFactory::getDBO();
    $lang = JSFactory::getLang();
    $user = JFactory::getUser();
    $where = array();
    if ($publish) {
        $where[] = "category_publish = '1'";
    }
    if ($access) {
        $groups = implode(',', $user->getAuthorisedViewLevels());
        $where[] = ' access IN (' . $groups . ')';
    }
    $add_where = "";
    if (count($where)) {
        $add_where = " where " . implode(" and ", $where);
    }
    $query = "SELECT `" . $lang->get('name') . "` as name, category_id, category_parent_id, category_publish FROM `#__jshopping_categories`\r\n           \t  " . $add_where . " ORDER BY category_parent_id, ordering";
    $db->setQuery($query);
    $all_cats = $db->loadObjectList();
    $categories = array();
    if (count($all_cats)) {
        foreach ($all_cats as $key => $value) {
            if (!$value->category_parent_id) {
                recurseTree($value, 0, $all_cats, $categories, $is_select);
            }
        }
    }
    return $categories;
}
Ejemplo n.º 4
0
function recurseTree($cat, $level, $all_cats, &$categories, $is_select)
{
    $probil = '';
    if ($is_select) {
        for ($i = 0; $i < $level; $i++) {
            $probil .= '-- ';
        }
        $cat->name = $probil . $cat->name;
        $categories[] = JHTML::_('select.option', $cat->category_id, $cat->name, 'category_id', 'name');
    } else {
        $cat->level = $level;
        $categories[] = $cat;
    }
    foreach ($all_cats as $categ) {
        if ($categ->category_parent_id == $cat->category_id) {
            recurseTree($categ, ++$level, $all_cats, $categories, $is_select);
            $level--;
        }
    }
    return $categories;
}
Ejemplo n.º 5
0
 function getTreeAllCategories($order = null, $orderDir = null)
 {
     $db = JFactory::getDBO();
     $user = JFactory::getUser();
     $lang = JSFactory::getLang();
     $query = "SELECT ordering, category_id, category_parent_id, `" . $lang->get('name') . "` as name, `" . $lang->get('short_description') . "` as short_description, category_publish, category_image FROM `#__jshopping_categories`\n                  ORDER BY category_parent_id, " . $this->_allCategoriesOrder($order, $orderDir);
     $db->setQuery($query);
     $all_cats = $db->loadObjectList();
     $categories = array();
     if (count($all_cats)) {
         foreach ($all_cats as $key => $category) {
             $category->isPrev = 0;
             $category->isNext = 0;
             if (isset($all_cats[$key - 1]) && $category->category_parent_id == $all_cats[$key - 1]->category_parent_id) {
                 $category->isPrev = 1;
             }
             if (isset($all_cats[$key + 1]) && $category->category_parent_id == $all_cats[$key + 1]->category_parent_id) {
                 $category->isNext = 1;
             }
             if (!$category->category_parent_id) {
                 recurseTree($category, 0, $all_cats, $categories, 0);
             }
         }
     }
     if (count($categories)) {
         foreach ($categories as $key => $category) {
             $category->space = '';
             for ($i = 0; $i < $category->level; $i++) {
                 $category->space .= '<span class = "gi">|—</span>';
             }
         }
     }
     return $categories;
 }