GetNavigationChildren() public method

Gets immediate navigation children of a group (id) or a rootGroupId. Specify 0 for both Id and rootGroupId to get top level groups limited
public GetNavigationChildren ( int id, int rootGroupId, bool limitToSecurityRoleGroups, List groupTypeIncludedIds, List groupTypeExcludedIds, bool includeInactiveGroups = true ) : IQueryable
id int The identifier.
rootGroupId int The root group identifier.
limitToSecurityRoleGroups bool if set to true [limit to security role groups].
groupTypeIncludedIds List The group type included ids.
groupTypeExcludedIds List The group type excluded ids.
includeInactiveGroups bool if set to true [include inactive groups].
return IQueryable
Esempio n. 1
0
        public IQueryable<TreeViewItem> GetChildren( int id, int rootGroupId, bool limitToSecurityRoleGroups, string groupTypeIds )
        {
            var user = CurrentUser();
            if ( user != null )
            {
                var groupService = new GroupService();
                groupService.Repository.SetConfigurationValue( "ProxyCreationEnabled", "false" );
                var qry = groupService.GetNavigationChildren( id, rootGroupId, limitToSecurityRoleGroups, groupTypeIds );

                List<Group> groupList = new List<Group>();
                List<TreeViewItem> groupNameList = new List<TreeViewItem>();

                foreach ( var group in qry )
                {
                    if ( group.IsAuthorized( "View", user.Person ) )
                    {
                        groupList.Add( group );
                        var treeViewItem = new TreeViewItem();
                        treeViewItem.Id = group.Id.ToString();
                        treeViewItem.Name = System.Web.HttpUtility.HtmlEncode( group.Name );

                        // if there a IconCssClass is assigned, use that as the Icon.
                        var groupType = Rock.Web.Cache.GroupTypeCache.Read( group.GroupTypeId );
                        if ( groupType != null )
                        {
                            treeViewItem.IconCssClass = groupType.IconCssClass;
                        }

                        groupNameList.Add( treeViewItem );
                    }
                }

                // try to quickly figure out which items have Children
                List<int> resultIds = groupList.Select( a => a.Id ).ToList();

                var qryHasChildren = from x in Get().Select( a => a.ParentGroupId )
                                     where resultIds.Contains( x.Value )
                                     select x.Value;

                var qryHasChildrenList = qryHasChildren.ToList();

                foreach ( var g in groupNameList )
                {
                    int groupId = int.Parse( g.Id );
                    g.HasChildren = qryHasChildrenList.Any( a => a == groupId );
                }

                return groupNameList.AsQueryable();
            }
            else
            {
                throw new HttpResponseException( HttpStatusCode.Unauthorized );
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Finds the first group.
        /// </summary>
        /// <returns></returns>
        private Group FindFirstGroup()
        {
            // limit GroupType selection to what Block Attributes allow
            List<Guid> groupTypeGuids = GetAttributeValue( "GroupTypes" ).SplitDelimitedValues().Select( Guid.Parse ).ToList();
            string groupTypeIds = "0";
            if ( groupTypeGuids.Any() )
            {
                var groupTypeIdList = new List<int>();
                foreach ( Guid guid in groupTypeGuids )
                {
                    var groupType = GroupTypeCache.Read( guid );
                    if ( groupType != null )
                    {
                        groupTypeIdList.Add( groupType.Id );
                    }
                }

                groupTypeIds = groupTypeIdList.AsDelimited( "," );
                groupTypeIds = string.IsNullOrWhiteSpace( groupTypeIds ) ? "0" : groupTypeIds;
            }

            var groupService = new GroupService( new RockContext() );
            var qry = groupService.GetNavigationChildren( 0, hfRootGroupId.ValueAsInt(), hfLimitToSecurityRoleGroups.Value.AsBoolean(), groupTypeIds );

            foreach ( var group in qry.OrderBy( g => g.Name ) )
            {
                // return first group they are authorized to view
                if ( group.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
                {
                    return group;
                }
            }

            return null;
        }
        /// <summary>
        /// Finds the first group.
        /// </summary>
        /// <returns></returns>
        private Group FindFirstGroup()
        {
            var groupService = new GroupService( new RockContext() );
            var includedGroupTypeIds = hfGroupTypesInclude.Value.SplitDelimitedValues().AsIntegerList().Except( new List<int> { 0 } ).ToList();
            var excludedGroupTypeIds = hfGroupTypesExclude.Value.SplitDelimitedValues().AsIntegerList().Except( new List<int> { 0 } ).ToList();
            var qry = groupService.GetNavigationChildren( 0, hfRootGroupId.ValueAsInt(), hfLimitToSecurityRoleGroups.Value.AsBoolean(), includedGroupTypeIds, excludedGroupTypeIds );

            foreach ( var group in qry.OrderBy( g => g.Name ) )
            {
                // return first group they are authorized to view
                if ( group.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
                {
                    return group;
                }
            }

            return null;
        }
Esempio n. 4
0
        private Group FindFirstGroup()
        {
            var groupService = new GroupService();
            var qry = groupService.GetNavigationChildren( 0, hfRootGroupId.ValueAsInt(), hfLimitToSecurityRoleGroups.Value.AsBoolean(), hfGroupTypes.Value );

            foreach ( var group in qry )
            {
                if ( group.IsAuthorized( "View", CurrentPerson ) )
                {
                    return group;
                }
            }

            return null;
        }