Rock.Model.CategoryService.GetNavigationChildren C# (CSharp) Method

GetNavigationChildren() private method

Gets the navigation children.
private GetNavigationChildren ( int parentCategoryId, IEnumerable categories, List selectedCategoryGuids, bool checkSelected, bool includeAllChildren, Person currentPerson ) : List
parentCategoryId int The parent category identifier.
categories IEnumerable The categories.
selectedCategoryGuids List The selected category guids.
checkSelected bool if set to true [check selected].
includeAllChildren bool if set to true [include all children].
currentPerson Person The current person.
return List
        private List<CategoryNavigationItem> GetNavigationChildren( int? parentCategoryId, IEnumerable<Category> categories, List<Guid> selectedCategoryGuids, bool checkSelected, bool includeAllChildren, Person currentPerson )
        {
            var items = new List<CategoryNavigationItem>();

            foreach ( var category in categories
                .Where( c =>
                    c.ParentCategoryId == parentCategoryId ||
                    ( !c.ParentCategoryId.HasValue && !parentCategoryId.HasValue ) )
                .OrderBy( c => c.Order )
                .ThenBy( c => c.Name ) )
            {
                if ( category.IsAuthorized( Rock.Security.Authorization.VIEW, currentPerson ) )
                {
                    bool includeCategory = !checkSelected || selectedCategoryGuids.Contains( category.Guid );
                    bool checkChildSelected = checkSelected;

                    if ( includeCategory )
                    {
                        if ( checkSelected && includeAllChildren )
                        {
                            checkChildSelected = false;
                        }

                        var categoryItem = new CategoryNavigationItem( category );
                        items.Add( categoryItem );

                        // Recurse child categories
                        categoryItem.ChildCategories = GetNavigationChildren( category.Id, categories, selectedCategoryGuids, checkChildSelected, includeAllChildren, currentPerson );
                    }
                    else
                    {
                        foreach ( var categoryItem in GetNavigationChildren( category.Id, categories, selectedCategoryGuids, checkChildSelected, includeAllChildren, currentPerson ) )
                        {
                            items.Add( categoryItem );
                        }
                    }
                }

            }

            return items;
        }