GetCategory() public static method

public static GetCategory ( int itemId ) : Category
itemId int
return Category
コード例 #1
0
        /// <summary>
        /// Inserts a collection of <see cref="ListItem"/> into a <see cref="System.Web.UI.WebControls.ListControl"/>.
        /// Each item has a value of the name of the category plus ticks to indicate hierarchy between categories.
        /// Each item has a value of the category's itemId.
        /// If you have problems showing all Categories, you can try using <see cref="DisplayChildren(ListControl, int, int?)"/> on an instantiated ItemRelationship (see <see cref="Controls.ItemRelationships.UpdateAvailableItems"/> for an example).
        /// </summary>
        /// <param name="lc">The <see cref="System.Web.UI.WebControls.ListControl"/> into which the category options will be added.</param>
        /// <param name="categoryId">The id of the parent category from which the hierarchy will start, or -1 if all categories.</param>
        /// <param name="portalId">The id of the portal in which these categories reside.</param>
        /// <param name="includeParentCategory">if set to <c>true</c> includes the parent category in the list, otherwise only shows the parent's children.  This is ignored if the TopLevelCategory is selected.</param>
        /// <param name="itemToExclude">An item which you want to exclude from the list (including its children).  This is typically used to keep circular relationships from being possibe options.</param>
        public static void DisplayCategoryHierarchy(ListControl lc, int categoryId, int portalId, bool includeParentCategory, int itemToExclude)
        {
            DataTable dt;

            if (categoryId < 1)
            {
                dt = Category.GetCategoriesHierarchy(portalId);

                // we ignore includeParentCategory if it is the TopLevelCategory
            }
            else
            {
                dt = Item.GetAllChildren(ItemType.Category.GetId(), categoryId, RelationshipType.ItemToParentCategory.GetId(), portalId).Tables[0];

                if (includeParentCategory)
                {
                    Category parentCategory = Category.GetCategory(categoryId, portalId);
                    if (parentCategory != null)
                    {
                        DataRow parentRow = dt.NewRow();
                        parentRow["ParentItemId"] = "-1";
                        parentRow["ItemId"]       = categoryId;
                        parentRow["Name"]         = parentCategory.Name;
                        dt.Rows.InsertAt(parentRow, 0);
                    }
                }
            }

            TreeNode root = BuildHierarchy(dt);

            FillListControl(root, lc, itemToExclude);
        }
コード例 #2
0
 private void Page_Load(object sender, EventArgs e)
 {
     try
     {
         LocalizeControls();
         if (_itemType != null)
         {
             //TODO: we need to figure out PortalID so we can get the folloing items from Cache
             if (_itemType.Equals(ItemType.Category.Name, StringComparison.OrdinalIgnoreCase))
             {
                 //TODO: where can we get portalid from? NEED NEW METHOD - HK
                 Category category = Category.GetCategory(_itemId);
                 DisplayItem(category);
             }
             else if (_itemType.Equals(ItemType.Article.Name, StringComparison.OrdinalIgnoreCase))
             {
                 Article article = Article.GetArticle(_itemId);
                 DisplayItem(article);
             }
             else if (_itemType.Equals("OLDARTICLE", StringComparison.OrdinalIgnoreCase))
             {
                 int     newId   = Article.GetOldArticleId(_itemId);
                 Article article = Article.GetArticle(newId);
                 DisplayItem(article);
             }
         }
     }
     catch (Exception ec)
     {
         DotNetNuke.Services.Exceptions.Exceptions.ProcessPageLoadException(ec);
     }
 }
コード例 #3
0
        /// <summary>
        /// Creates an Article object that you can continue to modify or save back into the database.
        /// </summary>
        /// <param name="name">Name of the Category to be created.</param>
        /// <param name="description">The description/abstract of the category to be created.</param>
        /// <param name="articleText"></param>
        /// <param name="authorUserId">The ID of the author of this category.</param>
        /// <param name="parentCategoryId"></param>
        /// <param name="moduleId">The moduleid for where this category will most likely be displayed.</param>
        /// <param name="portalId">The Portal ID of the portal this category belongs to.</param>
        /// <returns>A <see cref="Article" /> with the assigned values.</returns>
        public static Article Create(string name, string description, string articleText, int authorUserId, int parentCategoryId, int moduleId, int portalId)
        {
            var a = new Article
            {
                Name         = name,
                Description  = description.Replace("<br>", "<br />"),
                _articleText = articleText.Replace("<br>", "<br />"),
                AuthorUserId = authorUserId
            };
            //should we strip <br> tags now?

            var irel = new ItemRelationship
            {
                RelationshipTypeId = Util.RelationshipType.ItemToParentCategory.GetId(),
                ParentItemId       = parentCategoryId
            };

            a.Relationships.Add(irel);
            a.StartDate = a.LastUpdated = a.CreatedDate = DateTime.Now.ToString(CultureInfo.InvariantCulture);
            a.PortalId  = portalId;
            a.ModuleId  = moduleId;
            Category c = Category.GetCategory(parentCategoryId, portalId);

            a.DisplayTabId     = c.ChildDisplayTabId;
            a.ApprovalStatusId = ApprovalStatus.Approved.GetId();
            a.NewWindow        = false;
            a.SetDefaultItemVersionSettings();
            return(a);
        }
コード例 #4
0
        private void DisplayCurrentVersion()
        {
            this.SetItemId(Convert.ToInt32(this.Request.QueryString["itemid"], CultureInfo.InvariantCulture));

            if (this.TypeOfItem == ItemType.Article)
            {
                string  articleControlToLoad = "~" + DesktopModuleFolderName + "ArticleControls/articleDisplay.ascx";
                Article a = Article.GetArticle(this.ItemId, this.PortalId);
                if (a == null)
                {
                    throw new InvalidOperationException("Article not found");
                }

                var ad = (ArticleDisplay)this.LoadControl(articleControlToLoad);
                ad.ModuleConfiguration = this.ModuleConfiguration;
                ad.ID                     = Path.GetFileNameWithoutExtension(articleControlToLoad);
                ad.Overrideable           = true;
                ad.DisplayPrinterFriendly = false;
                ad.DisplayRelatedArticle  = false;
                ad.DisplayRelatedLinks    = false;
                ad.DisplayEmailAFriend    = false;
                ad.SetItemId(a.ItemId);
                this.phItem.Controls.Add(ad);
            }
            else if (this.TypeOfItem == ItemType.Category)
            {
                string   categoryControlToLoad = "~" + DesktopModuleFolderName + "CategoryControls/CategoryDisplay.ascx";
                Category category = Category.GetCategory(this.ItemId, this.PortalId);
                if (category == null)
                {
                    throw new InvalidOperationException("Category not found");
                }

                var cd = (CategoryDisplay)this.LoadControl(categoryControlToLoad);
                cd.ModuleConfiguration = this.ModuleConfiguration;
                cd.ID           = Path.GetFileNameWithoutExtension(categoryControlToLoad);
                cd.Overrideable = true;
                cd.ShowAll      = true;
                cd.SetItemId(category.ItemId);
                this.phItem.Controls.Add(cd);
            }
            else
            {
                throw new InvalidOperationException("Invalid Item Type");
            }
        }