Example #1
0
        private void ListGroups()
        {
            var rockContext = new RockContext();

            var cellGroupsInLine    = LineQuery.GetCellGroupsInLine(CurrentPerson, rockContext, false).ToList();
            int responsibilityCount = cellGroupsInLine.Count;
            var cellGroupdTypeGuid  = org.kcionline.bricksandmortarstudio.SystemGuid.GroupType.CELL_GROUP.AsGuid();

            var cellMemberGroups =
                new GroupMemberService(rockContext).Queryable()
                .Where(
                    gm =>
                    gm.PersonId == CurrentPersonId &&
                    gm.Group.GroupType.Guid == cellGroupdTypeGuid).Select(gm => gm.Group).ToList();

            var allCellGroups = cellGroupsInLine.Union(cellMemberGroups);

            var groups = new List <GroupInvolvementSummary>();

            int totalCount             = 0;
            int amLeaderOfMembersCount = 0;
            int amLeaderOfGroupCount   = 0;

            foreach (var group in allCellGroups)
            {
                bool isLeader = group.Members.Any(gm => gm.GroupRole.IsLeader && gm.PersonId == CurrentPersonId);
                if (isLeader)
                {
                    amLeaderOfMembersCount += group.Members.Count;
                    amLeaderOfGroupCount++;
                }
                bool isMember = group.Members.Any(p => p.Person == CurrentPerson);
                totalCount += group.Members.Count;
                groups.Add(new GroupInvolvementSummary
                {
                    Group       = group,
                    IsLeader    = isLeader,
                    MemberCount = group.Members.Count,
                    IsMember    = isMember
                });
            }

            var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson);

            mergeFields.Add("Groups", groups.OrderBy(gis => gis.Group.Name));
            mergeFields.Add("TotalCount", totalCount);
            mergeFields.Add("ResponsibilityCount", responsibilityCount);
            mergeFields.Add("LeaderOfMemberCount", amLeaderOfMembersCount);
            mergeFields.Add("LeaderOfGroupCount", amLeaderOfGroupCount);
            var linkedPages = new Dictionary <string, object>();

            linkedPages.Add("DetailPage", LinkedPageRoute("DetailPage"));
            mergeFields.Add("LinkedPages", linkedPages);

            string template = GetAttributeValue("LavaTemplate");

            // show debug info
            bool enableDebug = GetAttributeValue("EnableDebug").AsBoolean();

            if (enableDebug && IsUserAuthorized(Authorization.EDIT))
            {
                lDebug.Visible = true;
                lDebug.Text    = mergeFields.lavaDebugInfo();
            }

            lContent.Text = template.ResolveMergeFields(mergeFields);
        }
        ////
        //// Group Methods

        /// <summary>
        /// Displays the view group  using a lava template
        /// </summary>
        private void DisplayViewGroup()
        {
            if (_groupId > 0)
            {
                RockContext  rockContext  = new RockContext();
                GroupService groupService = new GroupService(rockContext);

                bool enableDebug = GetAttributeValue("EnableDebug").AsBoolean();

                var qry = groupService
                          .Queryable("GroupLocations,Members,Members.Person,Members.Person.PhoneNumbers,GroupType")
                          .Where(g => g.Id == _groupId);

                if (!enableDebug)
                {
                    qry = qry.AsNoTracking();
                }

                var group = qry.FirstOrDefault();

                // order group members by name
                if (group != null)
                {
                    group.Members = group.Members.OrderBy(m => m.Person.LastName).ThenBy(m => m.Person.FirstName).ToList();
                }

                var mergeFields = LavaHelper.GetCommonMergeFields(RockPage, CurrentPerson);
                mergeFields.Add("Group", group);

                // add linked pages
                Dictionary <string, object> linkedPages = new Dictionary <string, object>();
                linkedPages.Add("PersonDetailPage", LinkedPageRoute("PersonDetailPage"));
                linkedPages.Add("RosterPage", LinkedPageRoute("RosterPage"));
                linkedPages.Add("AttendancePage", LinkedPageRoute("AttendancePage"));
                linkedPages.Add("CommunicationPage", LinkedPageRoute("CommunicationPage"));
                mergeFields.Add("LinkedPages", linkedPages);

                // add collection of allowed security actions
                Dictionary <string, object> securityActions = new Dictionary <string, object>();
                securityActions.Add("View", group != null && group.IsAuthorized(Authorization.VIEW, CurrentPerson));
                securityActions.Add("Edit", group != null && (group.IsAuthorized(Authorization.EDIT, CurrentPerson) || LineQuery.IsGroupInPersonsLine(group, CurrentPerson)));
                securityActions.Add("Administrate", group != null && group.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson));
                mergeFields.Add("AllowedActions", securityActions);
                mergeFields.Add("Groups", string.Join(",", LineQuery.GetCellGroupsInLine(CurrentPerson, new RockContext(), false).Select(g => g.Name).ToList()));

                mergeFields.Add("LinePermission", LineQuery.IsGroupInPersonsLine(group, CurrentPerson));

                Dictionary <string, object> currentPageProperties = new Dictionary <string, object>();
                currentPageProperties.Add("Id", RockPage.PageId);
                currentPageProperties.Add("Path", Request.Path);
                mergeFields.Add("CurrentPage", currentPageProperties);

                string template = GetAttributeValue("LavaTemplate");

                // show debug info
                if (enableDebug && IsUserAuthorized(Authorization.EDIT))
                {
                    string postbackCommands = @"<h5>Available Postback Commands</h5>
                                                <ul>
                                                    <li><strong>EditGroup:</strong> Shows a panel for modifing group info. Expects a group id. <code>{{ Group.Id | Postback:'EditGroup' }}</code></li>
                                                    <li><strong>AddGroupMember:</strong> Shows a panel for adding group info. Does not require input. <code>{{ '' | Postback:'AddGroupMember' }}</code></li>
                                                    <li><strong>EditGroupMember:</strong> Shows a panel for modifing group info. Expects a group member id. <code>{{ member.Id | Postback:'EditGroupMember' }}</code></li>
                                                    <li><strong>DeleteGroupMember:</strong> Deletes a group member. Expects a group member id. <code>{{ member.Id | Postback:'DeleteGroupMember' }}</code></li>
                                                    <li><strong>SendCommunication:</strong> Sends a communication to all group members on behalf of the Current User. This will redirect them to the communication page where they can author their email. <code>{{ '' | Postback:'SendCommunication' }}</code></li>
                                                </ul>";

                    lDebug.Visible = true;
                    lDebug.Text    = mergeFields.lavaDebugInfo(null, string.Empty, postbackCommands);
                }

                lContent.Text = template.ResolveMergeFields(mergeFields).ResolveClientIds(upnlContent.ClientID);
            }
            else
            {
                lContent.Text = "<div class='alert alert-warning'>No group was available from the querystring.</div>";
            }
        }