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;
}