/// <summary> /// Shows the view. /// </summary> /// <param name="groupId">The group identifier.</param> /// <param name="groupMemberId">The group member identifier.</param> protected void ShowView(int groupId, int groupMemberId) { pnlView.Visible = true; pnlMain.Visible = true; pnlEditPreferences.Visible = false; hfGroupId.Value = groupId.ToString(); hfGroupMemberId.Value = groupMemberId.ToString(); var rockContext = new RockContext(); var group = new GroupService(rockContext).Get(groupId); if (group == null) { pnlView.Visible = false; return; } var groupMember = new GroupMemberService(rockContext).Queryable().Where(a => a.GroupId == groupId && a.Id == groupMemberId).FirstOrDefault(); if (groupMember == null) { pnlView.Visible = false; return; } group.LoadAttributes(rockContext); // set page title to the trip name RockPage.Title = group.GetAttributeValue("OpportunityTitle"); RockPage.BrowserTitle = group.GetAttributeValue("OpportunityTitle"); RockPage.Header.Title = group.GetAttributeValue("OpportunityTitle"); var mergeFields = LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson, new CommonMergeFieldsOptions { GetLegacyGlobalMergeFields = false }); mergeFields.Add("Group", group); groupMember.LoadAttributes(rockContext); mergeFields.Add("GroupMember", groupMember); // Left Top Sidebar var photoGuid = group.GetAttributeValue("OpportunityPhoto"); imgOpportunityPhoto.ImageUrl = string.Format("~/GetImage.ashx?Guid={0}", photoGuid); // Top Main string profileLavaTemplate = this.GetAttributeValue("ProfileLavaTemplate"); if (groupMember.PersonId == this.CurrentPersonId) { // show a warning about missing Photo or Intro if the current person is viewing their own profile var warningItems = new List <string>(); if (!groupMember.Person.PhotoId.HasValue) { warningItems.Add("photo"); } if (groupMember.GetAttributeValue("PersonalOpportunityIntroduction").IsNullOrWhiteSpace()) { warningItems.Add("personal opportunity introduction"); } nbProfileWarning.Text = "<stong>Tip!</strong> Edit your profile to add a " + warningItems.AsDelimited(", ", " and ") + "."; nbProfileWarning.Visible = warningItems.Any(); } else { nbProfileWarning.Visible = false; } btnEditProfile.Visible = groupMember.PersonId == this.CurrentPersonId; lMainTopContentHtml.Text = profileLavaTemplate.ResolveMergeFields(mergeFields); bool disablePublicContributionRequests = groupMember.GetAttributeValue("DisablePublicContributionRequests").AsBoolean(); // only show Contribution stuff if the current person is the participant and contribution requests haven't been disabled bool showContributions = !disablePublicContributionRequests && (groupMember.PersonId == this.CurrentPersonId); btnContributionsTab.Visible = showContributions; // Progress var entityTypeIdGroupMember = EntityTypeCache.GetId <Rock.Model.GroupMember>(); var contributionTotal = new FinancialTransactionDetailService(rockContext).Queryable() .Where(d => d.EntityTypeId == entityTypeIdGroupMember && d.EntityId == groupMemberId) .Sum(a => (decimal?)a.Amount) ?? 0.00M; var individualFundraisingGoal = groupMember.GetAttributeValue("IndividualFundraisingGoal").AsDecimalOrNull(); if (!individualFundraisingGoal.HasValue) { individualFundraisingGoal = group.GetAttributeValue("IndividualFundraisingGoal").AsDecimalOrNull(); } var amountLeft = individualFundraisingGoal - contributionTotal; var percentMet = individualFundraisingGoal > 0 ? contributionTotal * 100 / individualFundraisingGoal : 100; mergeFields.Add("AmountLeft", amountLeft); mergeFields.Add("PercentMet", percentMet); var queryParams = new Dictionary <string, string>(); queryParams.Add("GroupId", hfGroupId.Value); queryParams.Add("GroupMemberId", hfGroupMemberId.Value); mergeFields.Add("MakeDonationUrl", LinkedPageUrl("DonationPage", queryParams)); var opportunityType = DefinedValueCache.Get(group.GetAttributeValue("OpportunityType").AsGuid()); string makeDonationButtonText = null; if (groupMember.PersonId == this.CurrentPersonId) { makeDonationButtonText = "Make Payment"; } else { makeDonationButtonText = string.Format("Contribute to {0} {1}", RockFilters.Possessive(groupMember.Person.NickName), opportunityType); } mergeFields.Add("MakeDonationButtonText", makeDonationButtonText); var progressLavaTemplate = this.GetAttributeValue("ProgressLavaTemplate"); lProgressHtml.Text = progressLavaTemplate.ResolveMergeFields(mergeFields); // set text on the return button btnMainPage.Text = opportunityType.Value + " Page"; // Tab:Updates btnUpdatesTab.Visible = false; bool showContentChannelUpdates = false; var updatesContentChannelGuid = group.GetAttributeValue("UpdateContentChannel").AsGuidOrNull(); if (updatesContentChannelGuid.HasValue) { var contentChannel = new ContentChannelService(rockContext).Get(updatesContentChannelGuid.Value); if (contentChannel != null) { showContentChannelUpdates = true; // only show the UpdatesTab if there is another Tab option btnUpdatesTab.Visible = btnContributionsTab.Visible; string updatesLavaTemplate = this.GetAttributeValue("UpdatesLavaTemplate"); var contentChannelItems = new ContentChannelItemService(rockContext).Queryable().Where(a => a.ContentChannelId == contentChannel.Id).AsNoTracking().ToList(); mergeFields.Add("ContentChannelItems", contentChannelItems); lUpdatesContentItemsHtml.Text = updatesLavaTemplate.ResolveMergeFields(mergeFields); btnUpdatesTab.Text = string.Format("{0} Updates ({1})", opportunityType, contentChannelItems.Count()); } } if (showContentChannelUpdates) { SetActiveTab("Updates"); } else if (showContributions) { SetActiveTab("Contributions"); } else { SetActiveTab(""); } // Tab: Contributions BindContributionsGrid(); // Tab:Comments var noteType = NoteTypeCache.Get(this.GetAttributeValue("NoteType").AsGuid()); if (noteType != null) { notesCommentsTimeline.NoteOptions.SetNoteTypes(new List <NoteTypeCache> { noteType }); } notesCommentsTimeline.NoteOptions.EntityId = groupMember.Id; // show the Add button on comments for any logged in person notesCommentsTimeline.AddAllowed = true; var enableCommenting = group.GetAttributeValue("EnableCommenting").AsBoolean(); if (CurrentPerson == null) { notesCommentsTimeline.Visible = enableCommenting && (notesCommentsTimeline.NoteCount > 0); lNoLoginNoCommentsYet.Visible = notesCommentsTimeline.NoteCount == 0; pnlComments.Visible = enableCommenting; btnLoginToComment.Visible = enableCommenting; } else { lNoLoginNoCommentsYet.Visible = false; notesCommentsTimeline.Visible = enableCommenting; pnlComments.Visible = enableCommenting; btnLoginToComment.Visible = false; } // if btnContributionsTab is the only visible tab, hide the tab since there is nothing else to tab to if (!btnUpdatesTab.Visible && btnContributionsTab.Visible) { SetActiveTab("Contributions"); btnContributionsTab.Visible = false; } }
/// <summary> /// Shows the view. /// </summary> /// <param name="groupId">The group identifier.</param> protected void ShowView(int groupId) { pnlView.Visible = true; hfGroupId.Value = groupId.ToString(); var rockContext = new RockContext(); var group = new GroupService(rockContext).Get(groupId); if (group == null) { pnlView.Visible = false; return; } group.LoadAttributes(rockContext); var opportunityType = DefinedValueCache.Get(group.GetAttributeValue("OpportunityType").AsGuid()); if (this.GetAttributeValue("SetPageTitletoOpportunityTitle").AsBoolean()) { RockPage.Title = group.GetAttributeValue("OpportunityTitle"); RockPage.BrowserTitle = group.GetAttributeValue("OpportunityTitle"); RockPage.Header.Title = group.GetAttributeValue("OpportunityTitle"); } var mergeFields = LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson, new CommonMergeFieldsOptions { GetLegacyGlobalMergeFields = false }); mergeFields.Add("Block", this.BlockCache); mergeFields.Add("Group", group); // Left Sidebar var photoGuid = group.GetAttributeValue("OpportunityPhoto").AsGuidOrNull(); imgOpportunityPhoto.Visible = photoGuid.HasValue; imgOpportunityPhoto.ImageUrl = string.Format("~/GetImage.ashx?Guid={0}", photoGuid); var groupMembers = group.Members.ToList(); foreach (var gm in groupMembers) { gm.LoadAttributes(rockContext); } // only show the 'Donate to a Participant' button if there are participants that are taking contribution requests btnDonateToParticipant.Visible = groupMembers.Where(a => !a.GetAttributeValue("DisablePublicContributionRequests").AsBoolean()).Any(); if (!string.IsNullOrWhiteSpace(opportunityType.GetAttributeValue("core_DonateButtonText"))) { btnDonateToParticipant.Text = opportunityType.GetAttributeValue("core_DonateButtonText"); } RegistrationInstance registrationInstance = null; var registrationInstanceId = group.GetAttributeValue("RegistrationInstance").AsIntegerOrNull(); if (registrationInstanceId.HasValue) { registrationInstance = new RegistrationInstanceService(rockContext).Get(registrationInstanceId.Value); } mergeFields.Add("RegistrationPage", LinkedPageRoute("RegistrationPage")); if (registrationInstance != null) { mergeFields.Add("RegistrationInstance", registrationInstance); mergeFields.Add("RegistrationInstanceLinkages", registrationInstance.Linkages); // populate merge fields for Registration Counts var maxRegistrantCount = 0; var currentRegistrationCount = 0; if (registrationInstance.MaxAttendees != 0) { maxRegistrantCount = registrationInstance.MaxAttendees; } currentRegistrationCount = new RegistrationRegistrantService(rockContext).Queryable().AsNoTracking() .Where(r => r.Registration.RegistrationInstanceId == registrationInstance.Id && r.OnWaitList == false) .Count(); mergeFields.Add("CurrentRegistrationCount", currentRegistrationCount); if (maxRegistrantCount != 0) { mergeFields.Add("MaxRegistrantCount", maxRegistrantCount); mergeFields.Add("RegistrationSpotsAvailable", maxRegistrantCount - currentRegistrationCount); } } string sidebarLavaTemplate = this.GetAttributeValue("SidebarLavaTemplate"); lSidebarHtml.Text = sidebarLavaTemplate.ResolveMergeFields(mergeFields); SetActiveTab("Details"); // Top Main string summaryLavaTemplate = this.GetAttributeValue("SummaryLavaTemplate"); lMainTopContentHtml.Text = summaryLavaTemplate.ResolveMergeFields(mergeFields); // only show the leader toolbox link of the currentperson has a leader role in the group btnLeaderToolbox.Visible = group.Members.Any(a => a.PersonId == this.CurrentPersonId && a.GroupRole.IsLeader); //// Participant Actions // only show if the current person is a group member var groupMember = group.Members.FirstOrDefault(a => a.PersonId == this.CurrentPersonId); if (groupMember != null) { hfGroupMemberId.Value = groupMember.Id.ToString(); pnlParticipantActions.Visible = true; } else { hfGroupMemberId.Value = null; pnlParticipantActions.Visible = false; } mergeFields.Add("GroupMember", groupMember); // Progress if (groupMember != null && pnlParticipantActions.Visible) { var entityTypeIdGroupMember = EntityTypeCache.GetId <Rock.Model.GroupMember>(); var contributionTotal = new FinancialTransactionDetailService(rockContext).Queryable() .Where(d => d.EntityTypeId == entityTypeIdGroupMember && d.EntityId == groupMember.Id) .Sum(a => (decimal?)a.Amount) ?? 0.00M; var individualFundraisingGoal = groupMember.GetAttributeValue("IndividualFundraisingGoal").AsDecimalOrNull(); if (!individualFundraisingGoal.HasValue) { individualFundraisingGoal = group.GetAttributeValue("IndividualFundraisingGoal").AsDecimalOrNull(); } var amountLeft = individualFundraisingGoal - contributionTotal; var percentMet = individualFundraisingGoal > 0 ? contributionTotal * 100 / individualFundraisingGoal : 100; mergeFields.Add("AmountLeft", amountLeft); mergeFields.Add("PercentMet", percentMet); var queryParams = new Dictionary <string, string>(); queryParams.Add("GroupId", hfGroupId.Value); queryParams.Add("GroupMemberId", hfGroupMemberId.Value); mergeFields.Add("MakeDonationUrl", LinkedPageUrl("DonationPage", queryParams)); mergeFields.Add("ParticipantPageUrl", LinkedPageUrl("ParticipantPage", queryParams)); string makeDonationButtonText = null; if (groupMember.PersonId == this.CurrentPersonId) { makeDonationButtonText = "Make Payment"; } else { makeDonationButtonText = string.Format("Contribute to {0} {1}", RockFilters.Possessive(groupMember.Person.NickName), opportunityType); } mergeFields.Add("MakeDonationButtonText", makeDonationButtonText); var participantLavaTemplate = this.GetAttributeValue("ParticipantLavaTemplate"); lParticipantActionsHtml.Text = participantLavaTemplate.ResolveMergeFields(mergeFields); } // Tab:Details lDetailsHtml.Text = group.GetAttributeValue("OpportunityDetails"); btnDetailsTab.Text = string.Format("{0} Details", opportunityType); // Tab:Updates liUpdatesTab.Visible = false; var updatesContentChannelGuid = group.GetAttributeValue("UpdateContentChannel").AsGuidOrNull(); if (updatesContentChannelGuid.HasValue) { var contentChannel = new ContentChannelService(rockContext).Get(updatesContentChannelGuid.Value); if (contentChannel != null) { liUpdatesTab.Visible = true; string updatesLavaTemplate = this.GetAttributeValue("UpdatesLavaTemplate"); var contentChannelItems = new ContentChannelItemService(rockContext).Queryable().Where(a => a.ContentChannelId == contentChannel.Id).AsNoTracking().ToList(); mergeFields.Add("ContentChannelItems", contentChannelItems); lUpdatesContentItemsHtml.Text = updatesLavaTemplate.ResolveMergeFields(mergeFields); btnUpdatesTab.Text = string.Format("{0} Updates ({1})", opportunityType, contentChannelItems.Count()); } } // Tab:Comments var noteType = NoteTypeCache.Get(this.GetAttributeValue("NoteType").AsGuid()); if (noteType != null) { notesCommentsTimeline.NoteOptions.SetNoteTypes(new List <NoteTypeCache> { noteType }); } notesCommentsTimeline.NoteOptions.EntityId = groupId; // show the Add button on comments for any logged in person notesCommentsTimeline.AddAllowed = true; var enableCommenting = group.GetAttributeValue("EnableCommenting").AsBoolean(); btnCommentsTab.Text = string.Format("Comments ({0})", notesCommentsTimeline.NoteCount); if (CurrentPerson == null) { notesCommentsTimeline.Visible = enableCommenting && (notesCommentsTimeline.NoteCount > 0); lNoLoginNoCommentsYet.Visible = notesCommentsTimeline.NoteCount == 0; liCommentsTab.Visible = enableCommenting; btnLoginToComment.Visible = enableCommenting; } else { lNoLoginNoCommentsYet.Visible = false; notesCommentsTimeline.Visible = enableCommenting; liCommentsTab.Visible = enableCommenting; btnLoginToComment.Visible = false; } // if btnDetailsTab is the only visible tab, hide the tab since there is nothing else to tab to if (!liCommentsTab.Visible && !liUpdatesTab.Visible) { tlTabList.Visible = false; } }
/// <summary> /// Executes the specified context. /// </summary> /// <param name="context">The context.</param> public void Execute(IJobExecutionContext context) { var jobDataMap = context.JobDetail.JobDataMap; var contentChannelGuid = jobDataMap.GetString(AttributeKey.ContentChannel).AsGuidOrNull(); if (!contentChannelGuid.HasValue) { context.Result = $"The Service Job {jobDataMap.GetString( "Name" )} did not specify a valid Content Channel"; ExceptionLogService.LogException(context.Result.ToString()); return; } var errors = new List <string>(); List <Exception> exceptions = new List <Exception>(); var rockContext = new RockContext(); var contentChannelId = new ContentChannelService(rockContext).GetId(contentChannelGuid.Value); var contentChannelItems = new ContentChannelItemService(rockContext).Queryable().Where(i => i.ContentChannelId == contentChannelId).ToList(); var attributeLinks = new Field.Types.KeyValueListFieldType().GetValuesFromString(null, jobDataMap.GetString(AttributeKey.AttributeLinks), null, false); var itemMergeFields = new Dictionary <string, object>(Lava.LavaHelper.GetCommonMergeFields(null)); var jobResultStringBuilder = new StringBuilder(); var totalItems = contentChannelItems.Count(); var updatedItems = 0; var updatedAttributes = 0; var itemId = 0; foreach (var contentChannelItem in contentChannelItems) { itemMergeFields.AddOrReplace("ContentChannelItem", contentChannelItem); foreach (var attributeLink in attributeLinks) { try { // merge the template lava and put the rendered text into the target key contentChannelItem.LoadAttributes(); var lavaTemplate = contentChannelItem.GetAttributeValue(attributeLink.Key); var lavaOutput = contentChannelItem.GetAttributeValue(attributeLink.Value.ToString()); if (lavaTemplate == null || lavaOutput == null) { var errorMessage = $"Template with key '{attributeLink.Key}' or target with key '{attributeLink.Value}' not found."; errors.Add(errorMessage); continue; } var mergedContent = lavaTemplate.ResolveMergeFields(itemMergeFields); if (lavaOutput.Equals(mergedContent)) { continue; } contentChannelItem.SetAttributeValue(attributeLink.Value.ToString(), mergedContent); updatedAttributes++; if (contentChannelItem.Id != itemId) { itemId = contentChannelItem.Id; updatedItems++; } } catch (Exception ex) { exceptions.Add(ex); jobResultStringBuilder.AppendLine($"<i class='fa fa-circle text-danger'></i> error(s) occurred. See exception log for details."); ExceptionLogService.LogException(ex); continue; } contentChannelItem.SaveAttributeValues(rockContext); } } jobResultStringBuilder.AppendLine($"Updated {updatedAttributes} ContentChannelItem {"attribute".PluralizeIf( updatedAttributes != 1 )} in {updatedItems} of {totalItems} ContentChannelItems"); foreach (var error in errors) { jobResultStringBuilder.AppendLine($"<i class='fa fa-circle text-warning'></i> {error}"); } context.Result = jobResultStringBuilder.ToString(); rockContext.SaveChanges(); if (exceptions.Any() || errors.Any()) { var exceptionList = new AggregateException("One or more exceptions occurred in ContentChannelItemSelfUpdate.", exceptions); throw new RockJobWarningException("ContentChannelItemSelfUpdate completed with warnings", exceptionList); } }