Tree Module: Children should inherit parent ItemId

Phoca Gallery modules - modules for Phoca Gallery extension
birdie
Phoca Member
Phoca Member
Posts: 22
Joined: 16 Aug 2008, 12:31

Tree Module: Children should inherit parent ItemId

Post 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);
}
[...]
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48386
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Tree Module: Children should inherit parent ItemId

Post 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
If you find Phoca extensions useful, please support the project
birdie
Phoca Member
Phoca Member
Posts: 22
Joined: 16 Aug 2008, 12:31

Re: Tree Module: Children should inherit parent ItemId

Post 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
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48386
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Tree Module: Children should inherit parent ItemId

Post by Jan »

ok, thanks for the info

Jan
If you find Phoca extensions useful, please support the project
ggtoby
Phoca Newbie
Phoca Newbie
Posts: 3
Joined: 08 Nov 2008, 17:55
Contact:

Re: Tree Module: Children should inherit parent ItemId

Post by ggtoby »

thanks a lot! for the solution as well as the info
tclark
Phoca Newbie
Phoca Newbie
Posts: 3
Joined: 11 Dec 2008, 01:06

Re: Tree Module: Children should inherit parent ItemId

Post 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.
Post Reply