protected void Page_Load(object sender, EventArgs e) { PageTitle.TitleText = GetString("newsletter_issue_subscribersclicks.title"); linkId = QueryHelper.GetInteger("linkid", 0); if (linkId == 0) { RequestHelper.EndResponse(); } LinkInfo link = LinkInfoProvider.GetLinkInfo(linkId); EditedObject = link; IssueInfo issue = IssueInfoProvider.GetIssueInfo(link.LinkIssueID); EditedObject = issue; // Prevent accessing issues from sites other than current site if (issue.IssueSiteID != SiteContext.CurrentSiteID) { RedirectToResourceNotAvailableOnSite("Issue with ID " + link.LinkIssueID); } var where = new WhereCondition().Where("LinkID", QueryOperator.Equals, linkId); // Link's issue is the main A/B test issue if (issue.IssueIsABTest && !issue.IssueIsVariant) { // Get A/B test and its winner issue ID ABTestInfo test = ABTestInfoProvider.GetABTestInfoForIssue(issue.IssueID); if (test != null) { // Get ID of the same link from winner issue var winnerLink = LinkInfoProvider.GetLinks() .WhereEquals("LinkIssueID", test.TestWinnerIssueID) .WhereEquals("LinkTarget", link.LinkTarget) .WhereEquals("LinkDescription", link.LinkDescription) .TopN(1) .Column("LinkID") .FirstOrDefault(); if (winnerLink != null) { if (winnerLink.LinkID > 0) { // Add link ID of winner issue link where.Or(new WhereCondition().Where("LinkID", QueryOperator.Equals, winnerLink.LinkID)); } } } } where.And(new WhereCondition(fltOpenedBy.WhereCondition)); UniGrid.WhereCondition = where.WhereCondition; UniGrid.QueryParameters = where.Parameters; UniGrid.Pager.DefaultPageSize = PAGESIZE; UniGrid.Pager.ShowPageSize = false; UniGrid.FilterLimit = 1; UniGrid.OnExternalDataBound += UniGrid_OnExternalDataBound; }
/// <summary> /// Handles the UniGrid's OnExternalDataBound event. /// </summary> /// <param name="sender">The sender</param> /// <param name="sourceName">Name of the source</param> /// <param name="parameter">The data row</param> /// <returns>Formatted value to be used in the UniGrid</returns> protected object UniGrid_OnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName.ToLowerCSafe()) { case "issuesubject": return(HTMLHelper.HTMLEncode(MacroSecurityProcessor.RemoveSecurityParameters(parameter.ToString(), true, null))); case "issueopenedemails": return(GetOpenedEmails(parameter as DataRowView)); case "issuestatus": IssueStatusEnum status = IssueStatusEnum.Idle; if ((parameter != DBNull.Value) && (parameter != null)) { status = (IssueStatusEnum)parameter; } return(GetString(String.Format("newsletterissuestatus." + Convert.ToString(status)))); case "viewclickedlinks": if (sender is CMSGridActionButton) { // Hide 'view clicked links' action if tracking is not available or if the issue has no tracked links CMSGridActionButton imageButton = sender as CMSGridActionButton; if (!mTrackingEnabled) { imageButton.Visible = false; } else { GridViewRow gvr = parameter as GridViewRow; if (gvr != null) { DataRowView drv = gvr.DataItem as DataRowView; if (drv != null) { int issueId = ValidationHelper.GetInteger(drv["IssueID"], 0); // Try to get one tracked link (only ID) of the issue var links = LinkInfoProvider.GetLinks().WhereEquals("LinkIssueID", issueId).TopN(1).Column("LinkID"); if (!links.Any()) { imageButton.Visible = false; } } } } } return(sender); default: return(parameter); } }
protected DataSet GetLinks(string completeWhere, string currentOrder, int currentTopN, string columns, int currentOffset, int currentPageSize, ref int totalRecords) { // Default where condition WhereCondition whereIssues = new WhereCondition().WhereEquals("LinkIssueID", issueID); isMainABTestIssue = isMainABTestIssue && (issueID == IssueID); int winnerIssueId = 0; if (IncludeAllVariants && isABTest) { // Get all variants var issueIDs = IssueInfoProvider.GetIssues() .Column("IssueID") .WhereEquals("IssueID", IssueID) .Or() .WhereEquals("IssueVariantOfIssueID", IssueID).GetListResult <Int32>(); // Include all links for all variants whereIssues = new WhereCondition().WhereIn("LinkIssueID", issueIDs); } else if (IncludeWinnerStatistics && isMainABTestIssue) { var test = ABTestInfoProvider.GetABTestInfoForIssue(issueID); if (test != null) { // Get winner variant issue ID winnerIssueId = test.TestWinnerIssueID; } if (winnerIssueId > 0) { // Include winner issue whereIssues = whereIssues.Or().WhereEquals("LinkIssueID", winnerIssueId); } } // Get links with clicks statistics for issue(s) var query = LinkInfoProvider.GetLinks() .Columns( new QueryColumn("LinkID"), new QueryColumn("LinkIssueID"), new QueryColumn("LinkTarget"), new QueryColumn("LinkDescription"), new QueryColumn("LinkOutdated"), // Get total and unique clicks new AggregatedColumn(AggregationType.Count, "DISTINCT(ClickedLinkEmail)").As("UniqueClicks"), new AggregatedColumn(AggregationType.Count, "ClickedLinkEmail").As("TotalClicks") ) .Where(whereIssues) .And() .Where(fltLinks.WhereCondition) .Source(s => s.LeftJoin <ClickedLinkInfo>("LinkID", "ClickedLinkNewsletterLinkID")) .GroupBy("LinkID", "LinkIssueID", "LinkTarget", "LinkDescription", "LinkOutdated"); if ((winnerIssueId > 0) || IncludeAllVariants) { // Aggregate same links (LinkTarget, LinkDescription, LinkOutdated) from various variants (variant + winner OR all variants) query = query.AsNested() .Columns( new QueryColumn("LinkTarget"), new QueryColumn("LinkDescription"), new QueryColumn("LinkOutdated"), // Get ID of main issue link (grater than variant link ID) new AggregatedColumn(AggregationType.Max, "LinkID").As("LinkID"), // Get total and unique clicks (sum variants) new AggregatedColumn(AggregationType.Sum, "UniqueClicks").As("UniqueClicks"), new AggregatedColumn(AggregationType.Sum, "TotalClicks").As("TotalClicks") ) .GroupBy("LinkTarget", "LinkDescription", "LinkOutdated"); if (DisplayOnlyClickedLinks) { query = query.Having(x => x.WhereGreaterThan(new AggregatedColumn(AggregationType.Sum, "UniqueClicks"), 0)); } } else if (DisplayOnlyClickedLinks) { query = query.Having(x => x.WhereGreaterThan(new AggregatedColumn(AggregationType.Count, "DISTINCT(ClickedLinkEmail)").As("UniqueClicks"), 0)); } if (TopN > 0) { query = query.TopN(TopN); } query = query.OrderByDescending("UniqueClicks"); return(query.Result); }
protected void Page_Load(object sender, EventArgs e) { PageTitle.TitleText = GetString("newsletter_issue_subscribersclicks.title"); linkId = QueryHelper.GetInteger("linkid", 0); if (linkId == 0) { RequestHelper.EndResponse(); } LinkInfo link = LinkInfoProvider.GetLinkInfo(linkId); EditedObject = link; IssueInfo issue = IssueInfoProvider.GetIssueInfo(link.LinkIssueID); EditedObject = issue; // Prevent accessing issues from sites other than current site if (issue.IssueSiteID != SiteContext.CurrentSiteID) { RedirectToResourceNotAvailableOnSite("Issue with ID " + link.LinkIssueID); } var listingWhereCondition = new WhereCondition().WhereEquals("ClickedLinkNewsletterLinkID", linkId); // Link's issue is the main A/B test issue if (issue.IssueIsABTest && !issue.IssueIsVariant) { // Get A/B test and its winner issue ID ABTestInfo test = ABTestInfoProvider.GetABTestInfoForIssue(issue.IssueID); if (test != null) { // Get ID of the same link from winner issue var winnerLink = LinkInfoProvider.GetLinks() .WhereEquals("LinkIssueID", test.TestWinnerIssueID) .WhereEquals("LinkTarget", link.LinkTarget) .WhereEquals("LinkDescription", link.LinkDescription) .TopN(1) .Column("LinkID") .FirstOrDefault(); if (winnerLink != null) { if (winnerLink.LinkID > 0) { // Add link ID of winner issue link listingWhereCondition.Or(new WhereCondition().WhereEquals("ClickedLinkNewsletterLinkID", winnerLink.LinkID)); } } } } UniGrid.Pager.DefaultPageSize = PAGESIZE; UniGrid.Pager.ShowPageSize = false; UniGrid.FilterLimit = 1; fltOpenedBy.EmailColumn = "ClickedLinkEmail"; // Get click count by email UniGrid.DataSource = ClickedLinkInfoProvider.GetClickedLinks() .Columns( new QueryColumn("ClickedLinkEmail"), new AggregatedColumn(AggregationType.Count, null).As("ClickCount") ) .GroupBy("ClickedLinkEmail") .Where(listingWhereCondition) .And() .Where(fltOpenedBy.WhereCondition) .OrderByDescending("ClickCount") .Result; }
protected void Page_Load(object sender, EventArgs e) { CurrentMaster.Title.TitleText = GetString("newsletter_issue_subscribersclicks.title"); CurrentMaster.Title.TitleImage = GetImageUrl("CMSModules/CMS_Newsletter/ViewParticipants.png"); linkId = QueryHelper.GetInteger("linkid", 0); if (linkId == 0) { RequestHelper.EndResponse(); } LinkInfo link = LinkInfoProvider.GetLinkInfo(linkId); EditedObject = link; IssueInfo issue = IssueInfoProvider.GetIssueInfo(link.LinkIssueID); EditedObject = issue; // Prevent accessing issues from sites other than current site if (issue.IssueSiteID != CMSContext.CurrentSiteID) { RedirectToResourceNotAvailableOnSite("Issue with ID " + link.LinkIssueID); } QueryDataParameters parameters = null; string where = string.Empty; // Link's issue is the main A/B test issue if (issue.IssueIsABTest && !issue.IssueIsVariant) { // Prepare base where condition where = "LinkID IN (" + link.LinkID.ToString(); // Get A/B test and its winner issue ID ABTestInfo test = ABTestInfoProvider.GetABTestInfoForIssue(issue.IssueID); if (test != null) { // Get ID of the same link from winner issue InfoDataSet <LinkInfo> winnerLink = LinkInfoProvider.GetLinks(string.Format("LinkIssueID={0} AND LinkTarget=N'{1}' AND LinkDescription=N'{2}'", test.TestWinnerIssueID, link.LinkTarget, link.LinkDescription), null, 1, "LinkID"); if (!DataHelper.DataSourceIsEmpty(winnerLink)) { string winnerLinkID = ValidationHelper.GetString(DataHelper.GetDataRowValue(winnerLink.Tables[0].Rows[0], "LinkID"), string.Empty); if (!string.IsNullOrEmpty(winnerLinkID)) { // Add link ID of winner issue link where += "," + winnerLinkID; } } } // Close where condition where += ")"; } else { // Filter by Link ID (from querystring) parameters = new QueryDataParameters(); parameters.Add("@LinkID", linkId); } UniGrid.QueryParameters = parameters; UniGrid.WhereCondition = SqlHelperClass.AddWhereCondition(fltOpenedBy.WhereCondition, where); UniGrid.Pager.DefaultPageSize = PAGESIZE; UniGrid.Pager.ShowPageSize = false; UniGrid.FilterLimit = 1; UniGrid.OnExternalDataBound += UniGrid_OnExternalDataBound; }
/// <summary> /// Handles the UniGrid's OnExternalDataBound event. /// </summary> /// <param name="sender">The sender</param> /// <param name="sourceName">Name of the source</param> /// <param name="parameter">The data row</param> /// <returns>Formatted value to be used in the UniGrid</returns> protected object UniGrid_OnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName.ToLowerCSafe()) { case "issuesubject": return(HTMLHelper.HTMLEncode(MacroResolver.RemoveSecurityParameters(parameter.ToString(), true, null))); case "issueopenedemails": return(GetOpenedEmails(parameter as DataRowView)); case "issuestatus": IssueStatusEnum status = IssueStatusEnum.Idle; if ((parameter != DBNull.Value) && (parameter != null)) { status = (IssueStatusEnum)parameter; } return(GetString(String.Format("newsletterissuestatus." + Convert.ToString(status)))); case "edit": if (sender is ImageButton) { if (mNewsletter.NewsletterType.EqualsCSafe(NewsletterType.Dynamic) && !mNewsletter.NewsletterEnableResending) { // Hide 'edit' action if newsletter is dynamic and resending is disabled ImageButton imageButton = sender as ImageButton; imageButton.Style.Add(HtmlTextWriterStyle.Display, "none"); } } return(sender); case "viewclickedlinks": if (sender is ImageButton) { // Hide 'view clicked links' action if tracking is not available or if the issue has no tracked links ImageButton imageButton = sender as ImageButton; if (!mTrackingEnabled) { imageButton.Style.Add(HtmlTextWriterStyle.Display, "none"); } else { GridViewRow gvr = parameter as GridViewRow; if (gvr != null) { DataRowView drv = gvr.DataItem as DataRowView; if (drv != null) { int issueId = ValidationHelper.GetInteger(drv["IssueID"], 0); // Try to get one tracked link (only ID) of the issue InfoDataSet <LinkInfo> links = LinkInfoProvider.GetLinks("LinkIssueID=" + issueId, null, 1, "LinkID"); if (DataHelper.DataSourceIsEmpty(links)) { imageButton.Style.Add(HtmlTextWriterStyle.Display, "none"); } } } } } return(sender); default: return(parameter); } }