<?php
/**
* СодеÑÐ¶Ð¸Ñ ÐºÐ»Ð°ÑÑ BreadCrumbs
*
* @package energine
* @author dr.Pavka
* @copyright ColoCall 2006
* @version $Id: BreadCrumbs.class.php,v 1.10 2007/12/17 14:16:14 pavka Exp $
*/
//require_once('core/modules/share/components/DataSet.class.php');
/**
* "ХлебнÑе кÑоÑки"
*
* @package energine
* @subpackage share
* @final
*/
final class BreadCrumbs extends DataSet {
/**
* СпиÑок дополниÑелÑнÑÑ
ÑлеменÑов
* ÐеобÑ
одим Ð´Ð»Ñ Ñого ÑÑÐ¾Ð±Ñ Ð´ÑÑгие компоненÑÑ Ð¼Ð¾Ð³Ð»Ð¸ добавлÑÑÑ Ñ
лебнÑе кÑоÑки
* @var array
* @access private
*/
private $additionalCrumbs = array();
/**
* ÐонÑÑÑÑкÑÐ¾Ñ ÐºÐ»Ð°ÑÑа
*
* @return void
*/
public function __construct($name, $module, Document $document, array $params = null) {
parent::__construct($name, $module, $document, $params);
$this->setType(self::COMPONENT_TYPE_LIST);
}
/**
* ÐоÑколÑÐºÑ Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ðµ пеÑеÑÐ½Ñ Ð¿Ð¾Ð»ÐµÐ¹ невозможно, пÑинÑдиÑелÑно вÑÑÑавлÑем необÑ
одимÑе знаÑениÑ
*
* @return DataDescription
* @access protected
*/
protected function createDataDescription() {
$result = new DataDescription();
$field = new FieldDescription('Id');
$field->setType(FieldDescription::FIELD_TYPE_INT);
$field->addProperty('key', true);
$result->addFieldDescription($field);
$field = new FieldDescription('Name');
$field->setType(FieldDescription::FIELD_TYPE_STRING);
$result->addFieldDescription($field);
$field = new FieldDescription('Segment');
$field->setType(FieldDescription::FIELD_TYPE_STRING);
$result->addFieldDescription($field);
return $result;
}
/**
* ÐеÑеопÑеделеннÑй меÑод загÑÑзки даннÑÑ
*
* @return mixed
* @access protected
*/
protected function loadData() {
$sitemap = Sitemap::getInstance();
$result = array();
$parents = $sitemap->getParents($this->document->getID());
foreach ($parents as $id => $current) {
$result[] = array(
'Id' => $id,
'Name' => $current['Name'],
'Segment' => $current['Segment']
);
}
$docInfo = $sitemap->getDocumentInfo($this->document->getID());
$result[] = array(
'Id' => $this->document->getID(),
'Name' => $docInfo['Name'],
'Segment' => $sitemap->getURLByID($this->document->getID())
);
if (!empty($this->additionalCrumbs)) {
$result = array_merge($result, $this->additionalCrumbs);
}
// добавлÑем инÑоÑмаÑÐ¸Ñ Ð¾ главной ÑÑÑаниÑе в наÑало
$defaultID = $sitemap->getDefault();
if (($this->document->getID() != $defaultID) && (isset($result[0]) && ($result[0]['Id'] != $defaultID))) {
$docInfo = $sitemap->getDocumentInfo($defaultID);
$result = array_push_before(
$result,
array(
array(
'Id' => $defaultID,
'Name' => $docInfo['Name'],
'Segment' => ''//$sitemap->getURLByID($defaultID)
)
),
0
);
}
return $result;
}
/**
* ÐеÑод добавлÑÑÑий Ñ
лебнÑÑ ÐºÑоÑкÑ
* ÐÑли пÑиÑ
одÑÑ Ð¿ÑÑÑÑе паÑамеÑÑÑ, Ñо ÑÑа кÑоÑка не вÑводиÑÑÑ, а пÑедÑдÑÑÐ°Ñ Ñ
Ð»ÐµÐ±Ð½Ð°Ñ ÐºÑоÑка бÑÐ´ÐµÑ ÑÑÑлкой
*
* @param int
* @param string
* @param segment
* @return void
* @access public
*/
public function addCrumb($smapID = '', $smapName = '', $smapSegment = '') {
$this->additionalCrumbs[] = array(
'Id' => $smapID,
'Name' => $smapName,
'Segment' => $smapSegment
);
}
}