Tree Module: Children should inherit parent ItemId
Posted: 03 Sep 2008, 21:42
Hi Jan,
In Phoca Gallery Tree Module 1.8.8,
IF you have (one or more) menu link to a category, AND this category has subcategories (maybe nested), AND if you click on a subcategory in tree,
THEN this subcategory is shown with ItemId=0.
As this was not what I wanted, I changed the code in file mod_phocagallery_tree.php.
Now, children in the tree inherit their parent's ItemId, and all is fine!
This is what I changed, hope that helps (see my comments with SV):
In Phoca Gallery Tree Module 1.8.8,
IF you have (one or more) menu link to a category, AND this category has subcategories (maybe nested), AND if you click on a subcategory in tree,
THEN this subcategory is shown with ItemId=0.
As this was not what I wanted, I changed the code in file mod_phocagallery_tree.php.
Now, children in the tree inherit their parent's ItemId, and all is fine!
This is what I changed, hope that helps (see my comments with SV):
Code: Select all
[...]
// Categories tree
$tree = array();
$text = '';
$parentItemId = 0; /* Changed: SV -- Children in tree derive last known parent ItemId */
$tree = categoryTree( $categories, $tree, 0, $text, $treeId, $parentItemId );
// Create category tree
function categoryTree( $data, $tree, $id=0, $text='', $treeId, &$parentItemId=0 )
{
foreach ( $data as $value )
{
if ($value->parentid == $id)
{
$saveItemId = $parentItemId; /* Added: SV */
$link = getLink ( $value->id, $parentItemId );
$showText = $text . ''.$treeId.'.add('.$value->id.','.$value->parentid.',\''.addslashes($value->text).'\',\''.$link.'\');'."\n";
$tree[$value->id] = $showText;
$tree = categoryTree($data, $tree, $value->id, '', $treeId, $parentItemId);
$parentItemId = $saveItemId; /* Added: SV */
}
}
return($tree);
}
// Create link (set Itemid)
function getLink( $id, &$parentItemId ) /* Added $parentItemId logic: SV */
{
// Set Itemid id, exists this link in Menu?
$menu = &JSite::getMenu();
$itemsCategory = $menu->getItems('link', 'index.php?option=com_phocagallery&view=category&id='.(int) $id );
$itemsCategories= $menu->getItems('link', 'index.php?option=com_phocagallery&view=categories');
if(isset($itemsCategory[0])) {
$itemId = $itemsCategory[0]->id;
$alias = $itemsCategory[0]->alias;
} else if(isset($itemsCategories[0])) {
$itemId = $itemsCategories[0]->id;
$alias = '';
} else {
$itemId = $parentItemId; /* Changed: SV -- was: 0 */
$alias = '';
}
$parentItemId = $itemId; /* Added: SV */
if ($alias != '') {
$catid_slug = $id . ':' . $alias;
} else {
$db =& JFactory::getDBO();
$query = 'SELECT c.alias'.
' FROM #__phocagallery_categories AS c' .
' WHERE c.id = '. (int)$id;
$db->setQuery( $query );
$catid_alias = $db->loadObject();
if (isset($catid_alias->alias) && $catid_alias->alias != '') {
$catid_slug = (int)$id . ':'.$catid_alias->alias;
} else {
$catid_slug = (int)$id;
}
}
// Category
$link = JRoute::_('index.php?option=com_phocagallery&view=category&id='. $catid_slug .'&Itemid='.$itemId);
return ($link);
}
[...]