1
leonidou
How to create dynamic entries of menus and submenus in the main menu?
  • 2008/1/7 21:40

  • leonidou

  • Just popping in

  • Posts: 7

  • Since: 2007/11/21


Hi all,

Does anybody knows how to create dynamic entries of menus and submenus in the main menu? I will explain more:
Suppose we have a module with the following entries in the xoops_version.php file with the following lines:

// Menu
$modversion['hasMain'] = 1;
$modversion['sub'][1]['name'] = "Categoty 1";
$modversion['sub'][1]['url'] = "categoty.php?catid=1";
$modversion['sub'][2]['name'] = "Category 2";
$modversion['sub'][2]['url'] = "category.php?catid=2";

Can I replace it with code generated dynamicly so I get the the submenus from a DB table?

Can I have 2,3 or more levels (sub levels) or categories?

Thanks for your time!


2
trabis
Re: How to create dynamic entries of menus and submenus in the main menu?
  • 2008/1/8 1:10

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Yes you can!

Here is one example from the 'news' module:
/**
 * This part inserts the selected topics as sub items in the XOOPS main menu
 */
$module_handler =& xoops_gethandler('module');
$module =& $module_handler->getByDirname($modversion['dirname']);
if (
$module) {
    global 
$xoopsUser;
    if (
is_object($xoopsUser)) {
        
$groups $xoopsUser->getGroups();
    } else {
        
$groups XOOPS_GROUP_ANONYMOUS;
    }
    
$gperm_handler =& xoops_gethandler('groupperm');
    if (
$gperm_handler->checkRight("news_submit"0$groups$module->getVar('mid'))) {
          
$cansubmit 1;
    }
}

// ************
$i 1;
global 
$xoopsDB$xoopsUser$xoopsConfig$xoopsModule$xoopsModuleConfig;
// We try to "win" some time
// 1)  Check to see it the module is the current module
if (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $modversion['dirname'] && $xoopsModule->getVar('isactive')) {
    
// 2) If there's no topics to display as sub menus we can go on
    
if(!isset($_SESSION['items_count']) || $_SESSION['items_count']== -1) {
        
$sql "SELECT COUNT(*) as cpt FROM ".$xoopsDB->prefix("topics")." WHERE menu=1";
        
$result $xoopsDB->query($sql);
        list(
$count) = $xoopsDB->fetchRow($result);
        
$_SESSION['items_count'] = $count;
    } else {
        
$count $_SESSION['items_count'];
    }
    if(
$count>0) {
        include_once 
XOOPS_ROOT_PATH.'/class/tree.php';
        include_once 
XOOPS_ROOT_PATH.'/modules/news/class/class.newstopic.php';
        include_once 
XOOPS_ROOT_PATH.'/modules/news/include/functions.php';
        
$xt = new NewsTopic();
        
$allTopics $xt->getAllTopics(news_getmoduleoption('restrictindex'));
        
$topic_tree = new XoopsObjectTree($allTopics'topic_id''topic_pid');
        
$topics_arr $topic_tree->getAllChild(0);
        if (
$module) {
            foreach (
$topics_arr as $onetopic) {
                if (
$gperm_handler->checkRight('news_view'$onetopic->topic_id(), $groups$xoopsModule->getVar('mid')) && $onetopic->menu()) {
                    
$modversion['sub'][$i]['name'] = $onetopic->topic_title();
                      
$modversion['sub'][$i]['url'] = "index.php?storytopic=" $onetopic->topic_id();
                   }
                   
$i++;
               }
        }
        unset(
$xt);
    }
}


As for sub categories I don´t think it is possible, but using the same logic above you could show them in the main menu when you are viewing the parent category.

Hum, let me see, if that info can show dynamicaly without having to update the module then...
Then maybe it has a direct relation just with the main block and with nothing else.
If this is true then you can change your main block to fecth an extra array containing the sub categories menus.


$modversion['sub'][$i]['extra'] = array containing name and url for each subcat!!!!

3
leonidou
Re: How to create dynamic entries of menus and submenus in the main menu?
  • 2008/1/10 7:36

  • leonidou

  • Just popping in

  • Posts: 7

  • Since: 2007/11/21


Unfortunatly
$modversion['sub'][$i]['extra'] did not worked with me so I can not create sub categories. Any other ideas?

Thanks for your support trabis. Really appreciate.

4
trabis
Re: How to create dynamic entries of menus and submenus in the main menu?
  • 2008/1/10 13:42

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


As I said you would have to do some code changes to make that ideia work.

If you could share more information about the module and what you want to do maybe I could help you better.

:)

5
Will_H
Re: How to create dynamic entries of menus and submenus in the main menu?
  • 2008/1/10 13:48

  • Will_H

  • Friend of XOOPS

  • Posts: 1786

  • Since: 2004/10/10


xoops menu system is very limited which is why multimenu was born.

6
trabis
Re: How to create dynamic entries of menus and submenus in the main menu?
  • 2008/1/10 14:06

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Multimenu?

Multimenu is static. I don´t see how would it help here!

7
Will_H
Re: How to create dynamic entries of menus and submenus in the main menu?
  • 2008/1/10 14:39

  • Will_H

  • Friend of XOOPS

  • Posts: 1786

  • Since: 2004/10/10


Thats true, but if the guy is trying to build a dynamic menu, that is three deep or greater, I dont see how you intend to help. I mean you get two levels to work with in xoops. anything deeper is static. period.

Wherein, with multimenu he could create rich hierarchy's of menu's that are really effortless to modify.

8
trabis
Re: How to create dynamic entries of menus and submenus in the main menu?
  • 2008/1/10 19:55

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


No, not period.
Module has Categories and they have subcategories. Thats 3 level and 2 of them are dynamic. The block as it is only fetch the categories. Let´s make it fetch the subcategories!! It can´t be that hard :)

9
leonidou
Re: How to create dynamic entries of menus and submenus in the main menu?
  • 2008/1/12 19:06

  • leonidou

  • Just popping in

  • Posts: 7

  • Since: 2007/11/21


Hi friend,

I will include more info in case you still want to help me. I have a categories table (in DB), each category has a category_id as primary key and a categoyy_parent as a foreigh key pointing to the parent category. In theory level can be infinite. I need to make a block which will host a dynamic tree composed of the categories in order to navigate in the categories. This block has to be in the main menu section.

Thanks all.

Login

Who's Online

292 user(s) are online (216 user(s) are browsing Support Forums)


Members: 0


Guests: 292


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits