public IContentLibraryItem GetItem(IEclUri eclUri)
        {
            if (eclUri.ItemType == EclItemTypes.File)
            {
                if (eclUri.SubType.Equals("product"))
                {
                    string productId = eclUri.ItemId;
                    return(this.CreateProductItem(eclUri.PublicationId, null, EclProvider.ProductCatalog.GetProduct(productId, eclUri.PublicationId)));
                }
                else // selectable category
                {
                    string categoryId = eclUri.ItemId;
                    var    category   = EclProvider.GetCategory(categoryId, eclUri.PublicationId);
                    return(new SelectableCategoryItem(eclUri.PublicationId, category));
                }
            }
            else if (eclUri.ItemType == EclItemTypes.Folder)
            {
                if (eclUri.ItemId.StartsWith("Type_"))
                {
                    string typeName = eclUri.ItemId.Replace("Type_", "");
                    return(new TypeItem(eclUri.PublicationId, typeName));
                }
                else
                {
                    string categoryId = eclUri.ItemId;
                    if (categoryId == null)
                    {
                        throw new Exception("Undefined category for ECL URI: " + eclUri);
                    }
                    var category = EclProvider.GetCategory(categoryId, eclUri.PublicationId);
                    if (category == null)
                    {
                        // Use the root category as fallback to avoid errors when browsing in the ECL catalog
                        //
                        category = EclProvider.GetRootCategory(eclUri.PublicationId);
                    }

                    return(new CategoryItem(eclUri.PublicationId, category));
                }
            }
            throw new NotSupportedException();
        }
        public IFolderContent GetFolderContent(IEclUri parentFolderUri, int pageIndex, EclItemTypes itemTypes)
        {
            List <IContentLibraryListItem> items = new List <IContentLibraryListItem>();
            int numberOfPages = 1;

            // If root -> list all root categories
            //
            if (parentFolderUri.ItemType == EclItemTypes.MountPoint && itemTypes.HasFlag(EclItemTypes.Folder))
            {
                items.Add(new TypeItem(parentFolderUri.PublicationId, "Categories"));
                items.Add(new TypeItem(parentFolderUri.PublicationId, "Products"));
            }
            else if (parentFolderUri.ItemType == EclItemTypes.Folder && itemTypes.HasFlag(EclItemTypes.Folder))
            {
                if (parentFolderUri.ItemId.StartsWith("Type_"))
                {
                    if (parentFolderUri.ItemId.Equals("Type_Products"))
                    {
                        foreach (var category in EclProvider.GetRootCategory(parentFolderUri.PublicationId).Categories)
                        {
                            if (!String.IsNullOrEmpty(category.CategoryId))
                            {
                                items.Add(new CategoryItem(parentFolderUri.PublicationId, category));
                            }
                        }
                    }
                    else // Type_Categories
                    {
                        /*
                         * List<string> allCategories = EclProvider.GetAllCategoryIds();
                         * foreach ( var categoryId in allCategories )
                         * {
                         *  items.Add(new SelectableCategoryItem(parentFolderUri.PublicationId, categoryId));
                         * }
                         */

                        // TODO: Can we somehow build up a structure here instead???
                        // TODO: Have a hook for providers to hook in their variant on the listing here???

                        var allCategories = EclProvider.GetAllCategories(parentFolderUri.PublicationId);
                        foreach (var category in allCategories)
                        {
                            items.Add(new SelectableCategoryItem(parentFolderUri.PublicationId, category));
                        }
                    }
                }
                else
                {
                    // TODO: Always use the product catalog for retrieving the category???

                    var parentCategory = EclProvider.GetCategory(parentFolderUri.ItemId, parentFolderUri.PublicationId);
                    if (parentCategory != null)
                    {
                        foreach (var category in parentCategory.Categories)
                        {
                            if (!String.IsNullOrEmpty(category.CategoryId))
                            {
                                // TODO: Have possibility to have concrete category items for each provider
                                items.Add(new CategoryItem(parentFolderUri.PublicationId, category));
                            }
                        }

                        var result = EclProvider.ProductCatalog.GetProducts(parentFolderUri.ItemId, parentFolderUri.PublicationId, pageIndex);
                        if (result != null)
                        {
                            numberOfPages = result.NumberOfPages;
                            foreach (var product in result.Products)
                            {
                                items.Add(this.CreateProductItem(parentFolderUri.PublicationId, parentCategory, product));
                            }
                        }
                    }
                }
            }

            return(EclProvider.HostServices.CreateFolderContent(parentFolderUri, pageIndex, numberOfPages, items, CanGetUploadMultimediaItemsUrl(parentFolderUri.PublicationId), CanSearch(parentFolderUri.PublicationId)));
        }
Exemplo n.º 3
0
        public IFolderContent GetFolderContent(IEclUri parentFolderUri, int pageIndex, EclItemTypes itemTypes)
        {
            List <IContentLibraryListItem> items = new List <IContentLibraryListItem>();

            // If root -> list all root categories
            //
            if (parentFolderUri.ItemType == EclItemTypes.MountPoint && itemTypes.HasFlag(EclItemTypes.Folder))
            {
                items.Add(new TypeItem(parentFolderUri.PublicationId, "Categories"));
                items.Add(new TypeItem(parentFolderUri.PublicationId, "Products"));
            }
            else if (parentFolderUri.ItemType == EclItemTypes.Folder && itemTypes.HasFlag(EclItemTypes.Folder))
            {
                if (parentFolderUri.ItemId.StartsWith("Type_"))
                {
                    if (parentFolderUri.ItemId.Equals("Type_Products"))
                    {
                        foreach (var category in EclProvider.RootCategory.Categories)
                        {
                            if (!String.IsNullOrEmpty(category.CategoryId))
                            {
                                items.Add(new CategoryItem(parentFolderUri.PublicationId, category));
                            }
                        }
                    }
                    else // Type_Categories
                    {
                        /*
                         * List<string> allCategories = EclProvider.GetAllCategoryIds();
                         * foreach ( var categoryId in allCategories )
                         * {
                         *  items.Add(new SelectableCategoryItem(parentFolderUri.PublicationId, categoryId));
                         * }
                         * */
                        var allCategories = EclProvider.GetAllCategories();
                        foreach (var category in allCategories)
                        {
                            items.Add(new SelectableCategoryItem(parentFolderUri.PublicationId, category));
                        }
                    }
                }
                else
                {
                    // TODO: Always use the product catalog for retrieving the category???

                    var parentCategory = EclProvider.GetCategory(parentFolderUri.ItemId);
                    if (parentCategory != null)
                    {
                        foreach (var category in parentCategory.Categories)
                        {
                            if (!String.IsNullOrEmpty(category.CategoryId))
                            {
                                // TODO: Have possibility to have concrete category items for each provider
                                items.Add(new CategoryItem(parentFolderUri.PublicationId, category));
                            }
                        }

                        var products = EclProvider.ProductCatalog.GetProducts(parentFolderUri.ItemId, parentFolderUri.PublicationId);
                        if (products != null)
                        {
                            // TODO: Have some kind of pagination here???

                            // At a leaf category -> list all products in that category
                            //
                            foreach (var product in products)
                            {
                                items.Add(this.CreateProductItem(parentFolderUri.PublicationId, parentCategory, product));
                            }
                        }
                    }
                }
            }

            return(EclProvider.HostServices.CreateFolderContent(parentFolderUri, items, CanGetUploadMultimediaItemsUrl(parentFolderUri.PublicationId), CanSearch(parentFolderUri.PublicationId)));
        }