Menu

#40 recursive category structure

open
nobody
None
5
2013-03-09
2013-03-09
No

Hi Mark,

I want to suggest having a recursive system of categories instead of the current category-subcategory system, so that essentially you can get infinitely many levels of sub-sub-...-subcategories.

This is a bigger change so it may be something for the future, on the other hand if you're restructuring the database now it might be worth thinking about adjusting the database to make this possible in future, that might not be too big a change.

This idea is really inspired by Joomla where version 1.5. had a two-level system of "sections" and "categories" which they changed to enable deeper nesting in v2.5.

The basic idea is that every category can be defined to be a subcategory of one other category ("parent"). So for example, you may have categories

  • 1 animals -> no parent defined
  • 2 mammals -> parent: animals
  • 3 cats -> parent: mammals
  • 4 wild cats -> parent: cats
  • 5 house cats -> parent: cats
  • 6 birds -> parent: animals
  • 7 plants -> not parent defined

which will lead to a structure

animals
- mammals
-- cats
--- wild cats
--- house cats
- birds
plants

In the database, instead of having a separate category and subcategory tables, you just have one table which needs the fields

  • category id: unique identifier
  • parent id: points to the category id of the parent, or NULL if top level cat.
  • name
  • (optionally) level (e.g. 0 for top level, 1 for first subcat, 2 for sub-sub-cats etc.) this isn't strictly necessary but make creating the tree more efficient.

Your subcategory table already has this structure, the only difference is that the existing field CategoryID points to a different table, whereas with recursion it would point to the same table.

The ressource_category would just contain the category ids of the deepest categories. For example, a ressource might be set to e.g. category 4 (wild cats) and 7 (plants), but when somebody lists category 2 (mammals) that would automatically include 3 and 4.

In the category selector, the categories would all just be listed in one list similar to the second one above, and the user choses e.g. "wild cats" and "plants" to set it to 4 and 7.

You also need an admin panel where again all categories are listed, and when you edit a category you can set the parent category there.

As a first step, it might work to change the database structure but leave the category/subcategory selectors as they are, only that the subcategory selector would for the moment just select categories of level 1. On the other hand, there is also a feature request from me to combine the cat/subcat selectors, so that would be addressed automatically.

Cheers
Stephan

Discussion

  • Mark Grimshaw

    Mark Grimshaw - 2013-03-09

    Sounds interesting Stephan,

    I think I will leave this to a later database upgrade (v4.3) as it's a relatively big change and I need to get v4.2.1 out because the usersUserSession database field is overflowing and causing problems. v4.2.1 increases that field's size.

    Regards,

    Mark

    P.S. Did you get an email from me earlier today?

     
    • Stephan Matthiesen

      Yes, leave it to later, no problem.

      I didn't get your email...

      Stephan

       
  • Mark Grimshaw

    Mark Grimshaw - 2013-03-09

    Yep, got another mail server failure. I was asking if you like to be added to the list of beta testers listed within the code
    for the next release, please let me have your affiliation in the same
    format as found under Wikindx|About Wikindx.

    Mark

     

Log in to post a comment.