/// <summary> /// Gets number of total pages waiting for the approval. /// </summary> /// <param name="siteInfo">Site the pages belongs to</param> /// <param name="userInfo">The user providing the approval</param> /// <returns>Total number of waiting pages</returns> private int GetNumberOfPendingPages(SiteInfo siteInfo, UserInfo userInfo) { int siteId = siteInfo.SiteID; // Get correct pending steps which may current user manage var steps = new IDQuery <WorkflowStepInfo>().Where(WorkflowStepInfoProvider.GetWorkflowPendingStepsWhereCondition(userInfo, siteId)); var docs = new IDQuery <TreeNode>() .OnSite(siteId) .WhereIn("DocumentWorkflowStepID", steps); return(docs.Count); }
protected void Page_Load(object sender, EventArgs e) { if (StopProcessing) { // Do nothing return; } gridElem.IsLiveSite = IsLiveSite; gridElem.OnExternalDataBound += gridElem_OnExternalDataBound; gridElem.HideControlForZeroRows = false; currentUserInfo = CMSContext.CurrentUser; // Initialize strings string strDays = GetString("MyDesk.OutdatedDocuments.Days"); string strWeeks = GetString("MyDesk.OutdatedDocuments.Weeks"); string strMonths = GetString("MyDesk.OutdatedDocuments.Months"); string strYears = GetString("MyDesk.OutdatedDocuments.Years"); // Set proper XML for control type switch (ListingType) { case ListingTypeEnum.CheckedOut: gridElem.ZeroRowsText = GetString("mydesk.ui.nochecked"); gridElem.WhereCondition = "View_CMS_Tree_Joined.DocumentCheckedOutByUserID = @UserID"; break; case ListingTypeEnum.MyDocuments: gridElem.ZeroRowsText = GetString("general.nodatafound"); gridElem.WhereCondition = "View_CMS_Tree_Joined.NodeOwner = @UserID"; break; case ListingTypeEnum.RecentDocuments: gridElem.ZeroRowsText = GetString("general.nodatafound"); gridElem.WhereCondition = "((View_CMS_Tree_Joined.DocumentCreatedByUserID = @UserID OR View_CMS_Tree_Joined.DocumentModifiedByUserID = @UserID OR View_CMS_Tree_Joined.DocumentCheckedOutByUserID = @UserID))"; break; case ListingTypeEnum.PendingDocuments: gridElem.ZeroRowsText = GetString("mydesk.ui.nowaitingdocs"); gridElem.WhereCondition = WorkflowStepInfoProvider.GetWorkflowPendingStepsWhereCondition(currentUserInfo, SiteName); break; case ListingTypeEnum.OutdatedDocuments: // Initialize controls if (!RequestHelper.IsPostBack()) { // Fill the dropdown list drpFilter.Items.Add(strDays); drpFilter.Items.Add(strWeeks); drpFilter.Items.Add(strMonths); drpFilter.Items.Add(strYears); // Load default value txtFilter.Text = "1"; drpFilter.SelectedValue = strYears; // Bind dropdown lists BindDropDowns(); } gridElem.WhereCondition = "((DocumentCreatedByUserID = @UserID OR DocumentModifiedByUserID = @UserID OR DocumentCheckedOutByUserID = @UserID) AND " + SOURCE_MODIFIEDWHEN + "<=@OlderThan AND " + SOURCE_NODESITEID + "=@SiteID)"; // Add where condition if (!string.IsNullOrEmpty(txtDocumentName.Text)) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, GetOutdatedWhereCondition(SOURCE_DOCUMENTNAME, drpDocumentName, txtDocumentName)); } if (!string.IsNullOrEmpty(txtDocumentType.Text)) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, GetOutdatedWhereCondition(SOURCE_CLASSDISPLAYNAME, drpDocumentType, txtDocumentType)); } gridElem.ZeroRowsText = GetString("mydesk.ui.nooutdated"); // Show custom filter plcOutdatedFilter.Visible = true; break; case ListingTypeEnum.WorkflowDocuments: break; case ListingTypeEnum.PageTemplateDocuments: gridElem.ZeroRowsText = GetString("Administration-PageTemplate_Header.Documents.nodata"); break; case ListingTypeEnum.CategoryDocuments: gridElem.ZeroRowsText = GetString("Category_Edit.Documents.nodata"); break; case ListingTypeEnum.ProductDocuments: break; case ListingTypeEnum.TagDocuments: gridElem.ZeroRowsText = GetString("taggroup_edit.documents.nodata"); break; case ListingTypeEnum.DocTypeDocuments: gridElem.ZeroRowsText = GetString("DocumentType_Edit_General.Documents.nodata"); break; case ListingTypeEnum.All: gridElem.ZeroRowsText = GetString("mydesk.ui.nodata"); break; } // Page Size if (!RequestHelper.IsPostBack() && !String.IsNullOrEmpty(ItemsPerPage)) { gridElem.Pager.DefaultPageSize = ValidationHelper.GetInteger(ItemsPerPage, -1); } // Order switch (ListingType) { case ListingTypeEnum.WorkflowDocuments: case ListingTypeEnum.OutdatedDocuments: case ListingTypeEnum.PageTemplateDocuments: case ListingTypeEnum.CategoryDocuments: case ListingTypeEnum.TagDocuments: case ListingTypeEnum.ProductDocuments: case ListingTypeEnum.DocTypeDocuments: gridElem.OrderBy = SOURCE_DOCUMENTNAME; break; default: gridElem.OrderBy = OrderBy; break; } if (ListingType == ListingTypeEnum.All) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, String.Format("(UserID1 = {0} OR UserID2 = {0} OR UserID3 = {0})", currentUserInfo.UserID)); } // Create query parameters QueryDataParameters parameters = new QueryDataParameters(); if (ListingType == ListingTypeEnum.OutdatedDocuments) { parameters.Add("@SiteID", CMSContext.CurrentSite.SiteID); DateTime olderThan = DateTime.Now; int dateTimeValue = ValidationHelper.GetInteger(txtFilter.Text, 0); if (drpFilter.SelectedValue == strDays) { olderThan = olderThan.AddDays(-dateTimeValue); } else if (drpFilter.SelectedValue == strWeeks) { olderThan = olderThan.AddDays(-dateTimeValue * 7); } else if (drpFilter.SelectedValue == strMonths) { olderThan = olderThan.AddMonths(-dateTimeValue); } else if (drpFilter.SelectedValue == strYears) { olderThan = olderThan.AddYears(-dateTimeValue); } parameters.Add("@OlderThan", olderThan); } // Initialize UserID query parameter int userID = currentUserInfo.UserID; if (ListingType == ListingTypeEnum.PendingDocuments) { parameters.Add("@SiteID", SiteInfoProvider.GetSiteID(SiteName)); if ((currentUserInfo.IsGlobalAdministrator) || (currentUserInfo.IsAuthorizedPerResource("CMS.Content", "manageworkflow"))) { userID = -1; } } parameters.Add("@UserID", userID); // Document Age if (DocumentAge != String.Empty) { string[] ages = DocumentAge.Split(';'); if (ages.Length == 2) { // Add from a to values to temp parameters int from = ValidationHelper.GetInteger(ages[1], 0); int to = ValidationHelper.GetInteger(ages[0], 0); if (from > 0) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SOURCE_MODIFIEDWHEN + " >= @FROM"); parameters.Add("@FROM", DateTime.Now.AddDays((-1) * from)); } if (to > 0) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SOURCE_MODIFIEDWHEN + " <= @TO"); parameters.Add("@TO", DateTime.Now.AddDays((-1) * to)); } } } // Site name if (!String.IsNullOrEmpty(SiteName) && (SiteName != UniGrid.ALL)) { SiteInfo site = SiteInfoProvider.GetSiteInfo(SiteName); if (site != null) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SOURCE_NODESITEID + " = " + site.SiteID); UniGrid.GridColumns.Columns.RemoveAll(c => (c.Source == SOURCE_SITENAME || c.Source == SOURCE_NODESITEID)); } } // Path filter if (Path != String.Empty) { if (ListingType == ListingTypeEnum.All) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SOURCE_DOCUMENTNAMEPATH + " LIKE N'" + CMSContext.ResolveCurrentPath(Path).Replace("'", "''") + "'"); } else { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SOURCE_NODEALIASPATH + " LIKE N'" + CMSContext.ResolveCurrentPath(Path).Replace("'", "''") + "'"); } } // Document type filer if (!String.IsNullOrEmpty(DocumentType)) { string[] types = DocumentType.Split(';'); gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SqlHelperClass.GetWhereCondition <string>(SOURCE_CLASSNAME, types, true)); } // Document name filter if (DocumentName != String.Empty) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, SOURCE_DOCUMENTNAME + " LIKE N'%" + SqlHelperClass.GetSafeQueryString(DocumentName, false) + "%'"); } // Site running filter if ((SiteName == UniGrid.ALL) && DisplayOnlyRunningSites) { gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, "SiteName IN (SELECT SiteName FROM CMS_Site WHERE SiteStatus = 'RUNNING')"); } // Set parameters gridElem.QueryParameters = parameters; }
/// <summary> /// Setups grid where condition to filter out by given restrictions. /// </summary> private void SetupGridFilterWhereCondition() { string where = String.Empty; // Set proper base where condition switch (ListingType) { case ListingTypeEnum.CheckedOut: where = "DocumentCheckedOutByUserID = @UserID"; break; case ListingTypeEnum.MyDocuments: where = "NodeOwner = @UserID"; break; case ListingTypeEnum.RecentDocuments: where = "((DocumentCreatedByUserID = @UserID OR DocumentModifiedByUserID = @UserID OR DocumentCheckedOutByUserID = @UserID))"; break; case ListingTypeEnum.PendingDocuments: where = "DocumentWorkflowStepID IN (SELECT StepID FROM CMS_WorkflowStep WHERE " + WorkflowStepInfoProvider.GetWorkflowPendingStepsWhereCondition(currentUserInfo, new SiteInfoIdentifier(SiteName)).ToString(false) + ")"; break; case ListingTypeEnum.OutdatedDocuments: where = "DocumentCreatedByUserID = @UserID OR DocumentModifiedByUserID = @UserID OR DocumentCheckedOutByUserID = @UserID"; break; case ListingTypeEnum.All: where = String.Format("(UserID1 = {0} OR UserID2 = {0} OR UserID3 = {0})", currentUserInfo.UserID); break; } gridElem.WhereCondition = SqlHelper.AddWhereCondition(gridElem.WhereCondition, where); // Selected site filter if (!String.IsNullOrEmpty(SiteName) && (SiteName != UniGrid.ALL)) { selectedSiteInfo = SiteInfoProvider.GetSiteInfo(SiteName); if (selectedSiteInfo != null) { gridElem.WhereCondition = SqlHelper.AddWhereCondition(gridElem.WhereCondition, SOURCE_NODESITEID + " = " + selectedSiteInfo.SiteID); } } // Site running filter if ((SiteName == UniGrid.ALL) && DisplayOnlyRunningSites) { gridElem.WhereCondition = SqlHelper.AddWhereCondition(gridElem.WhereCondition, "NodeSiteID IN (SELECT SiteID FROM CMS_Site WHERE SiteStatus = 'RUNNING')"); } // Path filter if (Path != String.Empty) { gridElem.WhereCondition = SqlHelper.AddWhereCondition(gridElem.WhereCondition, ((ListingType == ListingTypeEnum.All) ? SOURCE_DOCUMENTNAMEPATH : SOURCE_NODEALIASPATH) + " LIKE N'" + SqlHelper.EscapeQuotes(MacroResolver.ResolveCurrentPath(Path)) + "'"); } // Document type filer if (!String.IsNullOrEmpty(DocumentType)) { string classNames = DocumentTypeHelper.GetClassNames(DocumentType); gridElem.WhereCondition = SqlHelper.AddWhereCondition(gridElem.WhereCondition, SqlHelper.GetWhereCondition <string>(SOURCE_CLASSNAME, classNames.Split(';'), true)); } // Document name filter if (DocumentName != String.Empty) { gridElem.WhereCondition = SqlHelper.AddWhereCondition(gridElem.WhereCondition, SOURCE_DOCUMENTNAME + " LIKE N'%" + SqlHelper.EscapeLikeText(SqlHelper.EscapeQuotes(DocumentName)) + "%'"); } }