/// <summary> /// Returns a person's consolidator if they have one /// </summary> /// <param name="followUp"></param> /// <param name="rockContext"></param> /// <returns></returns> public static Person GetConsolidator(this Person followUp, RockContext rockContext) { var groupMemberService = new GroupMemberService(rockContext); var consolidatedBy = new GroupTypeRoleService(rockContext).Get(SystemGuid.GroupTypeRole.CONSOLIDATED_BY.AsGuid()); return(groupMemberService.GetKnownRelationship(followUp.Id, consolidatedBy.Id).FirstOrDefault()?.Person); }
public static bool HasConsolidator(this Person person) { var rockContext = new RockContext(); var groupMemberService = new GroupMemberService(rockContext); var consolidatedBy = new GroupTypeRoleService(rockContext).Get(SystemGuid.GroupTypeRole.CONSOLIDATED_BY.AsGuid()); return(groupMemberService.GetKnownRelationship(person.Id, consolidatedBy.Id) != null); }
public IQueryable <GroupMember> GetKnownRelationship(int personId, int relationshipRoleId) { SetProxyCreation(true); var rockContext = this.Service.Context as RockContext; var groupMemberService = new GroupMemberService(rockContext); var groupMembers = groupMemberService.GetKnownRelationship(personId, relationshipRoleId); return(groupMembers); }
/// <summary> /// Gets a persons followups /// </summary> /// <param name="consolidator"></param> /// <param name="rockContext"></param> /// <returns></returns> public static IQueryable <Person> GetFollowUps(this Person consolidator, RockContext rockContext) { var groupMemberService = new GroupMemberService(rockContext); var consolidatedBy = new GroupTypeRoleService(rockContext).Get(SystemGuid.GroupTypeRole.CONSOLIDATOR.AsGuid()); if (consolidatedBy != null) { return(groupMemberService.GetKnownRelationship(consolidator.Id, consolidatedBy.Id).Select(gm => gm.Person)); } return(null); }
/// <summary> /// Gets the follow ups for the line below a leader or coordinator /// </summary> /// <param name="personService"></param> /// <param name="currentPerson"></param> /// <param name="rockContext"></param> /// <param name="showAllIfStaff">If a staff member, should they see all people</param> /// <returns></returns> public static IQueryable <Person> GetPeopleInLineFollowUps(PersonService personService, Person currentPerson, RockContext rockContext, bool showAllIfStaff) { if (currentPerson == null) { return(new List <Person>().AsQueryable()); } if (showAllIfStaff && CheckIsStaff(currentPerson, rockContext)) { return(personService.Queryable()); } var cellGroupsIdsInLine = GetCellGroupIdsInLine(currentPerson, rockContext); var recordStatusIsActiveGuid = Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE.AsGuid(); var groupMemberService = new GroupMemberService(rockContext); // Get person Ids from line var linePersonIds = groupMemberService.Queryable() .Where(gm => cellGroupsIdsInLine.Contains(gm.GroupId) && gm.Person.RecordStatusValue.Guid == recordStatusIsActiveGuid) .Select(gm => gm.PersonId).ToList(); // Get people's follow ups int consolidatorGroupTypeRoleId = new GroupTypeRoleService(rockContext).Get(SystemGuid.GroupTypeRole.CONSOLIDATOR.AsGuid()).Id; var followUpIds = new List <int>(); foreach (int personId in linePersonIds) { followUpIds.AddRange(groupMemberService.GetKnownRelationship(personId, consolidatorGroupTypeRoleId).Where(gm => gm.Person.RecordStatusValue.Guid == recordStatusIsActiveGuid).Select(gm => gm.PersonId)); } //Remove people who are in a group as a coordinator or leader var cellGroupType = GroupTypeCache.Read(SystemGuid.GroupType.CELL_GROUP.AsGuid()); var consolidatorCoordinatorGuid = SystemGuid.GroupTypeRole.CONSOLIDATION_COORDINATOR.AsGuid(); var idsToRemove = groupMemberService.Queryable() .Where( gm => followUpIds.Any(fId => gm.PersonId == fId) && gm.Group.GroupTypeId == cellGroupType.Id && (gm.GroupRole.Guid == consolidatorCoordinatorGuid || gm.GroupRole.IsLeader)) .Select(gm => gm.PersonId) .ToList(); foreach (int idToRemove in idsToRemove) { followUpIds.Remove(idToRemove); } return(personService.GetByIds(followUpIds).Distinct()); }
/// <summary> /// Gets the line members *and* their follow ups of the line below a leader or coordinator /// </summary> /// <param name="personService"></param> /// <param name="currentPerson"></param> /// <param name="rockContext"></param> /// <param name="showAllIfStaff"></param> /// <returns></returns> public static IQueryable <Person> GetLineMembersAndFollowUps(PersonService personService, Person currentPerson, RockContext rockContext, bool showAllIfStaff) { if (currentPerson == null) { return(new List <Person>().AsQueryable()); } if (showAllIfStaff && CheckIsStaff(currentPerson, rockContext)) { return(personService.Queryable()); } var cellGroupsIdsInLine = GetCellGroupIdsInLine(currentPerson, rockContext); var recordStatusIsActiveGuid = Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE.AsGuid(); var groupMemberService = new GroupMemberService(rockContext); // Get person Ids from line var linePersonIds = groupMemberService.Queryable() .Where( gm => cellGroupsIdsInLine.Contains(gm.GroupId) && gm.Person.RecordStatusValue.Guid == recordStatusIsActiveGuid) .Select(gm => gm.PersonId).ToList(); // Get people's follow ups int consolidatorGroupTypeRoleId = new GroupTypeRoleService(rockContext).Get(SystemGuid.GroupTypeRole.CONSOLIDATOR.AsGuid()).Id; var lineAndFollowUpIds = new List <int>(); foreach (int personId in linePersonIds) { lineAndFollowUpIds.AddRange( groupMemberService.GetKnownRelationship(personId, consolidatorGroupTypeRoleId) .Where(gm => gm.Person.RecordStatusValue.Guid == recordStatusIsActiveGuid) .Select(gm => gm.PersonId)); } lineAndFollowUpIds.AddRange(linePersonIds); return(personService.GetByIds(lineAndFollowUpIds).Distinct()); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var rockContext = new RockContext(); var groupMemberService = new GroupMemberService(rockContext); var searchPerson = CurrentPerson; // If the person is a group leader, get their coordinator so they can view as them var consolidatorCoordinatorGuid = org.kcionline.bricksandmortarstudio.SystemGuid.GroupTypeRole.CONSOLIDATION_COORDINATOR.AsGuid(); var cellGroupType = GroupTypeCache.Read(org.kcionline.bricksandmortarstudio.SystemGuid.GroupType.CELL_GROUP.AsGuid()); if ( groupMemberService.Queryable() .Any(gm => gm.GroupRole.IsLeader && gm.Group.GroupTypeId == cellGroupType.Id)) { var baseGroup = // ReSharper disable once PossibleNullReferenceException groupMemberService.Queryable() .FirstOrDefault( gm => gm.GroupRole.IsLeader && gm.Group.GroupTypeId == cellGroupType.Id) .Group; while (baseGroup != null) { var coordinator = baseGroup.Members.FirstOrDefault(gm => gm.GroupRole.Guid == consolidatorCoordinatorGuid); if (coordinator != null) { searchPerson = coordinator.Person; break; } baseGroup = baseGroup.ParentGroup; } } // filtering var connectionRequests = LineQuery.GetPeopleInLineFollowUpRequests(searchPerson); if (drpDates.LowerValue.HasValue) { connectionRequests = connectionRequests.Where(a => a.CreatedDateTime >= drpDates.LowerValue.Value); } if (drpDates.UpperValue.HasValue) { DateTime upperDate = drpDates.UpperValue.Value.Date.AddDays(1); connectionRequests = connectionRequests.Where(a => a.CreatedDateTime < upperDate); } if (!String.IsNullOrEmpty(ddlStatus.SelectedValue)) { connectionRequests = connectionRequests.Where(cr => cr.ConnectionStatus.Name == ddlStatus.SelectedValue); } if (ppConsolidator.SelectedValue.HasValue) { connectionRequests = connectionRequests.Where( cr => cr.ConnectorPersonAlias.PersonId == ppConsolidator.SelectedValue.Value); } // end filtering var groupTypeRoleService = new GroupTypeRoleService(rockContext); var groupTypeRole = groupTypeRoleService.Get( org.kcionline.bricksandmortarstudio.SystemGuid.GroupTypeRole.CONSOLIDATED_BY.AsGuid()); var followUps = new List <FollowUp>(connectionRequests.Count()); foreach (var request in connectionRequests) { var firstOrDefault = groupMemberService.GetKnownRelationship(request.PersonAlias.PersonId, groupTypeRole.Id) .FirstOrDefault(); if (firstOrDefault != null) { var consolidator = firstOrDefault.Person; followUps.Add(new FollowUp(request, consolidator)); } } gList.DataSource = followUps; gList.DataBind(); }
public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages) { errorMessages = new List <string>(); var personAliasService = new PersonAliasService(rockContext); // get person Person person = null; var guidPersonAttribute = GetAttributeValue(action, "Person").AsGuidOrNull(); if (guidPersonAttribute.HasValue) { var attributePerson = AttributeCache.Read(guidPersonAttribute.Value, rockContext); if (attributePerson != null) { var attributePersonValue = action.GetWorklowAttributeValue(guidPersonAttribute.Value).AsGuidOrNull(); if (attributePersonValue.HasValue) { person = personAliasService.GetPerson(attributePersonValue.Value); if (person == null) { errorMessages.Add(string.Format("Person could not be found for selected value ('{0}')!", guidPersonAttribute)); return(false); } } } } Person relatedPerson = null; var guidRelatedPersonAttribute = GetAttributeValue(action, "RelationshipTo").AsGuidOrNull(); if (guidRelatedPersonAttribute.HasValue) { var attributePerson = AttributeCache.Read(guidRelatedPersonAttribute.Value, rockContext); if (attributePerson != null) { var attributePersonValue = action.GetWorklowAttributeValue(guidRelatedPersonAttribute.Value).AsGuidOrNull(); if (attributePersonValue.HasValue) { relatedPerson = personAliasService.GetPerson(attributePersonValue.Value); if (relatedPerson == null) { errorMessages.Add(string.Format("Person could not be found for selected value ('{0}')!", guidPersonAttribute)); return(false); } } } } var groupTypeRoleService = new GroupTypeRoleService(rockContext); GroupTypeRole relationshipType = null; var relationshipRoleGuid = GetActionAttributeValue(action, "RelationshipType").AsGuidOrNull(); if (relationshipRoleGuid.HasValue) { relationshipType = groupTypeRoleService.Get(relationshipRoleGuid.Value); if (relationshipType == null) { errorMessages.Add(string.Format("GroupTypeRole (Relationship Type) could not be found for selected value ('{0}')!", relationshipRoleGuid)); return(false); } } var groupMemberService = new GroupMemberService(rockContext); // Check if relationship already exists if ( groupMemberService.GetKnownRelationship(person.Id, relationshipType.Id) .Any(gm => gm.Person.Id == relatedPerson.Id)) { errorMessages.Add(string.Format("Relationship of {0} already exists between {1} and {2}", relationshipType.Name, person.FullName, relatedPerson.FullName)); return(false); } groupMemberService.CreateKnownRelationship(person.Id, relatedPerson.Id, relationshipType.Id); // Create inverse relationship if it doesn't exist. if (relationshipType.Attributes.ContainsKey("InverseRelationship")) { var inverseRelationshipTypeGuid = relationshipType.GetAttributeValue("InverseRelationship").AsGuidOrNull(); if (inverseRelationshipTypeGuid.HasValue) { var inverseRelationshipType = groupTypeRoleService.Get(inverseRelationshipTypeGuid.Value); // Ensure relationship doesn't already exist if (!groupMemberService.GetKnownRelationship(relatedPerson.Id, inverseRelationshipType.Id) .Any(gm => gm.Person.Id == person.Id)) { groupMemberService.CreateKnownRelationship(relatedPerson.Id, person.Id, inverseRelationshipType.Id); } } } return(true); }