2
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!!!!