Exemple #1
0
        private void LoadFilterOptions(bool isEditor)
        {
            if (isEditor)
            {
                if (cbShow.Items.FindByValue("All") == null)
                {
                    cbShow.Items.Add(new ListItem("All", "All"));
                }
            }
            else
            {
                if (cbShow.Items.FindByValue("All") != null)
                {
                    cbShow.Items.Remove(cbShow.Items.FindByValue("All"));
                }
            }

            Group locationAdminGroup = new GroupService(new RockContext()).Get(GetAttributeValue("LocationAdminGroup").AsGuid());

            if (!(isEditor || (locationAdminGroup != null && locationAdminGroup.ActiveMembers().Where(m => m.PersonId == CurrentPerson.Id).Any())))
            {
                cbShow.Items.Remove(cbShow.Items.FindByValue("Location"));
            }

            hfFilterSubmittedBy.Visible = isEditor;
            chkShowInactive.Visible     = isEditor;
            ddlMinistry.Visible         = isEditor;
            ddlLocation.Visible         = isEditor;
            pnlRequester.Visible        = isEditor;
        }
Exemple #2
0
        private void LoadFilters()
        {
            LoadStatusList();
            LoadLocationList();
            LoadMinistryList();
            LoadFiscalYearList();
            //SetRequesterFilter( 0 );
            ddlMinistry.Visible    = UserCanEdit;
            ddlSCCLocation.Visible = UserCanEdit;
            requester.Visible      = UserCanEdit;
            txtGLAccount.Visible   = UserCanEdit;
            ddlFiscalYear.Visible  = UserCanEdit;

            SetRequestedByAllOption(UserCanEdit);

            Group locationAdminGroup = new GroupService(new RockContext()).Get(GetAttributeValue("LocationAdminGroup").AsGuid());

            if (!(UserCanEdit || (locationAdminGroup != null && locationAdminGroup.ActiveMembers().Where(m => m.PersonId == CurrentPerson.Id).Any())))
            {
                cblShow.Items.Remove(cblShow.Items.FindByValue("Location"));
            }
        }
Exemple #3
0
        /// <summary>
        /// Gets the filter person Ids based on dataview and optout group
        /// </summary>
        /// <param name="campaignConfiguration">The campaign configuration.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private static List <int> GetFilteredPersonIds(CampaignItem campaignConfiguration, RockContext rockContext)
        {
            var dataView               = new DataViewService(rockContext).Get(campaignConfiguration.DataViewGuid);
            var personService          = new PersonService(rockContext);
            int recordStatusInactiveId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid()).Id;
            var filteredPersonIds      = new List <int>();

            var dataViewGetQueryArgs = new DataViewGetQueryArgs();
            var personQuery          = dataView.GetQuery(dataViewGetQueryArgs).OfType <Rock.Model.Person>().Where(a => a.RecordStatusValueId != recordStatusInactiveId);

            if (campaignConfiguration.FamilyLimits == FamilyLimits.HeadOfHouse)
            {
                var familyMembersQuery = personQuery
                                         .Where(a => a.PrimaryFamily != null)
                                         .SelectMany(a => a.PrimaryFamily.Members)
                                         .Distinct();

                //// Get all family group Id and all it's family member in dictionary.
                //// We will all the family members to both figure out if might be opted out
                //// and to figure out the head of household
                var familyWithMembers = familyMembersQuery.AsNoTracking()
                                        .Select(a => new
                {
                    a.GroupId,
                    a.PersonId,
                    PersonIsActive   = a.Person.RecordStatusValueId != recordStatusInactiveId,
                    PersonIsDeceased = a.Person.IsDeceased,
                    GroupRoleOrder   = a.GroupRole.Order,
                    PersonGender     = a.Person.Gender
                })
                                        .ToList()
                                        .GroupBy(a => a.GroupId)
                                        .ToDictionary(k => k.Key, v => v);

                if (campaignConfiguration.OptOutGroupGuid.HasValue)
                {
                    var optOutGroup = new GroupService(rockContext).Get(campaignConfiguration.OptOutGroupGuid.Value);
                    if (optOutGroup != null)
                    {
                        var personIds = optOutGroup.ActiveMembers().Select(a => a.PersonId).ToList();

                        // exclude families in which any member is part of optOut Group.
                        familyWithMembers = familyWithMembers.Where(a => !a.Value.Any(b => personIds.Contains(b.PersonId))).ToDictionary(a => a.Key, b => b.Value);
                    }
                }

                foreach (var familyId in familyWithMembers.Keys)
                {
                    /* 2020-05-07 MDP
                     * It is possible that a person is the Head Of Household in more than one family. For example:
                     * -- Alex is in Ted Decker family. Ted Decker is Head of Household
                     * -- Ted Decker is in Grandpa Decker family, and also the head of household for that one too
                     *
                     * We'll deal with that by putting a Distinct on the filteredPersonIds
                     */

                    // Get all the head of house personIds of leftout family.
                    var headOfHouse = familyWithMembers[familyId]
                                      .Where(m => !m.PersonIsDeceased && m.PersonIsActive)
                                      .OrderBy(m => m.GroupRoleOrder)
                                      .ThenBy(m => m.PersonGender)
                                      .Select(a => a.PersonId)
                                      .FirstOrDefault();

                    if (headOfHouse != default(int))
                    {
                        filteredPersonIds.Add(headOfHouse);
                    }
                }
            }
            else
            {
                var personIdList = personQuery.Select(a => a.Id).ToList();
                if (campaignConfiguration.OptOutGroupGuid.HasValue)
                {
                    var optOutGroup = new GroupService(rockContext).Get(campaignConfiguration.OptOutGroupGuid.Value);
                    if (optOutGroup != null)
                    {
                        var personIds = optOutGroup.ActiveMembers().Select(a => a.PersonId).ToList();
                        personIdList = personIdList.Where(a => !personIds.Contains(a)).ToList();
                    }
                }

                filteredPersonIds = personIdList;
            }

            // just in case the same person is in multiple times (for example, head of household in multiple families), get just the distinct person ids
            filteredPersonIds = filteredPersonIds.Distinct().ToList();

            return(filteredPersonIds);
        }
Exemple #4
0
        /// <summary>
        /// Gets the filter person Ids based on dataview and optout group
        /// </summary>
        /// <param name="campaignConfiguration">The campaign configuration.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        private static List <int> GetFilteredPersonIds(CampaignItem campaignConfiguration, RockContext rockContext, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            var dataView      = new DataViewService(rockContext).Get(campaignConfiguration.DataViewGuid);
            var personService = new PersonService(rockContext);

            var filteredPersonIds = new List <int>();
            var personList        = dataView.GetQuery(null, null, out errorMessages).OfType <Rock.Model.Person>().AsNoTracking().ToList();

            if (!personList.Any())
            {
                return(filteredPersonIds);
            }

            if (campaignConfiguration.FamilyLimits == FamilyLimits.HeadOfHouse)
            {
                var familyWithMembers = new Dictionary <int, List <GroupMember> >();

                //// Get all family group Id and all it's family member in dictionary.
                //// We will all the family members to both figure out if might be opted out
                //// and to figure out the head of household
                foreach (var person in personList)
                {
                    var family = person.GetFamily(rockContext);
                    if (family != null && !familyWithMembers.ContainsKey(family.Id))
                    {
                        var familyMembers = personService.GetFamilyMembers(family, person.Id, true).AsNoTracking().ToList();
                        familyWithMembers.Add(family.Id, familyMembers);
                    }
                }

                if (campaignConfiguration.OptOutGroupGuid.HasValue)
                {
                    var optOutGroup = new GroupService(rockContext).Get(campaignConfiguration.OptOutGroupGuid.Value);
                    if (optOutGroup != null)
                    {
                        var personIds = optOutGroup.ActiveMembers().Select(a => a.PersonId).ToList();

                        // exclude families in which any member is part of optOut Group.
                        familyWithMembers = familyWithMembers.Where(a => !a.Value.Any(b => personIds.Contains(b.PersonId))).ToDictionary(a => a.Key, b => b.Value);
                    }
                }

                foreach (var familyId in familyWithMembers.Keys)
                {
                    /* 2020-05-07 MDP
                     * It is possible that a person is the Head Of Household in more than one family. For example:
                     * -- Alex is in Ted Decker family. Ted Decker is Head of Household
                     * -- Ted Decker is in Grandpa Decker family, and also the head of household for that one too
                     *
                     * We'll deal with that by putting a Distinct on the filteredPersonIds
                     */

                    // Get all the head of house personIds of leftout family.
                    var headOfHouse = familyWithMembers[familyId]
                                      .Where(m => !m.Person.IsDeceased)
                                      .OrderBy(m => m.GroupRole.Order)
                                      .ThenBy(m => m.Person.Gender)
                                      .Select(a => a.PersonId)
                                      .FirstOrDefault();

                    if (headOfHouse != default(int))
                    {
                        filteredPersonIds.Add(headOfHouse);
                    }
                }
            }
            else
            {
                if (campaignConfiguration.OptOutGroupGuid.HasValue)
                {
                    var optOutGroup = new GroupService(rockContext).Get(campaignConfiguration.OptOutGroupGuid.Value);
                    if (optOutGroup != null)
                    {
                        var personIds = optOutGroup.ActiveMembers().Select(a => a.PersonId).ToList();
                        personList = personList.Where(a => !personIds.Contains(a.Id)).ToList();
                    }
                }

                filteredPersonIds = personList.Select(a => a.Id).ToList();
            }

            // just in case the same person is in multiple times (for example, head of household in multiple families), get just the distinct person ids
            filteredPersonIds = filteredPersonIds.Distinct().ToList();

            return(filteredPersonIds);
        }