예제 #1
0
    /// <summary>
    /// Creates tree provider.
    /// </summary>
    private UniTreeProvider CreateTreeProvider(int siteId)
    {
        // Get root node level
        var rootPath  = ECommerceSettings.ProductsStartingPath(siteId);
        var rootLevel = rootPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Length;

        // Create and set sku category provider
        var provider = new UniTreeProvider
        {
            RootLevelOffset   = rootLevel,
            ObjectType        = "cms.tree",
            DisplayNameColumn = "NodeName",
            IDColumn          = "NodeID",
            LevelColumn       = "NodeLevel",
            OrderColumn       = "NodeOrder",
            ParentIDColumn    = "NodeParentID",
            PathColumn        = "NodeAliasPath",
            ValueColumn       = "NodeID",
            ChildCountColumn  = "NodeChildCount",
            Parameters        = new QueryDataParameters
            {
                { "SiteID", siteId }
            }
        };

        string selected = null;

        if (!string.IsNullOrEmpty(hidItem.Value))
        {
            var splittedValues = hidItem.Value.Split(new[]
            {
                mValuesSeparator
            }, StringSplitOptions.RemoveEmptyEntries);

            selected = mReturnColumnName == "NodeGUID"
                ? string.Join(",", splittedValues.Select(x => $"'{ValidationHelper.GetGuid(x, Guid.Empty)}'"))
                : string.Join(",", splittedValues.Select(x => ValidationHelper.GetInteger(x, 0)));
        }

        // Subquery to obtain count of enabled child sku categories for specified user, site
        string childCountColumn = "(SELECT COUNT(T.NodeID) FROM CMS_Tree AS T INNER JOIN CMS_Class AS C ON T.NodeClassID = C.ClassID AND C.ClassIsProductSection = 1 WHERE (T.NodeParentID = CMS_Tree.NodeID) AND (T.NodeSiteID = @SiteID)) AS NodeChildCount";

        // Subquery to obtain count of selected enabled child categories with no disabled parent.
        string checkedChildCountColumn = string.IsNullOrEmpty(selected) ? "(0) AS ChildChecked" : $"(SELECT COUNT(TT.NodeID) FROM CMS_Tree AS TT WHERE (TT.{mReturnColumnName} IN ({selected})) AND (TT.NodeAliasPath LIKE CMS_Tree.NodeAliasPath + '/%')) AS ChildChecked";

        // Prepare
        provider.Columns        = $"NodeID, NodeGUID, NodeName, NodeLevel, NodeOrder, NodeParentID, NodeAliasPath, {childCountColumn}, {checkedChildCountColumn}";
        provider.OrderBy        = "NodeAliasPath, NodeOrder";
        provider.WhereCondition = "NodeSiteID = @SiteID AND NodeAliasPath LIKE N'" + rootPath + "%' AND NodeClassID IN (SELECT ClassID FROM CMS_Class WHERE ClassIsProductSection = 1)";

        // Append explicit where condition
        provider.WhereCondition = SqlHelper.AddWhereCondition(provider.WhereCondition, mWhereCondition);

        return(provider);
    }