/// <summary> /// Copies the properties from another RegistrationTemplateFormField object to this RegistrationTemplateFormField object /// </summary> /// <param name="target">The target.</param> /// <param name="source">The source.</param> public static void CopyPropertiesFrom(this RegistrationTemplateFormField target, RegistrationTemplateFormField source) { target.Id = source.Id; target.AttributeId = source.AttributeId; target.FieldSource = source.FieldSource; target.ForeignGuid = source.ForeignGuid; target.ForeignKey = source.ForeignKey; target.IsGridField = source.IsGridField; target.IsInternal = source.IsInternal; target.IsRequired = source.IsRequired; target.IsSharedValue = source.IsSharedValue; target.Order = source.Order; target.PersonFieldType = source.PersonFieldType; target.PostText = source.PostText; target.PreText = source.PreText; target.RegistrationTemplateFormId = source.RegistrationTemplateFormId; target.ShowCurrentValue = source.ShowCurrentValue; target.ShowOnWaitlist = source.ShowOnWaitlist; target.CreatedDateTime = source.CreatedDateTime; target.ModifiedDateTime = source.ModifiedDateTime; target.CreatedByPersonAliasId = source.CreatedByPersonAliasId; target.ModifiedByPersonAliasId = source.ModifiedByPersonAliasId; target.Guid = source.Guid; target.ForeignId = source.ForeignId; }
/// <summary> /// Clones this RegistrationTemplateFormField object to a new RegistrationTemplateFormField object /// </summary> /// <param name="source">The source.</param> /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param> /// <returns></returns> public static RegistrationTemplateFormField Clone(this RegistrationTemplateFormField source, bool deepCopy) { if (deepCopy) { return(source.Clone() as RegistrationTemplateFormField); } else { var target = new RegistrationTemplateFormField(); target.CopyPropertiesFrom(source); return(target); } }
/// <summary> /// Gets the existing value for a specific field for the given registrant. /// </summary> /// <param name="registrant">The registrant.</param> /// <param name="person">The person.</param> /// <param name="family">The family.</param> /// <param name="Field">The field.</param> /// <param name="rockContext">The rock context.</param> /// <returns></returns> public object GetRegistrantValue(RegistrationRegistrant registrant, Person person, Group family, RegistrationTemplateFormField Field, RockContext rockContext) { if (Field.FieldSource == RegistrationFieldSource.PersonField) { if (person != null) { DefinedValueCache dvPhone = null; switch (Field.PersonFieldType) { case RegistrationPersonFieldType.FirstName: return(person.NickName); case RegistrationPersonFieldType.LastName: return(person.LastName); case RegistrationPersonFieldType.Campus: { if (family != null) { return(family.CampusId); } break; } case RegistrationPersonFieldType.Address: { var location = person.GetHomeLocation(rockContext); if (location != null) { return(location.Clone()); } break; } case RegistrationPersonFieldType.Email: return(person.Email); case RegistrationPersonFieldType.Birthdate: return(person.BirthDate); case RegistrationPersonFieldType.Grade: return(person.GraduationYear); case RegistrationPersonFieldType.Gender: return(person.Gender); case RegistrationPersonFieldType.MaritalStatus: return(person.MaritalStatusValueId); case RegistrationPersonFieldType.MobilePhone: { dvPhone = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_MOBILE); break; } case RegistrationPersonFieldType.HomePhone: { dvPhone = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME); break; } case RegistrationPersonFieldType.WorkPhone: { dvPhone = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_WORK); break; } } if (dvPhone != null) { var phoneNumber = new PersonService(rockContext).GetPhoneNumber(person, dvPhone); if (phoneNumber != null) { return(phoneNumber.Clone()); } } } } else { var attribute = AttributeCache.Read(Field.AttributeId ?? 0); if (attribute != null) { switch (Field.FieldSource) { case RegistrationFieldSource.PersonAttribute: { if (person != null) { if (person.Attributes == null) { person.LoadAttributes(); } return(person.GetAttributeValue(attribute.Key)); } break; } case RegistrationFieldSource.GroupMemberAttribute: { if (registrant != null && registrant.GroupMember != null) { if (registrant.GroupMember.Attributes == null) { registrant.GroupMember.LoadAttributes(); } return(registrant.GroupMember.GetAttributeValue(attribute.Key)); } break; } case RegistrationFieldSource.RegistrationAttribute: { if (registrant != null) { if (registrant.Attributes == null) { registrant.LoadAttributes(); } return(registrant.GetAttributeValue(attribute.Key)); } break; } } } } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="FieldValueObject"/> class. /// </summary> /// <param name="field">The field.</param> /// <param name="fieldValue">The field value.</param> public FieldValueObject(RegistrationTemplateFormField field, object fieldValue) { FieldSource = field.FieldSource; PersonFieldType = field.PersonFieldType; FieldValue = fieldValue; }
/// <summary> /// Gets the person control for this field's <see cref="PersonFieldType"/> /// </summary> /// <param name="setValue">if set to <c>true</c> [set value].</param> /// <param name="fieldValue">The field value.</param> /// <param name="familyMemberSelected">if set to <c>true</c> [family member selected].</param> /// <param name="validationGroup">The validation group.</param> /// <returns></returns> public Control GetPersonControl(bool setValue, object fieldValue, bool familyMemberSelected, string validationGroup) { RegistrationTemplateFormField field = this; Control personFieldControl = null; switch (field.PersonFieldType) { case RegistrationPersonFieldType.FirstName: var tbFirstName = new RockTextBox { ID = "tbFirstName", Label = "First Name", Required = field.IsRequired, CssClass = "js-first-name", ValidationGroup = validationGroup, Enabled = !familyMemberSelected, Text = setValue && fieldValue != null?fieldValue.ToString() : string.Empty }; personFieldControl = tbFirstName; break; case RegistrationPersonFieldType.LastName: var tbLastName = new RockTextBox { ID = "tbLastName", Label = "Last Name", Required = field.IsRequired, ValidationGroup = validationGroup, Enabled = !familyMemberSelected, Text = setValue && fieldValue != null?fieldValue.ToString() : string.Empty }; personFieldControl = tbLastName; break; case RegistrationPersonFieldType.MiddleName: var tbMiddleName = new RockTextBox { ID = "tbMiddleName", Label = "Middle Name", Required = field.IsRequired, ValidationGroup = validationGroup, Enabled = !familyMemberSelected, Text = setValue && fieldValue != null?fieldValue.ToString() : string.Empty }; // Enable the middle name field if it is currently disabled but required and there is no value. if (!tbMiddleName.Enabled && tbMiddleName.Required && tbMiddleName.Text.IsNullOrWhiteSpace()) { tbMiddleName.Enabled = true; } personFieldControl = tbMiddleName; break; case RegistrationPersonFieldType.Campus: var cpHomeCampus = new CampusPicker { ID = "cpHomeCampus", Label = "Campus", Required = field.IsRequired, ValidationGroup = validationGroup, Campuses = CampusCache.All(false), SelectedCampusId = setValue && fieldValue != null?fieldValue.ToString().AsIntegerOrNull() : null }; personFieldControl = cpHomeCampus; break; case RegistrationPersonFieldType.Address: var acAddress = new AddressControl { ID = "acAddress", Label = "Address", UseStateAbbreviation = true, UseCountryAbbreviation = false, Required = field.IsRequired, ValidationGroup = validationGroup }; if (setValue && fieldValue != null) { acAddress.SetValues(fieldValue as Location); } personFieldControl = acAddress; break; case RegistrationPersonFieldType.Email: var tbEmail = new EmailBox { ID = "tbEmail", Label = "Email", Required = field.IsRequired, ValidationGroup = validationGroup, Text = setValue && fieldValue != null?fieldValue.ToString() : string.Empty }; personFieldControl = tbEmail; break; case RegistrationPersonFieldType.Birthdate: var bpBirthday = new BirthdayPicker { ID = "bpBirthday", Label = "Birthday", Required = field.IsRequired, ValidationGroup = validationGroup, SelectedDate = setValue && fieldValue != null ? fieldValue as DateTime? : null }; personFieldControl = bpBirthday; break; case RegistrationPersonFieldType.Grade: var gpGrade = new GradePicker { ID = "gpGrade", Label = "Grade", Required = field.IsRequired, ValidationGroup = validationGroup, UseAbbreviation = true, UseGradeOffsetAsValue = true, CssClass = "input-width-md" }; personFieldControl = gpGrade; if (setValue && fieldValue != null) { var value = fieldValue.ToString().AsIntegerOrNull(); gpGrade.SetValue(Person.GradeOffsetFromGraduationYear(value)); } break; case RegistrationPersonFieldType.Gender: var ddlGender = new RockDropDownList { ID = "ddlGender", Label = "Gender", Required = field.IsRequired, ValidationGroup = validationGroup, }; ddlGender.BindToEnum <Gender>(true, new Gender[1] { Gender.Unknown }); personFieldControl = ddlGender; if (setValue && fieldValue != null) { var value = fieldValue.ToString().ConvertToEnumOrNull <Gender>() ?? Gender.Unknown; ddlGender.SetValue(value.ConvertToInt()); } break; case RegistrationPersonFieldType.MaritalStatus: var dvpMaritalStatus = new DefinedValuePicker { ID = "dvpMaritalStatus", Label = "Marital Status", Required = field.IsRequired, ValidationGroup = validationGroup }; dvpMaritalStatus.DefinedTypeId = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS.AsGuid()).Id; personFieldControl = dvpMaritalStatus; if (setValue && fieldValue != null) { var value = fieldValue.ToString().AsInteger(); dvpMaritalStatus.SetValue(value); } break; case RegistrationPersonFieldType.AnniversaryDate: var dppAnniversaryDate = new DatePartsPicker { ID = "dppAnniversaryDate", Label = "Anniversary Date", Required = field.IsRequired, ValidationGroup = validationGroup, SelectedDate = setValue && fieldValue != null ? fieldValue as DateTime? : null }; personFieldControl = dppAnniversaryDate; break; case RegistrationPersonFieldType.MobilePhone: var dvMobilePhone = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_MOBILE); if (dvMobilePhone == null) { break; } var ppMobile = new PhoneNumberBox { ID = "ppMobile", Label = dvMobilePhone.Value, Required = field.IsRequired, ValidationGroup = validationGroup, CountryCode = PhoneNumber.DefaultCountryCode() }; var mobilePhoneNumber = setValue && fieldValue != null ? fieldValue as PhoneNumber : null; ppMobile.CountryCode = mobilePhoneNumber != null ? mobilePhoneNumber.CountryCode : string.Empty; ppMobile.Number = mobilePhoneNumber != null?mobilePhoneNumber.ToString() : string.Empty; personFieldControl = ppMobile; break; case RegistrationPersonFieldType.HomePhone: var dvHomePhone = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME); if (dvHomePhone == null) { break; } var ppHome = new PhoneNumberBox { ID = "ppHome", Label = dvHomePhone.Value, Required = field.IsRequired, ValidationGroup = validationGroup, CountryCode = PhoneNumber.DefaultCountryCode() }; var homePhoneNumber = setValue && fieldValue != null ? fieldValue as PhoneNumber : null; ppHome.CountryCode = homePhoneNumber != null ? homePhoneNumber.CountryCode : string.Empty; ppHome.Number = homePhoneNumber != null?homePhoneNumber.ToString() : string.Empty; personFieldControl = ppHome; break; case RegistrationPersonFieldType.WorkPhone: var dvWorkPhone = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_WORK); if (dvWorkPhone == null) { break; } var ppWork = new PhoneNumberBox { ID = "ppWork", Label = dvWorkPhone.Value, Required = field.IsRequired, ValidationGroup = validationGroup, CountryCode = PhoneNumber.DefaultCountryCode() }; var workPhoneNumber = setValue && fieldValue != null ? fieldValue as PhoneNumber : null; ppWork.CountryCode = workPhoneNumber != null ? workPhoneNumber.CountryCode : string.Empty; ppWork.Number = workPhoneNumber != null?workPhoneNumber.ToString() : string.Empty; personFieldControl = ppWork; break; case RegistrationPersonFieldType.ConnectionStatus: var dvpConnectionStatus = new DefinedValuePicker { ID = "dvpConnectionStatus", Label = "Connection Status", Required = field.IsRequired, ValidationGroup = validationGroup }; dvpConnectionStatus.DefinedTypeId = DefinedTypeCache.Get(new Guid(Rock.SystemGuid.DefinedType.PERSON_CONNECTION_STATUS)).Id; if (setValue && fieldValue != null) { var value = fieldValue.ToString().AsInteger(); dvpConnectionStatus.SetValue(value); } personFieldControl = dvpConnectionStatus; break; } return(personFieldControl); }