I have modified tree module so now it can display
all categories and subcategories.
I have created a new directory (modules/mod_phocadownload_tree/helpers) and inside it a file named "mod_phocadownload_tree.php" with this content:
Code: Select all
<?php
defined('_JEXEC') or die();
class PhocaDownloadTree
{
function getCats(){
$db =& JFactory::getDBO();
$query = "SELECT * FROM #__phocadownload_categories ORDER BY parent_id";
$db->setQuery($query);
$cats = $db->loadObjectList();
return $cats;
}
function getSubCats( $pid ) {
$db =& JFactory::getDBO();
$query = "SELECT * FROM #__phocadownload_categories WHERE parent_id = '".$pid."' ORDER BY id";
$subCats = $db->loadObjectList();
return $subCats;
}
}
?>
and have modified a entrypoint file "mod_phocadownload_tree.php" in "modules/mod_phocadownload_tree/" with:
Code: Select all
<?php
/*
* @package Joomla 1.5
*
* modified version for Joomla 1.6 by webbati
*
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*
* @module Phoca - Phoca Module
* @copyright Copyright (C) Jan Pavelka www.phoca.cz
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @based on javascript: dTree 2.05 www.destroydrop.com/javascript/tree/
* @copyright (c) 2002-2003 Geir Landrö
*
*/
defined('_JEXEC') or die('Restricted access');// no direct access
if (!JComponentHelper::isEnabled('com_phocadownload', true)) {
return JError::raiseError(JText::_('Phoca Download Error'), JText::_('Phoca Download is not installed on your system'));
}
require_once( JPATH_BASE.DS.'components'.DS.'com_phocadownload'.DS.'helpers'.DS.'phocadownload.php' );
require_once( JPATH_BASE.DS.'components'.DS.'com_phocadownload'.DS.'helpers'.DS.'route.php' );
require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_phocadownload'.DS.'helpers'.DS.'phocadownload.php' );
require_once( JPATH_BASE.DS.'modules'.DS.'mod_phocadownload_tree'.DS.'helpers'.DS.'mod_phocadownload_tree.php' );
$user = &JFactory::getUser();
$db = &JFactory::getDBO();
$menu = &JSite::getMenu();
$document = &JFactory::getDocument();
// Start CSS
$document->addStyleSheet(JURI::base(true).'/modules/mod_phocadownload_tree/assets/dtree.css');
$document->addScript( JURI::base(true) . '/modules/mod_phocadownload_tree/assets/dtree.js' );
$imgPath = JURI::base(true) . '/modules/mod_phocadownload_tree/assets/';
//Unique id for more modules
$treeId = "d".uniqid( "tree_" );
// Current category info
$id = JRequest::getVar( 'id', 0, '', 'int' );
$option = JRequest::getVar( 'option', 0, '', 'string' );
$view = JRequest::getVar( 'view', 0, '', 'string' );
$categorie = new PhocaDownloadTree;
// Params
$hideC = $params->get( 'hide_categories', '');
$hideS = $params->get( 'hide_sections', '' );
$aid = $user->get('aid', 0);
$miecats = $categorie->getCats();
$tree = array();
$newIdSec = array();
$newIdCat = array();
$userAID = $user->get('aid', 0);
$userID = $user->get('id', 0);
foreach ($miecats as $miecat){
if ($miecat->parent_id == '0'){
$link = JRoute::_(PhocaDownloadHelperRoute::getCategoryRoute($miecat->id, $miecat->alias));
$tree[] = $treeId.'.add('.$miecat->id.', 0 ,\''.addslashes($miecat->title).'\',\''.$link.'\');'."\n";
$newIdSec[$miecat->id] = $miecat->id;
$subcats = $categorie->getSubCats($miecat->id);
foreach ($subcats as $subcat){
if ($subcat->parent_id != '0'){
$link = JRoute::_(PhocaDownloadHelperRoute::getCategoryRoute($subcat->id, $subcat->alias, $subcat->id));
$tree[] = $treeId.'.add('.$subcat->id.','.$subcat->parent_id .',\''.addslashes($subcat->title).'\',\''.$link.'\');'."\n";
$newIdCat[$subcat->id] = $subcat->id;
} // fine if subcat
} // fine foreach subcats
} // fine if
} // fine foreach miecats
// We added unique numbers to categories and sections (because section can have the same id as category we must to add other ids)
if ( $option == 'com_phocadownload' && $view == 'categories' ) {
if (isset($newIdSec[$id])) {
$catAndSecId = (int)$newIdSec[$id];
} else {
$catAndSecId = 0;
}
} else if ( $option == 'com_phocadownload' && $view == 'category' ) {
if (isset($newIdCat[$id])) {
$catAndSecId = (int)$newIdCat[$id];
} else {
$catAndSecId = 0;
}
} else {
$catAndSecId = 0;
}
// Categories (Head)
$linkSections = JRoute::_(PhocaDownloadHelperRoute::getCategoriesRoute());
// Create javascript code
$jsTree = '';
foreach($tree as $key => $value) {
$jsTree .= $value ;
}
// Output
$output ='<div style="text-align:left;">';
$output.='<div class="dtree">';
$output.='<script type="text/javascript">'."\n";
$output.='<!--'."\n";
$output.=''."\n";
$output.=''.$treeId.' = new dTree2568(\''.$treeId.'\', \''.$imgPath.'\');'."\n";
$output.=''."\n";
$output.=''.$treeId.'.add(0,-1,\''.JText::_( 'Download' ).'\',\''.$linkSections.'\');'."\n";
$output.=$jsTree;
$output.=''."\n";
$output.='document.write('.$treeId.');'."\n";
$output.=''.$treeId.'.openTo('. (int) $catAndSecId.',\'true\');'. "\n";
$output.=''."\n";
$output.='//-->'."\n";
$output.='</script>';
$output.='</div></div>';
require(JModuleHelper::getLayoutPath('mod_phocadownload_tree'));
?>
if you prefer to show only the main categories and only the first level look here
http://forum.joomla.it/index.php/topic,126581.0.html where i describe how to do it.
i hope this help you, bye