UDT for hierarchical tree of Gallery galleries

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
vilkis

UDT for hierarchical tree of Gallery galleries

Post by vilkis »

Hi,

EDIT: the working example in left sidebar at sventei.lt

The UDT for hierarchical tree of Gallery galleries:

Code: Select all

global $gCms;
$table = cms_db_prefix() . 'module_gallery';
$smarty = & $gCms->GetSmarty();
$db = & $gCms->GetDb();
if (!function_exists('bpti_output_function')) {
function bpti_output_function($node, &$array , $params, $hide = false){
	foreach($node as $k => $v){
		if ($hide == false){
			echo('<li>' . bpti_output_link($v, $params));
		}
		if (isset($array[$v['fileid']])){
			echo('<ul>');
			bpti_output_function($array[$v['fileid']], $array, $params, false);
			unset($array[$v['fileid']]);
			echo('</ul>');
		}
		if ($hide == false){
				echo('</li>');
		}
	}
}
}
if (!function_exists('bpti_output_link')) {
function bpti_output_link($arr, $params){
	$gallery = new CMSModule();
	global $gCms;
	$smarty = & $gCms->GetSmarty();
	$returnid = $smarty->get_template_vars('content_id');
	if (isset($params['targetpage'])){
		$manager =& $gCms->GetHierarchyManager();
		$node =& $manager->sureGetNodeByAlias($params['targetpage']);
		if (isset($node)){
			$targetpage = $node->getID();
			$id = 'cntnt01';
		}
		else{
			$node =& $manager->sureGetNodeById($params['targetpage']);
			if (isset($node)){
				$targetpage = $params['targetpage'];
				$id = 'cntnt01';
			}
		}
	}
	$dir = $arr['filepath'] . '/' . $arr['filename'];
	$prettyurl = 'gallery' . '/' . trim($dir,"/") . '/' .	($params['targetpage']!=''?$targetpage:$returnid);
	$link = $gallery->CreateFrontendLink($id, ($targetpage!=''?$targetpage:$returnid), 'default',
		(!empty($arr['title'])?$arr['title']:trim($arr['filename'],"/")), $params, '', false, false, '', false, $prettyurl);
	echo ($link);
}
}

$sql = 'SELECT fileid,filename,filepath,filedate,fileorder,	galleryid, title FROM ' . $table . ' WHERE active = 1 AND filename LIKE ? ORDER BY  galleryid ASC, fileorder ASC';
$arr = array('%/');
$res = $db->Execute($sql, $arr);
if ($res){
	while ($arr = $res->FetchRow()){ 
		if (!isset($tree[$arr['galleryid']][$arr['fileorder']]))
			$tree[$arr['galleryid']][$arr['fileorder']] = $arr;
		else
			$tree[$arr['galleryid']][$arr['fileid']] = $arr;
	} 

	foreach($tree as $k => $v){
		bpti_output_function($v, $tree, $params, true);
	}
}

if you name it gallerytree then you can call it in page or template

Code: Select all

{gallerytree targetpage='ALIAS_OF_PAGE'}
vilkis
Last edited by vilkis on Sun Jul 25, 2010 5:18 pm, edited 1 time in total.
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am

Re: UDT for hierarchical tree of Gallery galleries

Post by nicmare »

nice, thanks
Post Reply

Return to “Tips and Tricks”