Question

Photo of Ken Roach

0

How can I view a list of groups in a Block List that are linked to a parent group?

I'm trying to do a drill down from Small Group Section down to Small Groups in that Small Group Section.

I have a block that list the Small Group Sections.

GrpDrill1.jpg

The Detail Page link is set to the next page, where I have a Block List block added.  In this block I have selected the group type 'Small Group' . I want to see only those small groups linked to the parent group, the Section A Small Group Section.  But I get a list of all groups.  Is there any way I can restrict it to the parent group?

GrpDrill2.jpg

  • Photo of Nick Airdo

    0

    Ken, if I correctly understand what you're saying:

    • A starting page with a GroupList block which is set to only show group's of type "Small Group Section" and points to this page:
    • A 'detail' page with another GroupList block which is set to only show group's of type "Small Group".

    ...the only way I know to do this would be to "develop" a custom version of the GroupList block. This custom block would take a given GroupId page parameter and perform some additional "Where" filtering. This is too advanced of an answer for this forum, but for the sake of completeness, I'm going explain the cons of this approach and explain how to do it.

    The Cons

    If you ever find yourself wanting to customize a core block -- remember this: DON'T DO IT.  Any changes you make to a core block will be wiped out during an update. At best, you should have your developer carefully make a custom copy of the block and put it in under the Plugins folder.  Even so, your custom copy can potentially become 'out of phase' with future versions of Rock and will either miss out on new features or break if some underlying thing changes (hopefully rare).

    NOTE: The remainder of answer is really meant for the developer community and follow up discussion should really go to the Developer Q&A.

    The Approach

    Here is the approach I would tell a developer to take if he/she had to go down this path.  Before even thinking about the custom modifications you want to make, do the following:

    1. Make a folder under the Plugins folder called "com_yourdomain" and inside there create a "Core" folder. This is how you'll remember which core stuff you modified that you need to worry about after an update/upgrade.
    2. Make another folder under Core with the name of the core block's original parent folder (in this case above it would be "Groups").
    3. Now copy the core block to this new folder and immediately edit the contents of the *.ascx and *.ascx.cs files to reflect your ownership of this new block (and to prevent Rock from incorrectly registering this new block type.). 
    4. Edit the *.ascx file replacing this: Inherits="RockWeb.Blocks.Groups.GroupList" with this Inherits="RockWeb.Plugins.com_yourdomain.Core.Groups.GroupList" 
    5. Edit the *.ascx.cs file replacing the namespace from this namespace RockWeb.Blocks.Groups to this namespace RockWeb.Plugins.com_yourdomain.Core.Groups
    6. Also, replace the [Category( "Groups" )] with [Category( "com_yourdomain > Core Groups" )]

    Now you can make your modifications and then test them before deploying to your page.

    In your particular case you could add some additional code immediately after these lines in the BindGrid() method:

        var qryGroups = groupService.Queryable()
                    .Where( g => groupTypeIds.Contains( g.GroupTypeId ) && ( !onlySecurityGroups || g.IsSecurityRole ) );

    Below those lines add these:

       // this takes the GroupId page parameter (if any) and restricts the groups to those that
       // have this as their parent group.
       int? groupId = PageParameter( "GroupId" ).AsIntegerOrNull();
       if ( groupId.HasValue )
       {
           qryGroups = qryGroups.Where( g => g.ParentGroupId == groupId.Value );
       }

    Next, go to the Admin Tools > CMS Configuration > Block Types and verify that your new block is correctly registered.

    Lastly, go to the page where you want to use this block and swap it with the one that's currently in use.

    CustomCoreBlock.png 

    • Ken Roach

      Thank you for replying Nick, and for your detailed answer. Really appreciate it. Just what I wanted to know.

      Perhaps I could make a suggestion to the black book that the 'Parent Group' could be added as a Block Attribute of the BlockList block - this would make the BlockList block more versatile?


      (Would be good if there was a way to move this question over to the Developer forum. I realised I'd probably asked it in the wrong forum afterwards.)

    • Ken Roach

      Have added a Black Book suggestion to add a block attribute to the BlockList and BlockListPersonalizedLava blocks to ask 'Restrict groups to those of parent group'. This gives the functionality to be able to drill down an arm of the Group tree using these blocks.