/// <summary> /// Determines whether [is inherited group type recursive] [the specified group type]. /// </summary> /// <param name="groupType">Type of the group.</param> /// <returns></returns> private static bool IsInheritedGroupTypeRecursive(GroupTypeCache groupType) { if (new GroupTypeService().Queryable().Any(a => a.InheritedGroupType.Guid == groupType.Guid)) { return(true); } foreach (var childGroupType in groupType.ChildGroupTypes) { if (IsInheritedGroupTypeRecursive(childGroupType)) { return(true); } } return(false); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages) { errorMessages = new List <string>(); var adultRoleGuid = SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid(); var maritalStatusMarried = DefinedValueCache.Read(SystemGuid.DefinedValue.PERSON_MARITAL_STATUS_MARRIED.AsGuid()); var familyGroupType = GroupTypeCache.Read(SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()); var adultRole = familyGroupType.Roles.Where(r => r.Guid == adultRoleGuid).FirstOrDefault(); var person = GetPersonAliasFromActionAttribute("Person", rockContext, action, errorMessages); if (person != null) { string spouseAttributeValue = GetAttributeValue(action, "SpouseAttribute"); Guid? spouseGuid = spouseAttributeValue.AsGuidOrNull(); if (spouseGuid.HasValue) { var spouseAttribute = AttributeCache.Read(spouseGuid.Value, rockContext); if (spouseAttribute != null) { var spouse = person.GetSpouse(rockContext); if (spouse != null) { action.Activity.Workflow.SetAttributeValue(spouseAttribute.Key, spouse.PrimaryAlias.Guid.ToString()); action.AddLogEntry(string.Format("Set spouse attribute '{0}' attribute to '{1}'.", spouseAttribute.Name, spouse.FullName)); return(true); } else { action.AddLogEntry(string.Format("No spouse found for {0}.", person.FullName)); } } } } else { errorMessages.Add("No person was provided."); return(false); } errorMessages.ForEach(m => action.AddLogEntry(m, true)); return(true); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); _groupType = GroupTypeCache.Read(GetAttributeValue("GroupType").AsGuid()); if (_groupType == null) { _groupType = GroupTypeCache.GetFamilyGroupType(); } _IsFamilyGroupType = _groupType.Guid.Equals(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()); rptrGroups.ItemDataBound += rptrGroups_ItemDataBound; _allowEdit = IsUserAuthorized(Rock.Security.Authorization.EDIT); RegisterScripts(); }
/// <summary> /// Gets the selection. /// </summary> /// <param name="entityType"></param> /// <param name="controls">The controls.</param> /// <returns></returns> public override string GetSelection(Type entityType, Control[] controls) { var values = new List <string>(); if (controls.Length > 0) { Panel pnlGroupAttributeFilterControls = controls[0] as Panel; if (pnlGroupAttributeFilterControls.Controls.Count >= 1) { // note: since this datafilter creates additional controls outside of CreateChildControls(), we'll use our _controlsToRender instead of the controls parameter GroupTypePicker groupTypePicker = pnlGroupAttributeFilterControls.Controls[0] as GroupTypePicker; Guid groupTypeGuid = Guid.Empty; var groupType = GroupTypeCache.Read(groupTypePicker.SelectedGroupTypeId ?? 0); if (groupType != null) { if (pnlGroupAttributeFilterControls.Controls.Count == 1) { groupTypePicker_SelectedIndexChanged(groupTypePicker, new EventArgs()); } if (pnlGroupAttributeFilterControls.Controls.Count > 1) { DropDownList ddlProperty = pnlGroupAttributeFilterControls.Controls[1] as DropDownList; var entityFields = GetGroupAttributes(groupType.Id); var entityField = entityFields.FirstOrDefault(f => f.Name == ddlProperty.SelectedValue); if (entityField != null) { var panelControls = new List <Control>(); panelControls.AddRange(pnlGroupAttributeFilterControls.Controls.OfType <Control>()); var control = panelControls.FirstOrDefault(c => c.ID.EndsWith(entityField.Name)); if (control != null) { values.Add(groupType.Guid.ToString()); values.Add(ddlProperty.SelectedValue); entityField.FieldType.Field.GetFilterValues(control, entityField.FieldConfig).ForEach(v => values.Add(v)); } } } } } } return(values.ToJson()); }
/// <summary> /// Applies the block settings. /// </summary> private void ApplyBlockSettings() { _blockSettingsGroupTypeIds = this.GetAttributeValue(AttributeKey.GroupTypes).SplitDelimitedValues().AsGuidList().Select(a => GroupTypeCache.Get(a)).Where(a => a != null).Select(a => a.Id).ToList(); IEnumerable <GroupTypeCache> groupTypes = GroupTypeCache.All(); if (_blockSettingsGroupTypeIds.Any()) { groupTypes = groupTypes.Where(a => _blockSettingsGroupTypeIds.Contains(a.Id)); } else { groupTypes = groupTypes.Where(a => a.EnableGroupHistory == true); } gtGroupTypesFilter.SetGroupTypes(groupTypes); }
/// <summary> /// Returns the field's current value(s) /// </summary> /// <param name="parentControl">The parent control.</param> /// <param name="value">Information about the value</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param> /// <returns></returns> public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed) { string formattedValue = string.Empty; Guid guid = Guid.Empty; if (Guid.TryParse(value, out guid)) { var groupType = GroupTypeCache.Read(guid); if (groupType != null) { formattedValue = groupType.Name; } } return(base.FormatValue(parentControl, formattedValue, null, condensed)); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { if (!IsPostBack) { GroupService groupService = new GroupService(new RockContext()); var groupTypeGuid = GetAttributeValue("Check-inGroupType").AsGuidOrNull(); if (groupTypeGuid.HasValue) { int groupTypeId = GroupTypeCache.Get(groupTypeGuid.Value).Id; var groups = groupService.Queryable().Where(g => g.GroupTypeId == groupTypeId).ToList().Select(g => new ListItem(g.Name, g.Id.ToString())).ToList(); groups.Insert(0, new ListItem(String.Empty, String.Empty)); rddlCheckinGroup.DataSource = groups; rddlCheckinGroup.DataBind(); } } }
/// <summary> /// Creates a Linq Expression that can be applied to an IQueryable to filter the result set. /// </summary> /// <param name="entityType">The type of entity in the result set.</param> /// <param name="serviceInstance">A service instance that can be queried to obtain the result set.</param> /// <param name="parameterExpression">The input parameter that will be injected into the filter expression.</param> /// <param name="selection">A formatted string representing the filter settings.</param> /// <returns> /// A Linq Expression that can be used to filter an IQueryable. /// </returns> /// <exception cref="System.Exception">Filter issue(s): + errorMessages.AsDelimited( ; )</exception> public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection) { var settings = new FilterSettings(selection); var context = (RockContext)serviceInstance.Context; // Get the Location Data View that defines the set of candidates from which proximate Locations can be selected. var dataView = DataComponentSettingsHelper.GetDataViewForFilterComponent(settings.DataViewGuid, context); // Evaluate the Data View that defines the candidate Locations. var locationService = new LocationService(context); var locationQuery = locationService.Queryable(); if (dataView != null) { locationQuery = DataComponentSettingsHelper.FilterByDataView(locationQuery, dataView, locationService); } // Get all the Family Groups that have a Location matching one of the candidate Locations. int familyGroupTypeId = GroupTypeCache.Get(SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()).Id; var groupLocationsQuery = new GroupLocationService(context).Queryable() .Where(gl => gl.Group.GroupTypeId == familyGroupTypeId && locationQuery.Any(l => l.Id == gl.LocationId)); // If a Location Type is specified, apply the filter condition. if (settings.LocationTypeGuid.HasValue) { int groupLocationTypeId = DefinedValueCache.Get(settings.LocationTypeGuid.Value).Id; groupLocationsQuery = groupLocationsQuery.Where(x => x.GroupLocationTypeValue.Id == groupLocationTypeId); } // Get all of the Group Members of the qualifying Families. var groupMemberServiceQry = new GroupMemberService(context).Queryable() .Where(gm => groupLocationsQuery.Any(gl => gl.GroupId == gm.GroupId)); // Get all of the People corresponding to the qualifying Group Members. var qry = new PersonService(context).Queryable() .Where(p => groupMemberServiceQry.Any(gm => gm.PersonId == p.Id)); // Retrieve the Filter Expression. var extractedFilterExpression = FilterExpressionExtractor.Extract <Model.Person>(qry, parameterExpression, "p"); return(extractedFilterExpression); }
/// <summary> /// Formats the selection. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override string FormatSelection(Type entityType, string selection) { string result = "Placement Group Type"; var selectionConfig = SelectionConfig.Parse(selection); if (selectionConfig != null && selectionConfig.PlacementGroupTypeGuid.HasValue) { var groupType = GroupTypeCache.Get(selectionConfig.PlacementGroupTypeGuid.Value); if (groupType != null) { result = string.Format("Placement Group type: {0}", groupType.Name); } } return(result); }
/// <summary> /// Determines whether the specified action is authorized. /// </summary> /// <param name="action">The action.</param> /// <param name="person">The person.</param> /// <returns> /// <c>true</c> if the specified action is authorized; otherwise, <c>false</c>. /// </returns> public override bool IsAuthorized(string action, Person person) { // Check to see if user is authorized using normal authorization rules bool authorized = base.IsAuthorized(action, person); // If the user is not authorized for group through normal security roles, and this is a logged // in user trying to view or edit, check to see if they should be allowed based on their role // in the group. if (!authorized && person != null && (action == Authorization.VIEW || action == Authorization.MANAGE_MEMBERS || action == Authorization.EDIT)) { // Get the cached group type var groupType = GroupTypeCache.Read(this.GroupTypeId); if (groupType != null) { // For each occurrence of this person in this group, check to see if their role is valid // for the group type and if the role grants them authorization using (var rockContext = new RockContext()) { foreach (int roleId in new GroupMemberService(rockContext) .Queryable().AsNoTracking() .Where(m => m.PersonId == person.Id && m.GroupId == this.Id && m.GroupMemberStatus == GroupMemberStatus.Active) .Select(m => m.GroupRoleId)) { var role = groupType.Roles.FirstOrDefault(r => r.Id == roleId); if (role != null) { if (action == Authorization.VIEW && role.CanView) { return(true); } if ((action == Authorization.MANAGE_MEMBERS || action == Authorization.EDIT) && role.CanEdit) { return(true); } } } } } } return(authorized); }
/// <summary> /// Formats the selection. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override string FormatSelection(Type entityType, string selection) { string result = "Group Type"; string[] selectionValues = selection.Split('|'); if (selectionValues.Length >= 1) { var groupType = GroupTypeCache.Get(selectionValues[0].AsGuid()); if (groupType != null) { result = string.Format("Group type: {0}", groupType.Name); } } return(result); }
/// <summary> /// Rs the filter_ display filter value. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> protected void rFilter_DisplayFilterValue(object sender, GridFilter.DisplayFilterValueArgs e) { switch (e.Key) { case "Group Type": int id = e.Value.AsInteger() ?? 0; var groupType = GroupTypeCache.Read(id); if (groupType != null) { e.Value = groupType.Name; } break; } }
/// <summary> /// Binds the checkin types. /// </summary> /// <param name="selectedValue">The selected value.</param> private void BindCheckinTypes(int?checkinTypeId) { ddlCheckinType.Items.Clear(); if (ddlKiosk.SelectedValue != None.IdValue) { using (var rockContext = new RockContext()) { var groupTypeService = new GroupTypeService(rockContext); var checkinTemplateTypeId = DefinedValueCache.GetId(Rock.SystemGuid.DefinedValue.GROUPTYPE_PURPOSE_CHECKIN_TEMPLATE.AsGuid()); ddlCheckinType.DataSource = groupTypeService .Queryable().AsNoTracking() .Where(t => t.GroupTypePurposeValueId.HasValue && t.GroupTypePurposeValueId == checkinTemplateTypeId) .OrderBy(t => t.Name) .Select(t => new { t.Name, t.Id }) .ToList(); ddlCheckinType.DataBind(); } if (checkinTypeId.HasValue) { ddlCheckinType.SetValue(checkinTypeId); } else { if (LocalDeviceConfig.CurrentCheckinTypeId.HasValue) { ddlCheckinType.SetValue(LocalDeviceConfig.CurrentCheckinTypeId); } else { var groupType = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_WEEKLY_SERVICE_CHECKIN_AREA.AsGuid()); if (groupType != null) { ddlCheckinType.SetValue(groupType.Id); } } } } }
/// <summary> /// Refreshes the start button content. /// </summary> private void RefreshStartButton() { string checkinButtonText = GetAttributeValue(AttributeKey.CheckinButtonText).IfEmpty("Start"); var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, null, new Rock.Lava.CommonMergeFieldsOptions { GetLegacyGlobalMergeFields = false }); mergeFields.Add(AttributeKey.CheckinButtonText, checkinButtonText); mergeFields.Add("Kiosk", CurrentCheckInState.Kiosk); mergeFields.Add("RegistrationModeEnabled", CurrentCheckInState.Kiosk.RegistrationModeEnabled); if (LocalDeviceConfig.CurrentGroupTypeIds != null) { var checkInAreas = LocalDeviceConfig.CurrentGroupTypeIds.Select(a => GroupTypeCache.Get(a)); mergeFields.Add("CheckinAreas", checkInAreas); } // // Include the camera button if it is enabled and the device supports it. // var blockCameraMode = GetAttributeValue(AttributeKey.CameraBarcodeConfiguration).ConvertToEnum <CameraBarcodeConfiguration>(CameraBarcodeConfiguration.Available); var deviceHasCamera = CurrentCheckInState.Kiosk.Device.HasCamera; var cameraMode = CurrentCheckInState.Kiosk.Device.CameraBarcodeConfigurationType ?? blockCameraMode; cameraMode = deviceHasCamera ? cameraMode : CameraBarcodeConfiguration.Off; hfCameraMode.Value = cameraMode.ToString(); if (pnlActive.Visible && cameraMode != CameraBarcodeConfiguration.Off) { var scanButtonText = GetAttributeValue(AttributeKey.ScanButtonText); if (scanButtonText.IsNullOrWhiteSpace()) { scanButtonText = _defaultScanButtonText; } mergeFields.Add("BarcodeScanEnabled", true); mergeFields.Add("BarcodeScanButtonText", scanButtonText); } else { mergeFields.Add("BarcodeScanEnabled", false); } lStartButtonHtml.Text = CurrentCheckInState.CheckInType.StartLavaTemplate.ResolveMergeFields(mergeFields); }
/// <summary> /// Binds the families. /// </summary> private void BindFamilies() { if (Person != null && Person.Id > 0) { Guid familyGroupGuid = new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY); using (_bindFamiliesRockContext = new RockContext()) { var memberService = new GroupMemberService(_bindFamiliesRockContext); var families = memberService.Queryable(true) .Where(m => m.PersonId == Person.Id && m.Group.GroupType.Guid == familyGroupGuid) .Select(m => m.Group) .ToList(); if (!families.Any()) { // ensure that the person is in a family var familyGroupType = GroupTypeCache.GetFamilyGroupType(); if (familyGroupType != null) { var groupMember = new GroupMember(); groupMember.PersonId = Person.Id; groupMember.GroupRoleId = familyGroupType.DefaultGroupRoleId.Value; var family = new Group(); family.Name = Person.LastName; family.GroupTypeId = familyGroupType.Id; family.Members.Add(groupMember); // use the _bindFamiliesRockContext that is created/disposed in BindFamilies() var groupService = new GroupService(_bindFamiliesRockContext); groupService.Add(family); _bindFamiliesRockContext.SaveChanges(); families.Add(groupService.Get(family.Id)); } } rptrFamilies.DataSource = families; rptrFamilies.DataBind(); } } }
/// <summary> /// Builds the expression. /// </summary> /// <param name="serviceInstance">The service instance.</param> /// <param name="idQuery">The id query.</param> /// <param name="parameterExpression">The parameter expression.</param> /// <returns></returns> private Expression BuildExpression(IService serviceInstance, IQueryable <int> idQuery, ParameterExpression parameterExpression) { var rockContext = ( RockContext )serviceInstance.Context; var adultGuid = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid(); var adultGroupRoleId = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY).Roles.FirstOrDefault(r => r.Guid == adultGuid).Id; var marriedStatusId = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_MARITAL_STATUS_MARRIED).Id; var familyGroupTypeId = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY).Id; // // This duplicates the functionality of the ufnCrm_GetSpousePersonIdFromPersonId function // on a broader level. We are given a list of Person IDs so we need to handle more than one // at a time. That is what the GroupBy method does at the end. We group by the original person // Id and then order within that group to find the "first" spouse. // var sQuery = new GroupService(rockContext).Queryable() .Join(rockContext.GroupMembers, f => f.Id, fm1 => fm1.GroupId, (f, fm1) => new { f, fm1 }) .Join(rockContext.People, x => x.fm1.PersonId, p1 => p1.Id, (x, p1) => new { x.f, x.fm1, p1 }) .Join(rockContext.GroupMembers, x => x.f.Id, fm2 => fm2.GroupId, (x, fm2) => new { x.f, x.fm1, x.p1, fm2 }) .Join(rockContext.People, x => x.fm2.PersonId, p2 => p2.Id, (x, p2) => new { x.f, x.fm1, x.p1, x.fm2, p2 }) .Where(x => x.f.GroupTypeId == familyGroupTypeId && idQuery.Contains(x.p1.Id) && x.fm1.GroupRoleId == adultGroupRoleId && x.fm2.GroupRoleId == adultGroupRoleId && x.p1.MaritalStatusValueId == marriedStatusId && x.p2.MaritalStatusValueId == marriedStatusId && x.p1.Id != x.p2.Id && (x.p1.Gender != x.p2.Gender || x.p1.Gender == Gender.Unknown || x.p2.Gender == Gender.Unknown)) .Select(x => new { p1 = x.p1, p2 = x.p2, dif = Math.Abs(DbFunctions.DiffDays(x.p1.BirthDate ?? new DateTime(1, 1, 1), x.p2.BirthDate ?? new DateTime(1, 1, 1)).Value) }) .GroupBy(x => x.p1) .Select(x => x.OrderBy(y => y.dif).ThenBy(y => y.p2.Id).FirstOrDefault().p2.Id); // // Finaly build a query that gives us all people who are either the original person or // included in the spouse query. // var query = new PersonService(rockContext).Queryable() .Where(p => sQuery.Contains(p.Id) || idQuery.Contains(p.Id)); return(FilterExpressionExtractor.Extract <Rock.Model.Person>(query, parameterExpression, "p")); }
/// <summary> /// Loads by model. /// </summary> /// <param name="business">The business.</param> /// <returns></returns> public static BusinessIndex LoadByModel(Person business) { var businessIndex = new BusinessIndex(); businessIndex.SourceIndexModel = "Rock.Model.Person"; businessIndex.ModelConfiguration = "nofilters"; businessIndex.ModelOrder = 6; businessIndex.Id = business.Id; businessIndex.Name = business.LastName; businessIndex.DocumentName = business.LastName; // do not currently index business attributes since they are shared with people //AddIndexableAttributes( businessIndex, person ); var knownRelationshipGroupType = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS.AsGuid()); var knownRelationshipOwnerRoleId = knownRelationshipGroupType.Roles.Where(r => r.Guid == SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid()).FirstOrDefault().Id; var knownRelationshipBusinessContactId = knownRelationshipGroupType.Roles.Where(r => r.Guid == SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_BUSINESS_CONTACT.AsGuid()).FirstOrDefault().Id; RockContext rockContext = new RockContext(); var contactGroup = new GroupMemberService(rockContext).Queryable() .Where(m => m.Group.GroupTypeId == knownRelationshipGroupType.Id && m.GroupRoleId == knownRelationshipOwnerRoleId && m.PersonId == business.Id) .FirstOrDefault(); if (contactGroup != null) { var contacts = new GroupMemberService(rockContext).Queryable().AsNoTracking() .Where(m => m.Group.GroupTypeId == knownRelationshipGroupType.Id && m.GroupId == contactGroup.GroupId && m.GroupRoleId == knownRelationshipBusinessContactId) .Select(m => m.Person.NickName + " " + m.Person.LastName).ToList(); if (contacts != null) { businessIndex.Contacts = string.Join(", ", contacts); } } return(businessIndex); }
/// <summary> /// Builds the common fields. /// </summary> /// <param name="member">The group.</param> /// <param name="parameters">The parameters.</param> /// <returns>A string containing the XAML that represents the common Group fields.</returns> private string BuildCommonFields(GroupMember member, Dictionary <string, string> parameters) { var sb = new StringBuilder(); sb.AppendLine(MobileHelper.GetReadOnlyFieldXaml("Name", member.Person.FullName)); if (AllowRoleChange) { var items = GroupTypeCache.Get(member.Group.GroupTypeId) .Roles .Select(a => new KeyValuePair <string, string>(a.Id.ToString(), a.Name)); sb.AppendLine(MobileHelper.GetSingleFieldXaml(MobileHelper.GetDropDownFieldXaml("role", "Role", member.GroupRoleId.ToString(), true, items))); parameters.Add("role", "SelectedValue"); } else { sb.AppendLine(MobileHelper.GetReadOnlyFieldXaml("Role", member.GroupRole.Name)); } if (AllowMemberStatusChange) { var items = Enum.GetNames(typeof(GroupMemberStatus)) .Select(a => new KeyValuePair <string, string>(a, a)); sb.AppendLine(MobileHelper.GetSingleFieldXaml(MobileHelper.GetDropDownFieldXaml("memberstatus", "Member Status", member.GroupMemberStatus.ToString(), true, items))); parameters.Add("memberstatus", "SelectedValue"); } else { sb.AppendLine(MobileHelper.GetReadOnlyFieldXaml("Member Status", member.GroupMemberStatus.ToString())); } if (AllowNoteEdit) { sb.AppendLine(MobileHelper.GetSingleFieldXaml(MobileHelper.GetTextEditFieldXaml("note", "Note", member.Note, false, true))); parameters.Add("note", "Text"); } else { sb.AppendLine(MobileHelper.GetReadOnlyFieldXaml("Note", member.Note)); } return(sb.ToString()); }
/// <summary> /// Gets the expression. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="serviceInstance">The service instance.</param> /// <param name="parameterExpression">The parameter expression.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection) { string[] selectionValues = selection.Split('|'); if (selectionValues.Length >= 2) { GroupMemberService groupMemberService = new GroupMemberService((RockContext)serviceInstance.Context); int groupTypeId = 0; Guid groupTypeGuid = selectionValues[0].AsGuid(); var groupType = GroupTypeCache.Read(groupTypeGuid); if (groupType != null) { groupTypeId = groupType.Id; } var groupMemberServiceQry = groupMemberService.Queryable().Where(xx => xx.Group.GroupTypeId == groupTypeId && xx.Group.IsActive == true); var groupRoleGuids = selectionValues[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(n => n.AsGuid()).ToList(); if (groupRoleGuids.Count() > 0) { var groupRoleIds = new GroupTypeRoleService((RockContext)serviceInstance.Context).Queryable().Where(a => groupRoleGuids.Contains(a.Guid)).Select(a => a.Id).ToList(); groupMemberServiceQry = groupMemberServiceQry.Where(xx => groupRoleIds.Contains(xx.GroupRoleId)); } GroupMemberStatus?groupMemberStatus = null; if (selectionValues.Length >= 3) { groupMemberStatus = selectionValues[2].ConvertToEnumOrNull <GroupMemberStatus>(); } if (groupMemberStatus.HasValue) { groupMemberServiceQry = groupMemberServiceQry.Where(xx => xx.GroupMemberStatus == groupMemberStatus.Value); } var qry = new PersonService((RockContext)serviceInstance.Context).Queryable() .Where(p => groupMemberServiceQry.Any(xx => xx.PersonId == p.Id)); Expression extractedFilterExpression = FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p"); return(extractedFilterExpression); } return(null); }
/// <summary> /// Returns a collection of <see cref="Rock.Model.Person" /> entities containing the family members of the provided person. /// </summary> /// <param name="personId">The person identifier.</param> /// <param name="includeSelf">if set to <c>true</c> [include self].</param> /// <returns> /// An enumerable collection of <see cref="Rock.Model.Person" /> entities containing the family members of the provided person. /// </returns> public IQueryable <GroupMember> GetFamilyMembers(int personId, bool includeSelf = false) { int groupTypeFamilyId = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY).Id; var groupMemberService = new GroupMemberService((RockContext)this.Context); var familyGroupIds = groupMemberService.Queryable() .Where(m => m.PersonId == personId && m.Group.GroupTypeId == groupTypeFamilyId) .Select(m => m.GroupId) .Distinct(); return(groupMemberService.Queryable("Person,GroupRole") .Where(m => familyGroupIds.Contains(m.GroupId) && (includeSelf || m.PersonId != personId))); }
private static int GetListGroupId() { using (var rockContext = new RockContext()) { var groupGuid = Guid.NewGuid(); var group = new Group { GroupTypeId = GroupTypeCache.Get(SystemGuid.GroupType.GROUPTYPE_SMALL_GROUP).Id, Name = $"Name {groupGuid}", IsActive = true, }; var groupService = new GroupService(rockContext); groupService.Add(group); rockContext.SaveChanges(); return(group.Id); } }
/// <summary> /// Creates the family. /// </summary> /// <param name="FamilyName">Name of the family.</param> /// <returns></returns> protected Group CreateFamily(string FamilyName) { var familyGroup = new Group(); familyGroup.Name = FamilyName + " Family"; familyGroup.GroupTypeId = GroupTypeCache.GetFamilyGroupType().Id; familyGroup.IsSecurityRole = false; familyGroup.IsSystem = false; familyGroup.IsActive = true; Rock.Data.RockTransactionScope.WrapTransaction(() => { var gs = new GroupService(); gs.Add(familyGroup, CurrentPersonId); gs.Save(familyGroup, CurrentPersonId); }); return(familyGroup); }
/// <summary> /// Gets the selection. /// </summary> /// <param name="controls">The controls.</param> /// <returns></returns> public override string GetSelection(System.Web.UI.Control[] controls) { // Get the selected Group Type as a Guid. var groupTypeId = (controls[0] as GroupTypePicker).SelectedValueAsId().GetValueOrDefault(0); string value1 = string.Empty; if (groupTypeId > 0) { var groupType = GroupTypeCache.Read(groupTypeId); value1 = (groupType == null) ? string.Empty : groupType.Guid.ToString(); } // Get the selected Roles var value2 = (controls[1] as RockCheckBoxList).SelectedValues.AsDelimited(","); return(value1 + "|" + value2); }
/// <summary> /// Updates any Cache Objects that are associated with this entity /// </summary> /// <param name="entityState">State of the entity.</param> /// <param name="dbContext">The database context.</param> public void UpdateCache(System.Data.Entity.EntityState entityState, Rock.Data.DbContext dbContext) { // If the group changed, and it was a security group, flush the security for the group Guid?originalGroupTypeGuid = null; Guid groupTypeScheduleRole = Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid(); if (_originalGroupTypeId.HasValue && _originalGroupTypeId != this.GroupTypeId) { originalGroupTypeGuid = GroupTypeCache.Get(_originalGroupTypeId.Value, (RockContext)dbContext)?.Guid; } var groupTypeGuid = GroupTypeCache.Get(this.GroupTypeId, (RockContext)dbContext)?.Guid; if (this.IsSecurityRole || (_originalIsSecurityRole == true) || (groupTypeGuid == groupTypeScheduleRole) || (originalGroupTypeGuid == groupTypeScheduleRole)) { RoleCache.FlushItem(this.Id); } }
/// <summary> /// Gets the defined value value. /// </summary> /// <param name="groupType">The defined value.</param> /// <param name="groupTypeId">The defined value identifier.</param> /// <param name="blankValue">The blank value.</param> /// <returns></returns> public static string GetGroupTypeValue(GroupType groupType, int?groupTypeId, string blankValue) { if (groupType != null) { return(groupType.Name); } if (groupTypeId.HasValue) { var dv = GroupTypeCache.Read(groupTypeId.Value); if (dv != null) { return(dv.Name); } } return(blankValue); }
/// <summary> /// Creates the family. /// </summary> /// <param name="FamilyName">Name of the family.</param> /// <returns></returns> protected Group CreateFamily(string FamilyName) { var familyGroup = new Group(); familyGroup.Name = FamilyName + " Family"; familyGroup.GroupTypeId = GroupTypeCache.GetFamilyGroupType().Id; familyGroup.IsSecurityRole = false; familyGroup.IsSystem = false; familyGroup.IsActive = true; var rockContext = new RockContext(); var gs = new GroupService(rockContext); gs.Add(familyGroup); rockContext.SaveChanges(); return(familyGroup); }
/// <summary> /// Builds the expression. /// </summary> /// <param name="serviceInstance">The service instance.</param> /// <param name="idQuery">The id query.</param> /// <param name="parameterExpression">The parameter expression.</param> /// <returns></returns> private Expression BuildExpression(IService serviceInstance, IQueryable <int> idQuery, ParameterExpression parameterExpression) { var groupeType = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS.AsGuid()); int ownerRoleId = groupeType.Roles.Where(a => a.Guid == SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid()) .Select(a => a.Id) .FirstOrDefault(); int grandParentRoleId = groupeType.Roles.Where(a => a.Guid == SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_GRANDPARENT.AsGuid()) .Select(a => a.Id) .FirstOrDefault(); var qry = new PersonService((RockContext)serviceInstance.Context).Queryable() .Where(p => p.Members.Where(a => a.GroupRoleId == grandParentRoleId) .Any(a => a.Group.Members .Any(c => c.GroupRoleId == ownerRoleId && idQuery.Contains(c.PersonId)))); return(FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p")); }
/// <summary> /// Restores the view-state information from a previous user control request that was saved by the <see cref="M:System.Web.UI.UserControl.SaveViewState" /> method. /// </summary> /// <param name="savedState">An <see cref="T:System.Object" /> that represents the user control state to be restored.</param> protected override void LoadViewState(object savedState) { base.LoadViewState(savedState); if (CurrentCheckInState == null) { return; } EditFamilyState = (this.ViewState["EditFamilyState"] as string).FromJsonOrNull <FamilyRegistrationState>(); CreateDynamicFamilyControls(FamilyRegistrationState.FromGroup(new Group() { GroupTypeId = GroupTypeCache.GetFamilyGroupType().Id }), false); CreateDynamicPersonControls(FamilyRegistrationState.FamilyPersonState.FromTemporaryPerson(), false); }
/// <summary> /// Handles the DeleteGroupTypeClick event of the groupTypeEditor control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void groupTypeEditor_DeleteGroupTypeClick(object sender, EventArgs e) { CheckinGroupTypeEditor groupTypeEditor = sender as CheckinGroupTypeEditor; var groupType = GroupTypeCache.Read(groupTypeEditor.GroupTypeGuid); if (groupType != null) { // Warn if this GroupType or any of its child grouptypes (recursive) is being used as an Inherited Group Type. Probably shouldn't happen, but just in case if (IsInheritedGroupTypeRecursive(groupType)) { nbDeleteWarning.Text = "WARNING - Cannot delete. This group type or one of its child group types is assigned as an inherited group type."; nbDeleteWarning.Visible = true; return; } } groupTypeEditor.Parent.Controls.Remove(groupTypeEditor); }
/// <summary> /// Gets the expression. /// </summary> /// <param name="context">The context.</param> /// <param name="entityIdProperty">The entity identifier property.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection) { int familyGroupTypeId = GroupTypeCache.GetFamilyGroupType().Id; var familyGroups = new GroupService(context).Queryable() .Where(m => m.GroupTypeId == familyGroupTypeId); var personFamilyNameQuery = new PersonService(context).Queryable() .Select(p => familyGroups.Where(g => g.Members.Any(a => a.PersonId == p.Id)).Select(a => new { a.Members.FirstOrDefault(x => x.PersonId == p.Id).GroupOrder, GroupName = a.Name }).OrderBy(a => a.GroupOrder).Select(a => a.GroupName).FirstOrDefault() ); return(SelectExpressionExtractor.Extract(personFamilyNameQuery, entityIdProperty, "p")); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit( EventArgs e ) { base.OnInit( e ); _groupType = GroupTypeCache.Read( GetAttributeValue( "GroupType" ).AsGuid() ); if ( _groupType == null ) { _groupType = GroupTypeCache.GetFamilyGroupType(); } _groupTypeName = _groupType.Name; _isFamilyGroupType = _groupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid() ); _locationType = _groupType.LocationTypeValues.FirstOrDefault( v => v.Guid.Equals( GetAttributeValue( "LocationType" ).AsGuid() ) ); if ( _locationType == null ) { _locationType = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME ); } if ( _isFamilyGroupType ) { divGroupName.Visible = false; var campusi = GetAttributeValue( "ShowInactiveCampuses" ).AsBoolean() ? CampusCache.All() : CampusCache.All().Where( c => c.IsActive == true ).ToList(); cpCampus.Campuses = campusi; cpCampus.Visible = campusi.Any(); if ( campusi.Count == 1 ) { cpCampus.SelectedCampusId = campusi.FirstOrDefault().Id; } ddlMaritalStatus.Visible = true; ddlMaritalStatus.BindToDefinedType( DefinedTypeCache.Read( Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS.AsGuid() ), true ); var AdultMaritalStatus = DefinedValueCache.Read( GetAttributeValue( "AdultMaritalStatus" ).AsGuid() ); if ( AdultMaritalStatus != null ) { ddlMaritalStatus.SetValue( AdultMaritalStatus.Id ); } _childRoleId = _groupType.Roles .Where( r => r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD.AsGuid() ) ) .Select( r => r.Id ) .FirstOrDefault(); } else { divGroupName.Visible = true; tbGroupName.Label = _groupTypeName + " Name"; cpCampus.Visible = false; ddlMaritalStatus.Visible = false; } nfmMembers.ShowGrade = _isFamilyGroupType; nfmMembers.RequireGender = GetAttributeValue( "Gender" ).AsBoolean(); nfmMembers.RequireGrade = GetAttributeValue( "Grade" ).AsBoolean(); _SMSEnabled = GetAttributeValue("SMS").AsBoolean(); lTitle.Text = string.Format( "Add {0}", _groupType.Name ).FormatAsHtmlTitle(); _homePhone = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME ); _cellPhone = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_MOBILE ); _confirmMaritalStatus = _isFamilyGroupType && GetAttributeValue( "MaritalStatusConfirmation" ).AsBoolean(); if ( _confirmMaritalStatus ) { string script = string.Format( @" $('a.js-confirm-marital-status').click(function( e ){{ var anyAdults = false; $(""input[id$='_rblRole_0']"").each(function() {{ if ( $(this).prop('checked') ) {{ anyAdults = true; }} }}); if ( anyAdults ) {{ if ( $('#{0}').val() == '' ) {{ e.preventDefault(); Rock.dialogs.confirm('You have not selected a marital status for the adults in this new family. Are you sure you want to continue?', function (result) {{ if (result) {{ window.location = e.target.href ? e.target.href : e.target.parentElement.href; }} }}); }} }} }}); ", ddlMaritalStatus.ClientID ); ScriptManager.RegisterStartupScript( btnNext, btnNext.GetType(), "confirm-marital-status", script, true ); } }
/// <summary> /// Checks the settings. /// </summary> /// <returns></returns> private bool CheckSettings() { _rockContext = _rockContext ?? new RockContext(); _mode = GetAttributeValue( "Mode" ); _autoFill = GetAttributeValue( "AutoFillForm" ).AsBoolean(); tbEmail.Required = _autoFill; string registerButtonText = GetAttributeValue( "RegisterButtonAltText" ); if ( string.IsNullOrWhiteSpace( registerButtonText ) ) { registerButtonText = "Register"; } btnRegister.Text = registerButtonText; int groupId = PageParameter( "GroupId" ).AsInteger(); _group = new GroupService( _rockContext ) .Queryable( "GroupType.DefaultGroupRole" ).AsNoTracking() .FirstOrDefault( g => g.Id == groupId ); if ( _group == null ) { nbNotice.Heading = "Unknown Group"; nbNotice.Text = "<p>This page requires a valid group id parameter, and there was not one provided.</p>"; return false; } else { _defaultGroupRole = _group.GroupType.DefaultGroupRole; } _dvcConnectionStatus = DefinedValueCache.Read( GetAttributeValue( "ConnectionStatus" ).AsGuid() ); if ( _dvcConnectionStatus == null ) { nbNotice.Heading = "Invalid Connection Status"; nbNotice.Text = "<p>The selected Connection Status setting does not exist.</p>"; return false; } _dvcRecordStatus = DefinedValueCache.Read( GetAttributeValue( "RecordStatus" ).AsGuid() ); if ( _dvcRecordStatus == null ) { nbNotice.Heading = "Invalid Record Status"; nbNotice.Text = "<p>The selected Record Status setting does not exist.</p>"; return false; } _married = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_MARITAL_STATUS_MARRIED.AsGuid() ); _homeAddressType = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid() ); _familyType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid() ); _adultRole = _familyType.Roles.FirstOrDefault( r => r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid() ) ); if ( _married == null || _homeAddressType == null || _familyType == null || _adultRole == null ) { nbNotice.Heading = "Missing System Value"; nbNotice.Text = "<p>There is a missing or invalid system value. Check the settings for Marital Status of 'Married', Location Type of 'Home', Group Type of 'Family', and Family Group Role of 'Adult'.</p>"; return false; } return true; }
/// <summary> /// Updates the group member. /// </summary> /// <param name="businessId">The business identifier.</param> /// <param name="groupType">Type of the group.</param> /// <param name="groupName">Name of the group.</param> /// <param name="campusId">The campus identifier.</param> /// <param name="groupRoleId">The group role identifier.</param> /// <param name="rockContext">The rock context.</param> /// <returns></returns> private GroupMember UpdateGroupMember( int businessId, GroupTypeCache groupType, string groupName, int? campusId, int groupRoleId, RockContext rockContext ) { var groupMemberService = new GroupMemberService( rockContext ); GroupMember groupMember = groupMemberService.Queryable( "Group" ) .Where( m => m.PersonId == businessId && m.GroupRoleId == groupRoleId ) .FirstOrDefault(); if ( groupMember == null ) { groupMember = new GroupMember(); groupMember.Group = new Group(); groupMemberService.Add( groupMember ); } groupMember.PersonId = businessId; groupMember.GroupRoleId = groupRoleId; groupMember.GroupMemberStatus = GroupMemberStatus.Active; groupMember.Group.GroupTypeId = groupType.Id; groupMember.Group.Name = groupName; groupMember.Group.CampusId = campusId; return groupMember; }
/// <summary> /// Shows the group type edit details. /// </summary> /// <param name="groupType">Type of the group.</param> /// <param name="group">The group.</param> /// <param name="setValues">if set to <c>true</c> [set values].</param> private void ShowGroupTypeEditDetails( GroupTypeCache groupType, Group group, bool setValues ) { if ( group != null ) { // Save value to viewstate for use later when binding location grid AllowMultipleLocations = groupType != null && groupType.AllowMultipleLocations; // show/hide group sync panel based on permissions from the group type if ( group.GroupTypeId != 0 ) { using ( var rockContext = new RockContext() ) { GroupType selectedGroupType = new GroupTypeService( rockContext ).Get( group.GroupTypeId ); if ( selectedGroupType != null ) { wpGroupSync.Visible = selectedGroupType.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson ); } } } if ( groupType != null && groupType.LocationSelectionMode != GroupLocationPickerMode.None ) { wpMeetingDetails.Visible = true; gLocations.Visible = true; BindLocationsGrid(); } else { wpMeetingDetails.Visible = pnlSchedule.Visible; gLocations.Visible = false; } gLocations.Columns[2].Visible = groupType != null && ( groupType.EnableLocationSchedules ?? false ); spSchedules.Visible = groupType != null && ( groupType.EnableLocationSchedules ?? false ); phGroupAttributes.Controls.Clear(); group.LoadAttributes(); if ( group.Attributes != null && group.Attributes.Any() ) { wpGroupAttributes.Visible = true; Rock.Attribute.Helper.AddEditControls( group, phGroupAttributes, setValues, BlockValidationGroup ); } else { wpGroupAttributes.Visible = false; } } }
public NavigationGroupType( GroupTypeCache groupType, List<DateTime> chartTimes ) { Id = groupType.Id; Name = groupType.Name; Order = groupType.Order; CurrentPersonIds = new List<int>(); RecentPersonIds = new Dictionary<DateTime, List<int>>(); chartTimes.ForEach( t => RecentPersonIds.Add( t, new List<int>() ) ); ChildGroupTypeIds = new List<int>(); ChildGroupIds = new List<int>(); }
/// <summary> /// Determines whether [is inherited group type recursive] [the specified group type]. /// </summary> /// <param name="groupType">Type of the group.</param> /// <param name="rockContext">The rock context.</param> /// <returns></returns> private static bool IsInheritedGroupTypeRecursive( GroupTypeCache groupType, RockContext rockContext, List<int> typesChecked = null ) { // Track the groups that have been checked since group types can have themselves as a child typesChecked = typesChecked ?? new List<int>(); if ( !typesChecked.Contains( groupType.Id ) ) { typesChecked.Add( groupType.Id ); if ( new GroupTypeService( rockContext ).Queryable().Any( a => a.InheritedGroupType.Guid == groupType.Guid ) ) { return true; } foreach ( var childGroupType in groupType.ChildGroupTypes.Where( t => !typesChecked.Contains( t.Id ) ) ) { if ( IsInheritedGroupTypeRecursive( childGroupType, rockContext, typesChecked ) ) { return true; } } } return false; }
private List<KioskLabel> GetGroupTypeLabels( GroupTypeCache groupType ) { var labels = new List<KioskLabel>(); //groupType.LoadAttributes(); foreach ( var attribute in groupType.Attributes.OrderBy( a => a.Value.Order ) ) { if ( attribute.Value.FieldType.Guid == SystemGuid.FieldType.BINARY_FILE.AsGuid() && attribute.Value.QualifierValues.ContainsKey( "binaryFileType" ) && attribute.Value.QualifierValues["binaryFileType"].Value.Equals( SystemGuid.BinaryFiletype.CHECKIN_LABEL, StringComparison.OrdinalIgnoreCase ) ) { Guid? binaryFileGuid = groupType.GetAttributeValue( attribute.Key ).AsGuidOrNull(); if ( binaryFileGuid != null ) { var labelCache = KioskLabel.Read( binaryFileGuid.Value ); labelCache.Order = attribute.Value.Order; if ( labelCache != null ) { labels.Add( labelCache ); } } } } return labels; }
/// <summary> /// Determines whether [is inherited group type recursive] [the specified group type]. /// </summary> /// <param name="groupType">Type of the group.</param> /// <param name="rockContext">The rock context.</param> /// <returns></returns> private static bool IsInheritedGroupTypeRecursive( GroupTypeCache groupType, RockContext rockContext ) { if ( new GroupTypeService( rockContext ).Queryable().Any( a => a.InheritedGroupType.Guid == groupType.Guid ) ) { return true; } foreach ( var childGroupType in groupType.ChildGroupTypes ) { if ( IsInheritedGroupTypeRecursive( childGroupType, rockContext ) ) { return true; } } return false; }
/// <summary> /// Checks the settings. /// </summary> /// <returns></returns> private bool CheckSettings() { _rockContext = _rockContext ?? new RockContext(); _mode = GetAttributeValue( "Mode" ); _autoFill = GetAttributeValue( "AutoFillForm" ).AsBoolean(); tbEmail.Required = _autoFill; string registerButtonText = GetAttributeValue( "RegisterButtonAltText" ); if ( string.IsNullOrWhiteSpace( registerButtonText ) ) { registerButtonText = "Register"; } btnRegister.Text = registerButtonText; var groupService = new GroupService( _rockContext ); bool groupIsFromQryString = true; Guid? groupGuid = GetAttributeValue( "Group" ).AsGuidOrNull(); if ( groupGuid.HasValue ) { _group = groupService.Get( groupGuid.Value ); groupIsFromQryString = false; } if ( _group == null ) { groupGuid = PageParameter( "GroupGuid" ).AsGuidOrNull(); if ( groupGuid.HasValue ) { _group = groupService.Get( groupGuid.Value ); } } if ( _group == null ) { int? groupId = PageParameter( "GroupId" ).AsIntegerOrNull(); if ( groupId.HasValue ) { _group = groupService.Get( groupId.Value ); } } if ( _group == null ) { nbNotice.Heading = "Unknown Group"; nbNotice.Text = "<p>This page requires a valid group id parameter, and there was not one provided.</p>"; return false; } else { if ( groupIsFromQryString && ( _group.IsSecurityRole || _group.GroupType.Guid == Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() ) ) { nbNotice.Heading = "Invalid Group"; nbNotice.Text = "<p>The selected group is a security group and this block cannot be used to add people to a security group (unless configured for that specific group).</p>"; return false; } else { _defaultGroupRole = _group.GroupType.DefaultGroupRole; } } _dvcConnectionStatus = DefinedValueCache.Read( GetAttributeValue( "ConnectionStatus" ).AsGuid() ); if ( _dvcConnectionStatus == null ) { nbNotice.Heading = "Invalid Connection Status"; nbNotice.Text = "<p>The selected Connection Status setting does not exist.</p>"; return false; } _dvcRecordStatus = DefinedValueCache.Read( GetAttributeValue( "RecordStatus" ).AsGuid() ); if ( _dvcRecordStatus == null ) { nbNotice.Heading = "Invalid Record Status"; nbNotice.Text = "<p>The selected Record Status setting does not exist.</p>"; return false; } _married = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_MARITAL_STATUS_MARRIED.AsGuid() ); _homeAddressType = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid() ); _familyType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid() ); _adultRole = _familyType.Roles.FirstOrDefault( r => r.Guid.Equals( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid() ) ); if ( _married == null || _homeAddressType == null || _familyType == null || _adultRole == null ) { nbNotice.Heading = "Missing System Value"; nbNotice.Text = "<p>There is a missing or invalid system value. Check the settings for Marital Status of 'Married', Location Type of 'Home', Group Type of 'Family', and Family Group Role of 'Adult'.</p>"; return false; } return true; }
private List<GroupTypeCache> GetDescendentGroupTypes( GroupTypeCache groupType, List<int> recursionControl = null ) { var results = new List<GroupTypeCache>(); if ( groupType != null ) { recursionControl = recursionControl ?? new List<int>(); if ( !recursionControl.Contains( groupType.Id ) ) { recursionControl.Add( groupType.Id ); results.Add( groupType ); foreach ( var childGroupType in groupType.ChildGroupTypes ) { var childResults = GetDescendentGroupTypes( childGroupType, recursionControl ); childResults.ForEach( c => results.Add( c ) ); } } } return results; }
private void AddGroupType( GroupTypeCache groupType, List<DateTime> chartTimes ) { if ( groupType != null && !NavData.GroupTypes.Exists( g => g.Id == groupType.Id ) ) { var navGroupType = new NavigationGroupType( groupType, chartTimes ); NavData.GroupTypes.Add( navGroupType ); foreach ( var childGroupType in groupType.ChildGroupTypes ) { AddGroupType( childGroupType, chartTimes ); navGroupType.ChildGroupTypeIds.Add( childGroupType.Id ); } } }
/// <summary> /// Shows the group type edit details. /// </summary> /// <param name="groupType">Type of the group.</param> /// <param name="group">The group.</param> /// <param name="setValues">if set to <c>true</c> [set values].</param> private void ShowGroupTypeEditDetails( GroupTypeCache groupType, Group group, bool setValues ) { if ( group != null ) { // Save value to viewstate for use later when binding location grid AllowMultipleLocations = groupType != null && groupType.AllowMultipleLocations; if ( groupType != null && groupType.LocationSelectionMode != GroupLocationPickerMode.None ) { wpLocations.Visible = true; wpLocations.Title = AllowMultipleLocations ? "Locations" : "Location"; BindLocationsGrid(); } else { wpLocations.Visible = false; } phGroupAttributes.Controls.Clear(); group.LoadAttributes(); if ( group.Attributes != null && group.Attributes.Any() ) { wpGroupAttributes.Visible = true; Rock.Attribute.Helper.AddEditControls( group, phGroupAttributes, setValues, "GroupDetail" ); } else { wpGroupAttributes.Visible = false; } } }
private void SetScheduleControls( GroupTypeCache groupType, Group group ) { if ( group != null ) { dowWeekly.SelectedDayOfWeek = null; timeWeekly.SelectedTime = null; sbSchedule.iCalendarContent = string.Empty; spSchedule.SetValue( null ); if ( group.Schedule != null ) { switch ( group.Schedule.ScheduleType ) { case ScheduleType.Named: spSchedule.SetValue( group.Schedule ); break; case ScheduleType.Custom: hfUniqueScheduleId.Value = group.Schedule.Id.ToString(); sbSchedule.iCalendarContent = group.Schedule.iCalendarContent; break; case ScheduleType.Weekly: hfUniqueScheduleId.Value = group.Schedule.Id.ToString(); dowWeekly.SelectedDayOfWeek = group.Schedule.WeeklyDayOfWeek; timeWeekly.SelectedTime = group.Schedule.WeeklyTimeOfDay; break; } } } pnlSchedule.Visible = false; rblScheduleSelect.Items.Clear(); ListItem liNone = new ListItem( "None", "0" ); liNone.Selected = group != null && ( group.Schedule == null || group.Schedule.ScheduleType == ScheduleType.None ); rblScheduleSelect.Items.Add( liNone ); if ( groupType != null && ( groupType.AllowedScheduleTypes & ScheduleType.Weekly ) == ScheduleType.Weekly ) { ListItem li = new ListItem( "Weekly", "1" ); li.Selected = group != null && group.Schedule != null && group.Schedule.ScheduleType == ScheduleType.Weekly; rblScheduleSelect.Items.Add( li ); pnlSchedule.Visible = true; } if ( groupType != null && ( groupType.AllowedScheduleTypes & ScheduleType.Custom ) == ScheduleType.Custom ) { ListItem li = new ListItem( "Custom", "2" ); li.Selected = group != null && group.Schedule != null && group.Schedule.ScheduleType == ScheduleType.Custom; rblScheduleSelect.Items.Add( li ); pnlSchedule.Visible = true; } if ( groupType != null && ( groupType.AllowedScheduleTypes & ScheduleType.Named ) == ScheduleType.Named ) { ListItem li = new ListItem( "Named", "4" ); li.Selected = group != null && group.Schedule != null && group.Schedule.ScheduleType == ScheduleType.Named; rblScheduleSelect.Items.Add( li ); pnlSchedule.Visible = true; } SetScheduleDisplay(); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit( EventArgs e ) { base.OnInit( e ); _groupType = GroupTypeCache.Read( GetAttributeValue( "GroupType" ).AsGuid() ); if ( _groupType == null ) { _groupType = GroupTypeCache.GetFamilyGroupType(); } _IsFamilyGroupType = _groupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid() ); rptrGroups.ItemDataBound += rptrGroups_ItemDataBound; _allowEdit = IsUserAuthorized( Rock.Security.Authorization.EDIT ); RegisterScripts(); }
private GroupTypeCache GetCheckinType( GroupTypeCache groupType, int templateTypeId, List<int> recursionControl = null ) { if ( groupType != null ) { recursionControl = recursionControl ?? new List<int>(); if ( !recursionControl.Contains( groupType.Id ) ) { recursionControl.Add( groupType.Id ); if ( groupType.GroupTypePurposeValueId.HasValue && groupType.GroupTypePurposeValueId == templateTypeId ) { return groupType; } foreach ( var parentGroupType in groupType.ParentGroupTypes ) { var checkinType = GetCheckinType( parentGroupType, templateTypeId, recursionControl ); if ( checkinType != null ) { return checkinType; } } } } return null; }
/// <summary> /// Initializes a new instance of the <see cref="CheckinType"/> class. /// </summary> /// <param name="checkinTypeId">The checkin type identifier.</param> public CheckinType( int checkinTypeId ) { _checkinType = GroupTypeCache.Read( checkinTypeId ); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit( EventArgs e ) { base.OnInit( e ); var rockContext = new RockContext(); int groupId = int.MinValue; if ( int.TryParse( PageParameter( "GroupId" ), out groupId ) ) { _group = new GroupService( rockContext ).Get( groupId ); } if ( _group == null ) { nbInvalidGroup.Text = "Sorry, but the specified group was not found."; nbInvalidGroup.NotificationBoxType = NotificationBoxType.Danger; nbInvalidGroup.Visible = true; _group = null; pnlEditGroup.Visible = false; return; } else { _groupType = GroupTypeCache.Read( _group.GroupTypeId ); rblNewPersonRole.DataSource = _groupType.Roles.OrderBy( r => r.Order ).ToList(); rblNewPersonRole.DataBind(); if ( _groupType != null ) { _isFamilyGroupType = _groupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid() ); } else { _groupType = GroupTypeCache.GetFamilyGroupType(); _isFamilyGroupType = true; } GroupTypeName = _groupType.Name; tbGroupName.Label = _groupType.Name + " Name"; confirmExit.ConfirmationMessage = string.Format( "Changes have been made to this {0} that have not yet been saved.", _groupType.Name.ToLower() ); cbRemoveOtherGroups.Text = string.Format( "Remove person from other {0}.", _groupType.Name.ToLower().Pluralize() ); var homeLocType = _groupType.LocationTypeValues.FirstOrDefault( v => v.Guid.Equals( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid() ) ); var prevLocType = _groupType.LocationTypeValues.FirstOrDefault( v => v.Guid.Equals( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_PREVIOUS.AsGuid() ) ); lbMoved.Visible = ( homeLocType != null && prevLocType != null ); basePersonUrl = ResolveUrl( "~/Person/" ); btnDelete.Attributes["onclick"] = string.Format( "javascript: return Rock.dialogs.confirmDelete(event, '{0}');", _groupType.Name ); } _canEdit = IsUserAuthorized( Authorization.EDIT ); var campusi = CampusCache.All(); cpCampus.Campuses = campusi; cpCampus.Visible = campusi.Any(); if ( _isFamilyGroupType ) { cpCampus.Required = true; ddlRecordStatus.Visible = true; ddlRecordStatus.BindToDefinedType( DefinedTypeCache.Read( Rock.SystemGuid.DefinedType.PERSON_RECORD_STATUS.AsGuid() ), true ); ddlReason.BindToDefinedType( DefinedTypeCache.Read( Rock.SystemGuid.DefinedType.PERSON_RECORD_STATUS_REASON.AsGuid() ), true ); } else { cpCampus.Required = false; ddlRecordStatus.Visible = false; } ddlNewPersonTitle.BindToDefinedType( DefinedTypeCache.Read( Rock.SystemGuid.DefinedType.PERSON_TITLE.AsGuid() ), true ); ddlNewPersonSuffix.BindToDefinedType( DefinedTypeCache.Read( Rock.SystemGuid.DefinedType.PERSON_SUFFIX.AsGuid() ), true ); ddlNewPersonMaritalStatus.BindToDefinedType( DefinedTypeCache.Read( Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS.AsGuid() ), true ); ddlNewPersonConnectionStatus.BindToDefinedType( DefinedTypeCache.Read( Rock.SystemGuid.DefinedType.PERSON_CONNECTION_STATUS.AsGuid() ), true ); lvMembers.DataKeyNames = new string[] { "Index" }; lvMembers.ItemDataBound += lvMembers_ItemDataBound; lvMembers.ItemCommand += lvMembers_ItemCommand; modalAddPerson.SaveButtonText = "Save"; modalAddPerson.SaveClick += modalAddPerson_SaveClick; modalAddPerson.OnCancelScript = string.Format( "$('#{0}').val('');", hfActiveTab.ClientID ); gLocations.DataKeyNames = new string[] { "Id" }; gLocations.RowDataBound += gLocations_RowDataBound; gLocations.RowEditing += gLocations_RowEditing; gLocations.RowUpdating += gLocations_RowUpdating; gLocations.RowCancelingEdit += gLocations_RowCancelingEdit; gLocations.Actions.ShowAdd = _canEdit; gLocations.Actions.ShowAdd = true; gLocations.Actions.AddClick += gLocations_Add; gLocations.IsDeleteEnabled = _canEdit; gLocations.GridRebind += gLocations_GridRebind; rblNewPersonGender.Items.Clear(); rblNewPersonGender.Items.Add( new ListItem( Gender.Male.ConvertToString(), Gender.Male.ConvertToInt().ToString() ) ); rblNewPersonGender.Items.Add( new ListItem( Gender.Female.ConvertToString(), Gender.Female.ConvertToInt().ToString() ) ); rblNewPersonGender.Items.Add( new ListItem( Gender.Unknown.ConvertToString(), Gender.Unknown.ConvertToInt().ToString() ) ); btnSave.Visible = _canEdit; // Save and Cancel should not confirm exit btnSave.OnClientClick = string.Format( "javascript:$('#{0}').val('');return true;", confirmExit.ClientID ); btnCancel.OnClientClick = string.Format( "javascript:$('#{0}').val('');return true;", confirmExit.ClientID ); }
private void GetGroupTypeLabels( GroupTypeCache groupType, List<CheckInLabel> labels, Dictionary<string, object> mergeObjects ) { //groupType.LoadAttributes(); foreach ( var attribute in groupType.Attributes.OrderBy( a => a.Value.Order ) ) { if ( attribute.Value.FieldType.Guid == SystemGuid.FieldType.BINARY_FILE.AsGuid() && attribute.Value.QualifierValues.ContainsKey( "binaryFileType" ) && attribute.Value.QualifierValues["binaryFileType"].Value.Equals( SystemGuid.BinaryFiletype.CHECKIN_LABEL, StringComparison.OrdinalIgnoreCase ) ) { Guid? binaryFileGuid = groupType.GetAttributeValue( attribute.Key ).AsGuidOrNull(); if ( binaryFileGuid != null ) { var labelCache = KioskLabel.Read( binaryFileGuid.Value ); if ( labelCache != null ) { var checkInLabel = new CheckInLabel( labelCache, mergeObjects ); checkInLabel.FileGuid = binaryFileGuid.Value; labels.Add( checkInLabel ); } } } } }
/// <summary> /// Shows the group type edit details. /// </summary> /// <param name="groupType">Type of the group.</param> /// <param name="group">The group.</param> /// <param name="setValues">if set to <c>true</c> [set values].</param> private void ShowGroupTypeEditDetails( GroupTypeCache groupType, Group group, bool setValues ) { if ( group != null ) { // Save value to viewstate for use later when binding location grid AllowMultipleLocations = groupType != null && groupType.AllowMultipleLocations; if ( groupType != null && groupType.LocationSelectionMode != GroupLocationPickerMode.None ) { wpMeetingDetails.Visible = true; gLocations.Visible = true; BindLocationsGrid(); } else { wpMeetingDetails.Visible = pnlSchedule.Visible; gLocations.Visible = false; } gLocations.Columns[2].Visible = groupType != null && ( groupType.EnableLocationSchedules ?? false ); spSchedules.Visible = groupType != null && ( groupType.EnableLocationSchedules ?? false ); phGroupAttributes.Controls.Clear(); group.LoadAttributes(); if ( group.Attributes != null && group.Attributes.Any() ) { wpGroupAttributes.Visible = true; Rock.Attribute.Helper.AddEditControls( group, phGroupAttributes, setValues, BlockValidationGroup ); } else { wpGroupAttributes.Visible = false; } } }