Page 1 of 1

Tree Module: Children should inherit parent ItemId

Posted: 03 Sep 2008, 21:42
by birdie
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! :P

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);
}
[...]

Re: Tree Module: Children should inherit parent ItemId

Posted: 04 Sep 2008, 18:51
by Jan
Hi, thank you for this solution, I will take a look at it for the next version (I didn't get itemid=0, can you give me some example where this can happen) I have created categories and subcategories and every subcategories got Itemid from (categories menu link) or from menu link which links direct to this category)

Thank you, Jan

Re: Tree Module: Children should inherit parent ItemId

Posted: 05 Sep 2008, 10:15
by birdie
Hi Jan,

OK, I forgot one condition - here it is:

IF you have (one or more) menu link to a category (let's name it "parent category"),
AND this category has subcategories (maybe nested),
AND these subcategories do not have a menu link in Joomla,
AND if you click on a such a subcategory in tree,
THEN this subcategory is shown with ItemId=0.

I needed these subcategories to have the same ItemId as their respective parent category. That's what the code change does. Hope that helps.

Greetings, and thanks for this great component!
birdie

Re: Tree Module: Children should inherit parent ItemId

Posted: 05 Sep 2008, 21:08
by Jan
ok, thanks for the info

Jan

Re: Tree Module: Children should inherit parent ItemId

Posted: 08 Nov 2008, 18:40
by ggtoby
thanks a lot! for the solution as well as the info

Re: Tree Module: Children should inherit parent ItemId

Posted: 11 Dec 2008, 01:40
by tclark
I was having the same problem with Phoca Gallery Tree Module v2.1.0, the code changes suggested by birdie fixed it in this version as well.
Thanks alot.