<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

class breadcrumb_main extends ModuleTools
{
	public function __construct()
	{
		self::_setTpl('default');
		
		$breadcrumb=array();
		
		$cache_key='breadcrumb_'.implode('_', LabCMS::i()->parents);
		if (!$crumbs=TCache::get($cache_key)) {
			$crumbs=Db::i()->select(
				"SELECT path, name as name FROM ?_tree
				WHERE tree_id IN (?a) AND `show`=1
				ORDER BY FIELD(tree_id, ?a)", LabCMS::i()->parents, LabCMS::i()->parents
			);
			TCache::set($crumbs, $cache_key, array('main_tree'));
		}
		
		if ($crumbs) {
			foreach ($crumbs as $crumb) {
				$breadcrumb[]=array(
					'path'=>isset($crumb['path'])?_url(false, false, false, $crumb['path']):'',
					'name'=>isset($crumb['name'])?$crumb['name']:''
				);
			}
		}
		
		if (is_array(LabVars::$breadcrumb) && count(LabVars::$breadcrumb)) {
			foreach (LabVars::$breadcrumb as $val) {
				$breadcrumb[]=array(
								'path'=>isset($val['path'])?$val['path']:'',
								'name'=>isset($val['name'])?$val['name']:'',
								'name_html'=>isset($val['name_html'])?$val['name_html']:'');
			}
		}
		if (count($breadcrumb)>1) self::_assign('breadcrumb', $breadcrumb);
	}
}