/// <summary> /// Builds up a relative path based on specified segment parts. /// </summary> /// <param name="path">Path segments</param> /// <returns>Returns a relative path.</returns> public string GetPath(string[] path) { string[] childPath = path ?? new string[] { }; // create result path string resultPath = PathUtil.Combine(childPath); resultPath = resultPath.Trim('/', '\\'); // prepend root path with corrected separators // remove all leading and trailing separator chars string cleansedRoot = RootPath.Trim('/', '\\'); // replace all slashes with directory separator cleansedRoot = cleansedRoot.Replace('/', PathUtil.DirectorySeparatorChar); // replace all backslashes with directory separator cleansedRoot = cleansedRoot.Replace('\\', PathUtil.DirectorySeparatorChar); if (!resultPath.StartsWith(cleansedRoot)) { resultPath = Path.Join(cleansedRoot, resultPath); } // if root path is relative, add relative separator if (RootPath.StartsWith(PathUtil.DirectorySeparatorChar) || RootPath.StartsWith(PathUtil.AltDirectorySeparatorChar)) { resultPath = PathUtil.DirectorySeparatorChar + resultPath; } return(resultPath); }
/// <summary> /// Initializes the category provider /// </summary> private void InitCategoryProvider() { // Create and set category provider UniTreeProvider categoryProvider = new UniTreeProvider(); categoryProvider.DisplayNameColumn = "DisplayName"; categoryProvider.IDColumn = "ObjectID"; categoryProvider.LevelColumn = "ObjectLevel"; categoryProvider.OrderColumn = "CategoryOrder"; categoryProvider.ParentIDColumn = "ParentID"; categoryProvider.PathColumn = "ObjectPath"; categoryProvider.ValueColumn = "ObjectID"; categoryProvider.ChildCountColumn = "CompleteChildCount"; categoryProvider.QueryName = "cms.pagetemplatecategory.selectallview"; categoryProvider.ObjectTypeColumn = "ObjectType"; categoryProvider.Columns = "DisplayName, CodeName, ObjectID, ObjectLevel, CategoryOrder, ParentID, ObjectPath, CompleteChildCount, ObjectType, CategoryChildCount, CategoryImagePath, Parameter"; categoryProvider.ImageColumn = "CategoryImagePath"; categoryProvider.ParameterColumn = "Parameter"; if (!SelectPageTemplates) { categoryProvider.WhereCondition = "ObjectType = 'pagetemplatecategory'"; categoryProvider.ChildCountColumn = "CategoryChildCount"; categoryProvider.ObjectTypeColumn = ""; } else { categoryProvider.OrderBy = "ObjectType DESC, DisplayName ASC"; } // Do not show AdHoc category if (!ShowAdHocCategory) { categoryProvider.WhereCondition = SqlHelper.AddWhereCondition(categoryProvider.WhereCondition, "CodeName <> 'AdHoc' AND CodeName <> 'AdHocUI'"); } // Do not show empty categories if (!ShowEmptyCategories) { categoryProvider.WhereCondition = SqlHelper.AddWhereCondition(categoryProvider.WhereCondition, "CategoryTemplateChildCount > 0 OR CategoryChildCount > 0"); TreeProvider tp = new TreeProvider(MembershipContext.AuthenticatedUser); CMS.DocumentEngine.TreeNode node = DocumentHelper.GetDocument(DocumentID, tp); string culture = LocalizationContext.PreferredCultureCode; int level = 0; string path = string.Empty; string className = String.Empty; if (node != null) { level = node.NodeLevel; path = node.NodeAliasPath; if (IsNewPage) { level++; path = path + "/%"; } else { culture = node.DocumentCulture; } className = node.NodeClassName; // Check if class id is in query string - then use it's value instead of document class name int classID = QueryHelper.GetInteger("classid", 0); if (classID != 0) { DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(classID); if (dci != null) { className = dci.ClassName; } } } // Add where condition for scopes categoryProvider.WhereCondition += " AND (ObjectLevel = 0 OR (SELECT TOP 1 ObjectID FROM View_CMS_PageTemplateCategoryPageTemplate_Joined AS X WHERE X.ObjectType = 'pagetemplate' "; categoryProvider.WhereCondition += " AND (X.PageTemplateType IS NULL OR X.PageTemplateType <> N'" + PageTemplateInfoProvider.GetPageTemplateTypeCode(PageTemplateTypeEnum.Dashboard) + "')"; if (ShowOnlySiteTemplates) { categoryProvider.WhereCondition += " AND X.ObjectID IN (SELECT PageTemplateID FROM CMS_PageTemplateSite WHERE SiteID = " + SiteContext.CurrentSiteID + ") "; } if (node != null) { categoryProvider.WhereCondition += " AND (" + PageTemplateScopeInfoProvider.GetScopeWhereCondition(path, culture, className, level, SiteContext.CurrentSiteName, "X", "ObjectID") + ") "; } categoryProvider.WhereCondition += " AND (X.ObjectPath LIKE View_CMS_PageTemplateCategoryPageTemplate_Joined.ObjectPath + '/%')) IS NOT NULL)"; // Add column count column - minimal number of children categoryProvider.Columns += @", (SELECT TOP 1 Count(*) FROM View_CMS_PageTemplateCategoryPageTemplate_Joined AS Y WHERE (Y.ObjectID = View_CMS_PageTemplateCategoryPageTemplate_Joined.ObjectID AND Y.ObjectLevel = 0) OR ( View_CMS_PageTemplateCategoryPageTemplate_Joined.ObjectType = 'PageTemplateCategory' AND View_CMS_PageTemplateCategoryPageTemplate_Joined.CategoryChildCount > 0 AND Y.ObjectType = 'PageTemplate' AND Y.ObjectLevel > View_CMS_PageTemplateCategoryPageTemplate_Joined.ObjectLevel + 1 "; if (ShowOnlySiteTemplates) { categoryProvider.Columns += "AND Y.ObjectID IN (SELECT PageTemplateID FROM CMS_PageTemplateSite WHERE SiteID = " + SiteContext.CurrentSiteID + ") "; } if (node != null) { categoryProvider.Columns += " AND ( " + PageTemplateScopeInfoProvider.GetScopeWhereCondition(path, culture, className, level, SiteContext.CurrentSiteName, "Y", "ObjectID") + " ) "; } categoryProvider.Columns += " AND Y.ObjectPath LIKE View_CMS_PageTemplateCategoryPageTemplate_Joined.ObjectPath + '/%')) AS MinNumberOfChilds"; categoryProvider.ChildCountColumn = "MinNumberOfChilds"; } // Handle the root path if (!String.IsNullOrEmpty(RootPath)) { categoryProvider.RootLevelOffset = RootPath.Trim('/').Split('/').Length - 1; categoryProvider.WhereCondition = SqlHelper.AddWhereCondition(categoryProvider.WhereCondition, String.Format("((ObjectPath = '{0}' OR ObjectPath LIKE '{0}/%'))", RootPath.Trim('/'))); } treeElem.ProviderObject = categoryProvider; }