コード例 #1
0
ファイル: Address.cs プロジェクト: SparkDevNetwork/Rock
        /// <inheritdoc/>
        public override IOrderedQueryable <object> SearchQuery(string searchTerm)
        {
            var rockContext        = new RockContext();
            var personService      = new PersonService(rockContext);
            var groupMemberService = new GroupMemberService(rockContext);

            var personIdQry = groupMemberService.GetPersonIdsByHomeAddress(searchTerm);

            return(personService.Queryable()
                   .Where(p => personIdQry.Contains(p.Id))
                   .OrderBy(p => p.NickName)
                   .ThenBy(p => p.LastName));
        }
コード例 #2
0
        private void BindGrid()
        {
            var birthDateCol = gPeople.ColumnsOfType <DateField>().First(c => c.DataField == "BirthDate");
            var ageCol       = gPeople.ColumnsOfType <RockBoundField>().First(c => c.DataField == "Age");
            var genderCol    = gPeople.ColumnsOfType <RockBoundField>().First(c => c.DataField == "Gender");

            var envelopeNumberField = gPeople.ColumnsOfType <RockLiteralField>().First(c => c.ID == "lEnvelopeNumber");
            var spouseCol           = gPeople.ColumnsOfType <RockTemplateField>().First(c => c.HeaderText == "Spouse");

            var personGivingEnvelopeAttribute = AttributeCache.Get(Rock.SystemGuid.Attribute.PERSON_GIVING_ENVELOPE_NUMBER.AsGuid());

            if (personGivingEnvelopeAttribute != null)
            {
                envelopeNumberField.Visible = GlobalAttributesCache.Get().EnableGivingEnvelopeNumber&& this.GetAttributeValue("ShowEnvelopeNumber").AsBoolean();
            }
            else
            {
                envelopeNumberField.Visible = false;
            }

            birthDateCol.Visible = GetAttributeValue("ShowBirthdate").AsBoolean();
            ageCol.Visible       = GetAttributeValue("ShowAge").AsBoolean();
            genderCol.Visible    = GetAttributeValue("ShowGender").AsBoolean();
            spouseCol.Visible    = _showSpouse;

            string type = PageParameter("SearchType");
            string term = PageParameter("SearchTerm");

            if (!string.IsNullOrWhiteSpace(type) && !string.IsNullOrWhiteSpace(term))
            {
                term = term.Trim();
                type = type.Trim();
                var rockContext = new RockContext();

                var personService          = new PersonService(rockContext);
                IQueryable <Person> people = null;

                switch (type.ToLower())
                {
                case ("name"):
                {
                    bool allowFirstNameOnly = false;
                    if (!bool.TryParse(PageParameter("allowFirstNameOnly"), out allowFirstNameOnly))
                    {
                        allowFirstNameOnly = false;
                    }
                    people = personService.GetByFullName(term, allowFirstNameOnly, true);
                    break;
                }

                case ("phone"):
                {
                    var phoneService = new PhoneNumberService(rockContext);
                    var personIds    = phoneService.GetPersonIdsByNumber(term);
                    people = personService.Queryable().Where(p => personIds.Contains(p.Id));
                    break;
                }

                case ("address"):
                {
                    var groupMemberService = new GroupMemberService(rockContext);
                    var personIds2         = groupMemberService.GetPersonIdsByHomeAddress(term);
                    people = personService.Queryable().Where(p => personIds2.Contains(p.Id));
                    break;
                }

                case ("email"):
                {
                    var searchKeyQry = new PersonSearchKeyService(rockContext).Queryable();
                    people = personService.Queryable()
                             .Where(p => (term != "" && p.Email == term) ||
                                    searchKeyQry.Any(a => a.PersonAlias.PersonId == p.Id && a.SearchValue == term));
                    break;
                }

                case ("birthdate"):
                {
                    DateTime?birthDate = Request.QueryString["birthdate"].AsDateTime();
                    int?     personId  = Request.QueryString["person-id"].AsIntegerOrNull();
                    if (birthDate == null)
                    {
                        birthDate = term.AsDateTime();
                    }

                    if (personId.HasValue)
                    {
                        people = personService.Queryable().Where(a => a.Id == personId.Value);
                    }
                    else
                    {
                        people = personService.Queryable().Where(p => p.BirthDate.HasValue && birthDate.HasValue && p.BirthDate == birthDate.Value);
                    }

                    break;
                }
                }

                IEnumerable <int> personIdList = people.Select(p => p.Id);

                // just leave the personIdList as a Queryable if it is over 10000 so that we don't throw a SQL exception due to the big list of ids
                if (people.Count() < 10000)
                {
                    personIdList = personIdList.ToList();
                }

                people = personService.Queryable(true).Where(p => personIdList.Contains(p.Id));

                SortProperty sortProperty = gPeople.SortProperty;
                if (sortProperty != null)
                {
                    people = people.Sort(sortProperty);
                }
                else
                {
                    people = people.OrderBy(p => p.LastName).ThenBy(p => p.FirstName);
                }

                var familyGroupType   = GroupTypeCache.GetFamilyGroupType();
                int familyGroupTypeId = familyGroupType != null ? familyGroupType.Id : 0;

                var groupLocationTypeHome = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid());
                int homeAddressTypeId     = groupLocationTypeHome != null ? groupLocationTypeHome.Id : 0;

                var personList = people.Select(p => new PersonSearchResult
                {
                    Id         = p.Id,
                    FirstName  = p.FirstName,
                    NickName   = p.NickName,
                    LastName   = p.LastName,
                    BirthDate  = p.BirthDate,
                    BirthYear  = p.BirthYear,
                    BirthMonth = p.BirthMonth,
                    BirthDay   = p.BirthDay,
                    ConnectionStatusValueId = p.ConnectionStatusValueId,
                    RecordStatusValueId     = p.RecordStatusValueId,
                    RecordTypeValueId       = p.RecordTypeValueId,
                    AgeClassification       = p.AgeClassification,
                    SuffixValueId           = p.SuffixValueId,
                    IsDeceased = p.IsDeceased,
                    Email      = p.Email,
                    Gender     = p.Gender,
                    PhotoId    = p.PhotoId,
                    CampusIds  = p.Members
                                 .Where(m =>
                                        m.Group.GroupTypeId == familyGroupTypeId &&
                                        m.Group.CampusId.HasValue)
                                 .Select(m => m.Group.CampusId.Value)
                                 .ToList(),
                    HomeAddresses = p.Members
                                    .Where(m => m.Group.GroupTypeId == familyGroupTypeId)
                                    .SelectMany(m => m.Group.GroupLocations)
                                    .Where(gl => gl.GroupLocationTypeValueId == homeAddressTypeId)
                                    .Select(gl => gl.Location),
                    PhoneNumbers = p.PhoneNumbers
                                   .Where(n => n.NumberTypeValueId.HasValue)
                                   .Select(n => new PersonSearchResultPhone
                    {
                        NumberTypeValueId = n.NumberTypeValueId.Value,
                        Number            = n.NumberFormatted,
                        PhoneTypeName     = n.NumberTypeValue.Value
                    })
                                   .ToList(),
                    TopSignalColor        = p.TopSignalColor,
                    TopSignalIconCssClass = p.TopSignalIconCssClass
                }).ToList();

                if (personList.Count == 1)
                {
                    Response.Redirect(string.Format("~/Person/{0}", personList[0].Id), false);
                    Context.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    if (type.ToLower() == "name")
                    {
                        var similarNames = personService.GetSimilarNames(term,
                                                                         personList.Select(p => p.Id).ToList(), true);
                        if (similarNames.Any())
                        {
                            var hyperlinks = new List <string>();
                            foreach (string name in similarNames.Distinct())
                            {
                                var pageRef = CurrentPageReference;
                                pageRef.Parameters["SearchTerm"] = name;
                                hyperlinks.Add(string.Format("<a href='{0}'>{1}</a>", pageRef.BuildUrl(), name));
                            }
                            string altNames = string.Join(", ", hyperlinks);
                            nbNotice.Text    = string.Format("Other Possible Matches: {0}", altNames);
                            nbNotice.Visible = true;
                        }
                    }

                    _inactiveStatus = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE);
                    var personIds = personList.Select(a => a.Id).ToList();

                    if (envelopeNumberField != null && envelopeNumberField.Visible)
                    {
                        _envelopeNumbers = new AttributeValueService(rockContext).Queryable()
                                           .Where(a => a.AttributeId == personGivingEnvelopeAttribute.Id)
                                           .Where(a => personIds.Contains(a.EntityId.Value))
                                           .Select(a => new
                        {
                            PersonId = a.EntityId.Value,
                            Value    = a.Value
                        }).ToList().ToDictionary(k => k.PersonId, v => v.Value);
                    }

                    gPeople.EntityTypeId = EntityTypeCache.GetId <Person>();

                    gPeople.DataSource = personList;
                    gPeople.DataBind();
                }
            }
        }
コード例 #3
0
ファイル: PersonSearch.ascx.cs プロジェクト: shelsonjava/Rock
        private void BindGrid()
        {
            string type = PageParameter("SearchType");
            string term = PageParameter("SearchTerm");

            List <Person> personList = null;

            if (!String.IsNullOrWhiteSpace(type) && !String.IsNullOrWhiteSpace(term))
            {
                using (var uow = new Rock.Data.UnitOfWorkScope())
                {
                    IQueryable <Person> people = null;

                    var personService = new PersonService();

                    switch (type.ToLower())
                    {
                    case ("name"):

                        people = personService.GetByFullName(term, true);

                        break;

                    case ("phone"):

                        var phoneService = new PhoneNumberService();
                        var personIds    = phoneService.GetPersonIdsByNumber(term);

                        people = personService.Queryable().Where(p => personIds.Contains(p.Id));

                        break;

                    case ("address"):

                        var groupMemberService = new GroupMemberService();

                        var personIds2 = groupMemberService.GetPersonIdsByHomeAddress(term);
                        people = personService.Queryable().Where(p => personIds2.Contains(p.Id));

                        break;

                    case ("email"):

                        people = personService.Queryable().Where(p => p.Email.Contains(term));

                        break;
                    }

                    SortProperty sortProperty = gPeople.SortProperty;
                    if (sortProperty != null)
                    {
                        people = people.Sort(sortProperty);
                    }
                    else
                    {
                        people = people.OrderBy(p => p.LastName).ThenBy(p => p.FirstName);
                    }

                    personList = people.ToList();
                }
            }

            if (personList != null)
            {
                if (personList.Count == 1)
                {
                    Response.Redirect(string.Format("~/Person/{0}", personList[0].Id), false);
                    Context.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    gPeople.DataSource = personList;
                    gPeople.DataBind();
                }
            }
        }
コード例 #4
0
        private void BindGrid()
        {
            var birthDateCol = gPeople.ColumnsOfType <DateField>().First(c => c.DataField == "BirthDate");

            birthDateCol.Visible = GetAttributeValue("ShowBirthdate").AsBoolean();

            string type = PageParameter("SearchType");
            string term = PageParameter("SearchTerm");

            if (!string.IsNullOrWhiteSpace(type) && !string.IsNullOrWhiteSpace(term))
            {
                term = term.Trim();
                type = type.Trim();
                var rockContext = new RockContext();

                var personService          = new PersonService(rockContext);
                IQueryable <Person> people = null;

                switch (type.ToLower())
                {
                case ("name"):
                {
                    bool allowFirstNameOnly = false;
                    if (!bool.TryParse(PageParameter("allowFirstNameOnly"), out allowFirstNameOnly))
                    {
                        allowFirstNameOnly = false;
                    }
                    people = personService.GetByFullName(term, allowFirstNameOnly, true);
                    break;
                }

                case ("phone"):
                {
                    var phoneService = new PhoneNumberService(rockContext);
                    var personIds    = phoneService.GetPersonIdsByNumber(term);
                    people = personService.Queryable().Where(p => personIds.Contains(p.Id));
                    break;
                }

                case ("address"):
                {
                    var groupMemberService = new GroupMemberService(rockContext);
                    var personIds2         = groupMemberService.GetPersonIdsByHomeAddress(term);
                    people = personService.Queryable().Where(p => personIds2.Contains(p.Id));
                    break;
                }

                case ("email"):
                {
                    people = personService.Queryable().Where(p => p.Email.Contains(term));
                    break;
                }
                }

                var personIdList = people.Select(p => p.Id).ToList();

                people = personService.Queryable(true).Where(p => personIdList.Contains(p.Id));

                SortProperty sortProperty = gPeople.SortProperty;
                if (sortProperty != null)
                {
                    people = people.Sort(sortProperty);
                }
                else
                {
                    people = people.OrderBy(p => p.LastName).ThenBy(p => p.FirstName);
                }

                Guid familyGuid          = new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY);
                Guid homeAddressTypeGuid = new Guid(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME);

                var personList = people.Select(p => new PersonSearchResult
                {
                    Id         = p.Id,
                    FirstName  = p.FirstName,
                    NickName   = p.NickName,
                    LastName   = p.LastName,
                    BirthDate  = p.BirthDate,
                    BirthYear  = p.BirthYear,
                    BirthMonth = p.BirthMonth,
                    BirthDay   = p.BirthDay,
                    ConnectionStatusValueId = p.ConnectionStatusValueId,
                    RecordStatusValueId     = p.RecordStatusValueId,
                    RecordTypeValueId       = p.RecordTypeValueId,
                    SuffixValueId           = p.SuffixValueId,
                    IsDeceased = p.IsDeceased,
                    Email      = p.Email,
                    Gender     = p.Gender,
                    PhotoId    = p.PhotoId,
                    CampusIds  = p.Members
                                 .Where(m =>
                                        m.Group.GroupType.Guid.Equals(familyGuid) &&
                                        m.Group.CampusId.HasValue)
                                 .Select(m => m.Group.CampusId.Value)
                                 .ToList(),
                    HomeAddresses = p.Members
                                    .Where(m => m.Group.GroupType.Guid == familyGuid)
                                    .SelectMany(m => m.Group.GroupLocations)
                                    .Where(gl => gl.GroupLocationTypeValue.Guid.Equals(homeAddressTypeGuid))
                                    .Select(gl => gl.Location)
                }).ToList();

                if (personList.Count == 1)
                {
                    Response.Redirect(string.Format("~/Person/{0}", personList[0].Id), false);
                    Context.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    if (type.ToLower() == "name")
                    {
                        var similarNames = personService.GetSimilarNames(term,
                                                                         personList.Select(p => p.Id).ToList(), true);
                        if (similarNames.Any())
                        {
                            var hyperlinks = new List <string>();
                            foreach (string name in similarNames.Distinct())
                            {
                                var pageRef = CurrentPageReference;
                                pageRef.Parameters["SearchTerm"] = name;
                                hyperlinks.Add(string.Format("<a href='{0}'>{1}</a>", pageRef.BuildUrl(), name));
                            }
                            string altNames = string.Join(", ", hyperlinks);
                            nbNotice.Text    = string.Format("Other Possible Matches: {0}", altNames);
                            nbNotice.Visible = true;
                        }
                    }

                    _inactiveStatus      = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE);
                    gPeople.EntityTypeId = EntityTypeCache.GetId <Person>();

                    gPeople.DataSource = personList;
                    gPeople.DataBind();
                }
            }
        }
コード例 #5
0
        private void BindGrid()
        {
            string type = PageParameter("SearchType");
            string term = PageParameter("SearchTerm");

            if (string.IsNullOrWhiteSpace(type) ||
                string.IsNullOrWhiteSpace(term))
            {
                return;
            }

            var rockContext = new RockContext();

            var personService          = new PersonService(rockContext);
            IQueryable <Person> people = null;

            // Try to get a reference to the component that implements this search by matching the Path of the Result URL to the current Page URL.
            // Any search component that implements the IEntitySearchComponent<Person> interface can use this block to display its results.
            IEntitySearchComponent <Person> searchProvider = null;

            var searchComponent = GetSearchComponentForResultUrl(this.Request.Path);

            searchProvider = searchComponent as IEntitySearchComponent <Person>;

            if (searchProvider != null)
            {
                // Ask the search component to provide the query for the search results.
                people = searchProvider.GetResultsQuery(term);
            }
            else
            {
                // Process hard-coded search components that do not implement the IEntitySearchComponent<Person> interface.
                // TODO: Reimplement these search components to implement IEntitySearchComponent<Person>.
                switch (type.ToLower())
                {
                case ("name"):
                {
                    bool allowFirstNameOnly = false;
                    if (!bool.TryParse(PageParameter("allowFirstNameOnly"), out allowFirstNameOnly))
                    {
                        allowFirstNameOnly = false;
                    }
                    people = personService.GetByFullName(term, allowFirstNameOnly, true);
                    break;
                }

                case ("phone"):
                {
                    var phoneService = new PhoneNumberService(rockContext);
                    var personIds    = phoneService.GetPersonIdsByNumber(term);
                    people = personService.Queryable().Where(p => personIds.Contains(p.Id));
                    break;
                }

                case ("address"):
                {
                    var groupMemberService = new GroupMemberService(rockContext);
                    var personIds2         = groupMemberService.GetPersonIdsByHomeAddress(term);
                    people = personService.Queryable().Where(p => personIds2.Contains(p.Id));
                    break;
                }

                case ("email"):
                {
                    people = personService.Queryable().Where(p => p.Email.Contains(term));
                    break;
                }
                }
            }

            // If no suitable query can be supplied for the search results, we are done.
            if (people == null)
            {
                return;
            }

            SortProperty sortProperty = gPeople.SortProperty;

            if (sortProperty != null)
            {
                people = people.Sort(sortProperty);
            }
            else
            {
                people = people.OrderBy(p => p.LastName).ThenBy(p => p.FirstName);
            }

            Guid familyGuid          = new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY);
            Guid homeAddressTypeGuid = new Guid(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME);

            var personList = people.Select(p => new PersonSearchResult
            {
                Id         = p.Id,
                FirstName  = p.FirstName,
                NickName   = p.NickName,
                LastName   = p.LastName,
                BirthDate  = p.BirthDate,
                BirthYear  = p.BirthYear,
                BirthMonth = p.BirthMonth,
                BirthDay   = p.BirthDay,
                ConnectionStatusValueId = p.ConnectionStatusValueId,
                RecordStatusValueId     = p.RecordStatusValueId,
                RecordTypeValueId       = p.RecordTypeValueId,
                SuffixValueId           = p.SuffixValueId,
                IsDeceased = p.IsDeceased,
                Email      = p.Email,
                Gender     = p.Gender,
                PhotoId    = p.PhotoId,
                CampusIds  = p.Members
                             .Where(m =>
                                    m.Group.GroupType.Guid.Equals(familyGuid) &&
                                    m.Group.CampusId.HasValue)
                             .Select(m => m.Group.CampusId.Value)
                             .ToList(),
                HomeAddresses = p.Members
                                .Where(m => m.Group.GroupType.Guid == familyGuid)
                                .SelectMany(m => m.Group.GroupLocations)
                                .Where(gl => gl.GroupLocationTypeValue.Guid.Equals(homeAddressTypeGuid))
                                .Select(gl => gl.Location)
            }).ToList();

            if (personList.Count == 1)
            {
                // If the search returns a single result, display the Person Page immediately.
                Response.Redirect(string.Format("~/Person/{0}", personList[0].Id), false);
                Context.ApplicationInstance.CompleteRequest();
            }
            else
            {
                // If the search returns multiple results or nothing, include suggested related search terms if they are available from the search provider.
                List <string> similarNames;

                if (searchProvider != null)
                {
                    similarNames = searchProvider.GetSearchSuggestions(term, personList.Select(p => p.Id).ToList());
                }
                else if (type.ToLower() == "name")
                {
                    // Process hard-coded search components that do not implement the IEntitySearchComponent<Person> interface.
                    similarNames = personService.GetSimiliarNames(term,
                                                                  personList.Select(p => p.Id).ToList(), true);
                }
                else
                {
                    similarNames = new List <string>();
                }

                if (similarNames.Any())
                {
                    var hyperlinks = new List <string>();
                    foreach (string name in similarNames.Distinct())
                    {
                        var pageRef = CurrentPageReference;
                        pageRef.Parameters["SearchTerm"] = name;
                        hyperlinks.Add(string.Format("<a href='{0}'>{1}</a>", pageRef.BuildUrl(), name));
                    }
                    string altNames = string.Join(", ", hyperlinks);
                    nbNotice.Text    = string.Format("Other Possible Matches: {0}", altNames);
                    nbNotice.Visible = true;
                }

                _inactiveStatus = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE);

                gPeople.DataSource = personList;
                gPeople.DataBind();
            }
        }
コード例 #6
0
        private void BindGrid()
        {
            string type = PageParameter("SearchType");
            string term = PageParameter("SearchTerm");

            if (!String.IsNullOrWhiteSpace(type) && !String.IsNullOrWhiteSpace(term))
            {
                using (var rockContext = new RockContext())
                {
                    var personService          = new PersonService(rockContext);
                    IQueryable <Person> people = null;

                    switch (type.ToLower())
                    {
                    case ("name"):
                    {
                        bool allowFirstNameOnly = false;
                        if (!bool.TryParse(PageParameter("allowFirstNameOnly"), out allowFirstNameOnly))
                        {
                            allowFirstNameOnly = false;
                        }
                        people = personService.GetByFullName(term, allowFirstNameOnly, true);
                        break;
                    }

                    case ("phone"):
                    {
                        var phoneService = new PhoneNumberService(rockContext);
                        var personIds    = phoneService.GetPersonIdsByNumber(term);
                        people = personService.Queryable().Where(p => personIds.Contains(p.Id));
                        break;
                    }

                    case ("address"):
                    {
                        var groupMemberService = new GroupMemberService(rockContext);
                        var personIds2         = groupMemberService.GetPersonIdsByHomeAddress(term);
                        people = personService.Queryable().Where(p => personIds2.Contains(p.Id));
                        break;
                    }

                    case ("email"):
                    {
                        people = personService.Queryable().Where(p => p.Email.Contains(term));
                        break;
                    }
                    }

                    SortProperty sortProperty = gPeople.SortProperty;
                    if (sortProperty != null)
                    {
                        people = people.Sort(sortProperty);
                    }
                    else
                    {
                        people = people.OrderBy(p => p.LastName).ThenBy(p => p.FirstName);
                    }

                    var personList = people.ToList();

                    if (personList.Count == 1)
                    {
                        Response.Redirect(string.Format("~/Person/{0}", personList[0].Id), false);
                        Context.ApplicationInstance.CompleteRequest();
                    }
                    else
                    {
                        if (type.ToLower() == "name")
                        {
                            var similiarNames = personService.GetSimiliarNames(term,
                                                                               personList.Select(p => p.Id).ToList(), true);
                            if (similiarNames.Any())
                            {
                                var hyperlinks = new List <string>();
                                foreach (string name in similiarNames.Distinct())
                                {
                                    var pageRef = CurrentPageReference;
                                    pageRef.Parameters["SearchTerm"] = name;
                                    hyperlinks.Add(string.Format("<a href='{0}'>{1}</a>", pageRef.BuildUrl(), name));
                                }
                                string altNames = string.Join(", ", hyperlinks);
                                nbNotice.Text    = string.Format("Other Possible Matches: {0}", altNames);
                                nbNotice.Visible = true;
                            }
                        }

                        _inactiveStatus = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE);

                        gPeople.DataSource = personList;
                        gPeople.DataBind();
                    }
                }
            }
        }