/**
  *
  * @return array;
  */
 public function getPicklistOptions()
 {
     $tax_args = array('public' => true, '_builtin' => false);
     $taxonomies = get_taxonomies($tax_args);
     $taxonomies[] = 'category';
     $args = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1, 'hierarchical' => 1, 'taxonomy' => $taxonomies, 'pad_counts' => true);
     $categories = get_categories($args);
     $children = array();
     if ($categories) {
         foreach ($categories as $v) {
             $v->title = $v->cat_name;
             $v->parent_id = $v->category_parent;
             $v->id = $v->cat_ID;
             $pt = $v->category_parent;
             $list = @$children[$pt] ? $children[$pt] : array();
             array_push($list, $v);
             $children[$pt] = $list;
         }
     }
     //treecurse function from functions.php
     $list = treerecurse($children);
     $mitems = array();
     foreach ($list as $item) {
         $mitems[$item->id] = $item->treename;
     }
     return $mitems;
 }
Exemple #2
0
function treerecurse(&$params, $id = 0, $level = 0, $begin = false)
{
    static $output;
    if ($begin) {
        $output = '';
    }
    $mainframe = JFactory::getApplication();
    $root_id = (int) $params->get('root_id');
    $end_level = $params->get('end_level', NULL);
    $id = (int) $id;
    $catid = JRequest::getInt('id');
    $option = JRequest::getCmd('option');
    $view = JRequest::getCmd('view');
    $user = JFactory::getUser();
    $aid = (int) $user->get('aid');
    $db = JFactory::getDBO();
    switch ($params->get('categoriesListOrdering')) {
        case 'alpha':
            $orderby = 'name';
            break;
        case 'ralpha':
            $orderby = 'name DESC';
            break;
        case 'order':
            $orderby = 'ordering';
            break;
        case 'reversedefault':
            $orderby = 'id DESC';
            break;
        default:
            $orderby = 'id ASC';
            break;
    }
    if ($root_id != 0 && $level == 0) {
        $query = "SELECT * FROM #__k2_categories WHERE parent={$root_id} AND published=1 AND trash=0 ";
    } else {
        $query = "SELECT * FROM #__k2_categories WHERE parent={$id} AND published=1 AND trash=0 ";
    }
    if (K2_JVERSION != '15') {
        $query .= " AND access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
        if ($mainframe->getLanguageFilter()) {
            $languageTag = JFactory::getLanguage()->getTag();
            $query .= " AND language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") ";
        }
    } else {
        $query .= " AND access <= {$aid}";
    }
    $query .= " ORDER BY {$orderby}";
    $db->setQuery($query);
    $rows = $db->loadObjectList();
    if ($db->getErrorNum()) {
        echo $db->stderr();
        return false;
    }
    if ($level < intval($end_level) || is_null($end_level)) {
        $output .= '<ul ' . ($params->get('moduleclass_sfx') ? 'class="' . $params->get('moduleclass_sfx') . '"' : '') . '>';
        foreach ($rows as $row) {
            if ($params->get('categoriesListItemsCounter')) {
                $row->numOfItems = ' (' . modK2ToolsHelper::countCategoryItems($row->id) . ')';
            } else {
                $row->numOfItems = '';
            }
            if ($option == 'com_k2' && $view == 'itemlist' && $catid == $row->id) {
                $active = ' class="activeCategory"';
            } else {
                $active = '';
            }
            if (modK2ToolsHelper::hasChildren($row->id)) {
                $output .= '<li ><a href="' . urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($row->id . ':' . urlencode($row->alias)))) . '"><i class="fa fa-caret-right"></i> ' . preg_replace('/--([^-]*)--/', '$1', $row->name) . '</a>' . $row->numOfItems;
                treerecurse($params, $row->id, $level + 1);
                $output .= '</li>';
            } else {
                $output .= '<li><a href="' . urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($row->id . ':' . urlencode($row->alias)))) . '"><i class="fa fa-caret-right"></i> ' . preg_replace('/--([^-]*)--/', '$1', $row->name) . '</a>' . $row->numOfItems . '</li>';
            }
        }
        $output .= '</ul>';
    }
    return $output;
}
 function treerecurse($ParentId, $list, &$children, $maxlevel = 20, $level = 0)
 {
     //if there are children for this id and the max.level isn't reached
     if (@$children[$ParentId] && $level <= $maxlevel) {
         // Add each child to the $list and ask for its children
         foreach ($children[$ParentId] as $v) {
             $id = $v->id;
             //gallery id
             $list[$id] = $v;
             $list[$id]->level = $level;
             //$list[$id]->children = count(@$children[$id]);
             $list = treerecurse($id, $list, $children, $maxlevel, $level + 1);
         }
     }
     return $list;
 }