help.axcms.net Axinom Logo

Adding the Possibility to Classify Articles

Classification is one of the most important features in AxCMS.net. Learn how to enable classification for articles using CategoryButton.

Classification Basics

Every standard object in AxCMS.net is classifiable. We want of course that our custom article object is also classifiable.

The first step would be to implement the IClassifiable interface consisting of an AxID and the ElementType. This we already did in the first article of this tutorial. Now we need a GUI element which allows selecting categories and attaching these to our article. Such an element already exists: CategoryButton. 

Additionally, it is possible to classify multiple articles at the same time using ClassifyActivity. This is described in Adding Activites.

Using ClassifyButton

If we need to attach categories to our object and show the attached categories on the detail page we can implement the CategoryButton.

First, we need to register the CategoryButton control on our detail page:

<%@ Register TagPrefix="AxCMS" TagName="CategoryButton" Src="../admin/categories/CategoryButton.ascx" %>

Now we can put the control in any panel we want:

<AxCMS:CategoryButton id="_attributesButton" HeaderText="lbl_article_assignedAttributes" Text="btn_article_assignAttributes" runat="server" />

To use the CategoryButton we need to initialize all control properties. This can be done in the LoadProcess method:

01 
02 
03 
04 
05 
06 
07 
08 
09 
10 
11 
12 
protected override void LoadProcess()
{
    //Init Category button
    _attributesButton.FirstEditableLevel = 3;
    _attributesButton.ElementID = this.AxID;
    _attributesButton.Key = "Attributes";
    _attributesButton.Direction = DirectionMode.Both;
    _attributesButton.CategoryPageCall.ID = "_attributesPageCall";
    _attributesButton.SubTreeID = 6;
    _attributesButton.ElementTypeID = (int)ECommerceElementType.Article;
    base.LoadProcess();
}

We also need to create a session for the CategoryButton and assign the article object to it:









protected override void BindObject()
{
    base.BindObject();
    if (IsPostBack)
    {
    _attributesButton.CreateSession();
    _attributesButton.AssignObject(GetObject());
    }
}

Now we need to classify the selected categories to the article, so we will add some code to SaveObject method:



MessageCollection warningList = new MessageCollection();
_attributesButton.SavePermittedCategories((int)this.GetObject().ID, warningList, this.User);
this.AddMessages(warningList);

All this code will allow the CategoryButton to work, to classify the selected categories, and to show error messages when failures occur.

 


Next article: Customizing the Top Menu