Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Changing How Categories Look At The Panel

edited April 2010 in Vanilla 2.0 - 2.8
I have been looking into how to do some slight modifications to the way Categories are listed, basically I want to remove some Categories from being listed. Since I don't think it's a themes modification, I have been looking into applications to no avail.

I am not really sure if I should be looking under Modules or Controllers as I don't think I have found anything relevant. If anybody can point me the direction, ie the file to look at, it would be much appreciated!

Anyway, just another question. When you do a modification to an Application, do you usually copy the files out into a different folder as a new application? I am just wondering what is the best practice as I don't want anything I modified right now to be rewritten in the future upgrades, but I don't think Applications work like the way Themes work. Please advise.

Comments

  • Okay I think I made some progress and was able to pinpoint the relevant files to applications/vanilla/models/class.categorymodel.php and applications/vanilla/views/modules/categories.php

    Now I am just wondering if Applications would be like Themes, where you can have a different copy of the file that get executed, without editing the original file and without copying the entire folder.
  • I'm new to Vanilla so please, anyone, correct me where I'm wrong.

    @jjsee, this is not the best solution. In fact, it's probably really crap.

    Hooks are your friend.

    Hooks are, IMO, the best way to modify the output of the application without changing the application itself (I also don't like changing the app). And no, I don't think creating a copy of the application under a new application will work as you expect.

    Read the hooks link, also check out what plugins can do, create your hooks.php file, and then what you want to do is create a public function called Base_Render_Before. I believe this will target all of your controllers (every page).

    This is the categories module $Sender->Assets['Panel']['CategoriesModule']
    Now, by this point in execution, the Categories module has been converted ToString and is no longer an object.

    How you are going to manipulate that string to remove specific categories will be a pain; sorry, I can't help you there. To remove the CategoriesModule completely, simply unset() that value.

    You might be able to put the string into an XML parser and then searching for specific nodes to remove.
  • @tonyamazing Thanks for the pointer. I was thinking that it would be very easy to just manipulate the SQL query instead, and prevent it from selecting from certain categories. I am not sure if hooks can do that, but I will have a look into it. It would be great to maintain my modifications as separate files so that they won't be overwritten during updates. :)
  • @jjsee no I don't think hooks can do any SQL manipulation;

    I wouldn't have a clue how to do that and keep the files seperate
  • @tonyamazing I found a way to manipulate the data in Themes/views/modules instead via PHP. So it was good to be able to leave everything inside Applications intact. :)
  • @jjsee nice! Care to share? :)
  • @tonyamazing Sure. :) Hopefully my instructions won't get too confusing.

    To change the way Categories are listed at the side bar, copy applications/vanilla/views/modules/categories.php into /themes/views/modules

    You will see a foreach statement in the file:

    foreach ($this->_CategoryData->Result() as $Category) {

    Immediately after this, add this:

    if ($Category->CategoryID != 1) {

    Whereby 1 is the category id number that I would like to exclude. Also, immediately before the closing curly bracket } for the foreach loop, add another closing curly bracket } to close your new if statement.

    If you would like to exclude multiple Categories, you can do it with a few ANDs like this:

    if (($Category->CategoryID != 1) && ($Category->CategoryID != 5)){

    You can play around with this to create a second or third set of listing on the same side menu, with the Categories that you previously excluded by reversing the conditions of the if statement, which is actually what I am doing. :)
  • TimTim Vanilla Staff
    Interesting idea!

    It might be easier to maintain if you followed this line:
    foreach ($this->_CategoryData->Result() as $Category) {

    with something more like this:
    if (in_array($Category->CategoryID,array(1,2,3,etc)) { continue; }
    That way if you want to exclude more than one category, just keep adding CategoryIDs to the array.

    Vanilla Forums COO [GitHub, Twitter, About.me]

  • wondering if this concept can also be applied to all discussions not showing discussions from a particular category. Lets say if I want my All Discussions list to show all discussions except those from category #3? @Tim any thoughts?
  • @Gmantonz Yes you can. The files that you should look into at under applications/vanilla/views/discussions/helper_functions.php and possibly discussions.php too.

    I don't remember if my modifications on discussions.php is relevant or not. :)

  • Correction. discussions.php is the relevant file whereas helper_functions.php is not really relevant.

    This is a sample of my discussions.php (but I think I broke something while changing something just now, so proceed with caution)

    foreach ($this->DiscussionData->Result() as $Discussion) {
    if (($Discussion->CategoryID != 1) || ($this->CategoryID == 1)) {
    $Alt = $Alt == ' Alt' ? '' : ' Alt';
    WriteDiscussion($Discussion, $this, $Session, $Alt);
    }
    }

    However, I thought it was working excellent, until I realize that I have to take into consideration other ways of listing, ie My Discussions, My Bookmarks, My Drafts etc, or the filtered discussion list will not display for those.

    Still trying to find out how I could track how are users viewing the list. Pointers are appreciated. :)
  • Hmm I fixed my problem. So the snippets I pasted are alright to be copied and pasted to your own. :) Take note that "1" is the CategoryID of the particular category that I would like to filter off the main list.
  • great, that does work fantastic @rookie. thanks!
Sign In or Register to comment.