flattenTree() public static method

Return a flattened version of a tree.
public static flattenTree ( array $categories ) : array
$categories array The category tree.
return array Returns the flattened category tree.
 /**
  * Get the data for this module.
  */
 protected function getData()
 {
     // Allow plugins to set different data.
     $this->fireEvent('GetData');
     if ($this->Data) {
         return;
     }
     $categoryModel = new CategoryModel();
     $Categories = $categoryModel->setJoinUserCategory(true)->getChildTree(null);
     $Categories = CategoryModel::flattenTree($Categories);
     $Categories2 = $Categories;
     // Filter out the categories we aren't watching.
     foreach ($Categories2 as $i => $Category) {
         if (!$Category['PermsDiscussionsView'] || !$Category['Following']) {
             unset($Categories[$i]);
         }
     }
     $Data = new Gdn_DataSet($Categories, DATASET_TYPE_ARRAY);
     $Data->datasetType(DATASET_TYPE_OBJECT);
     $this->Data = $Data;
 }
示例#2
0
文件: all.php 项目: vanilla/vanilla
if (!defined('APPLICATION')) {
    exit;
}
if (!function_exists('GetOptions')) {
    include $this->fetchViewLocation('helper_functions', 'categories');
}
echo '<h1 class="H HomepageTitle">' . $this->data('Title') . '</h1>';
if ($Description = $this->Description()) {
    echo wrap($Description, 'div', array('class' => 'P PageDescription'));
}
$this->fireEvent('AfterPageTitle');
$CatList = '';
$MaxDisplayDepth = c('Vanilla.Categories.MaxDisplayDepth') + $this->data('Category.Depth', 0);
$ChildCategories = '';
$CategoryTree = $this->data('CategoryTree');
$Categories = CategoryModel::flattenTree($CategoryTree);
$this->EventArguments['NumRows'] = $Categories;
echo '<ul class="DataList CategoryList">';
foreach ($Categories as $CategoryRow) {
    $Category = (object) $CategoryRow;
    $this->EventArguments['CatList'] =& $CatList;
    $this->EventArguments['ChildCategories'] =& $ChildCategories;
    $this->EventArguments['Category'] =& $Category;
    $this->fireEvent('BeforeCategoryItem');
    $CssClass = CssClass($CategoryRow);
    $CategoryID = val('CategoryID', $Category);
    if ($Category->CategoryID > 0) {
        // If we are below the max depth, and there are some child categories
        // in the $ChildCategories variable, do the replacement.
        if ($Category->Depth < $MaxDisplayDepth && $ChildCategories != '') {
            $CatList = str_replace('{ChildCategories}', '<span class="ChildCategories">' . Wrap(t('Child Categories:'), 'b') . ' ' . $ChildCategories . '</span>', $CatList);