energine
[ class tree: energine ] [ index: energine ] [ all elements ]

Source for file BreadCrumbs.class.php

Documentation is available at BreadCrumbs.class.php

  1. <?php
  2. /**
  3.  * Содержит класс BreadCrumbs
  4.  *
  5.  * @package energine
  6.  * @subpackage share
  7.  * @author dr.Pavka
  8.  * @copyright Energine 2006
  9.  * @version $Id$
  10.  */
  11.  
  12. //require_once('core/modules/share/components/DataSet.class.php');
  13.  
  14. /**
  15.  * "Хлебные крошки"
  16.  *
  17.  * @package energine
  18.  * @subpackage share
  19.  * @author dr.Pavka
  20.  * @final
  21.  */
  22. final class BreadCrumbs extends DataSet {
  23.     /**
  24.      * Список дополнительных элементов
  25.      * Необходим для того чтобы другие компоненты могли добавлять хлебные крошки
  26.      * @var array 
  27.      * @access private
  28.      */
  29.     private $additionalCrumbs = array();
  30.  
  31.     /**
  32.      * Конструктор класса
  33.      *
  34.      * @return void 
  35.      */
  36.     public function __construct($name$moduleDocument $document,  array $params null{
  37.         parent::__construct($name$module$document,  $params);
  38.         $this->setType(self::COMPONENT_TYPE_LIST);
  39.     }
  40.  
  41.     /**
  42.      * Поскольку изменение перечня полей невозможно, принудительно выставляем необходимые значения
  43.      *
  44.      * @return DataDescription 
  45.      * @access protected
  46.      */
  47.  
  48.     protected function createDataDescription({
  49.         $result new DataDescription();
  50.         $field new FieldDescription('Id');
  51.         $field->setType(FieldDescription::FIELD_TYPE_INT);
  52.         $field->setProperty('key'true);
  53.         $result->addFieldDescription($field);
  54.  
  55.         $field new FieldDescription('Name');
  56.         $field->setType(FieldDescription::FIELD_TYPE_STRING);
  57.         $result->addFieldDescription($field);
  58.  
  59.         $field new FieldDescription('Segment');
  60.         $field->setType(FieldDescription::FIELD_TYPE_STRING);
  61.         $result->addFieldDescription($field);
  62.  
  63.         $field new FieldDescription('Title');
  64.         $field->setType(FieldDescription::FIELD_TYPE_STRING);
  65.         $result->addFieldDescription($field);
  66.  
  67.         return $result;
  68.     }
  69.     /**
  70.      * Переопределенный метод загрузки данных
  71.      *
  72.      * @return mixed 
  73.      * @access protected
  74.      */
  75.     protected function loadData({
  76.         $sitemap Sitemap::getInstance();
  77.         $result array();
  78.         $parents $sitemap->getParents($this->document->getID());
  79.         foreach ($parents as $id => $current{
  80.             $result[array(
  81.             'Id' => $id,
  82.             'Name' => $current['Name'],
  83.             'Segment' => $current['Segment'],
  84.             'Title' => $current['HtmlTitle'],
  85.             );
  86.         }
  87.         $docInfo $sitemap->getDocumentInfo($this->document->getID());
  88.         $result[array(
  89.         'Id' => $this->document->getID(),
  90.         'Name' => $docInfo['Name'],
  91.         'Segment' => $sitemap->getURLByID($this->document->getID()),
  92.         'Title' => $docInfo['HtmlTitle']
  93.         );
  94.         if (!empty($this->additionalCrumbs)) {
  95.             $result array_merge($result$this->additionalCrumbs);
  96.         }
  97.  
  98.  
  99.         // добавляем информацию о главной странице в начало
  100.         $defaultID $sitemap->getDefault();
  101.         if (($this->document->getID(!= $defaultID&& (isset($result[0]&& ($result[0]['Id'!= $defaultID))) {
  102.             $docInfo $sitemap->getDocumentInfo($defaultID);
  103.             $result array_push_before(
  104.             $result,
  105.             array(
  106.             array(
  107.             'Id' => $defaultID,
  108.             'Name' => $docInfo['Name'],
  109.             'Segment' => '',
  110.             'Title' => $docInfo['HtmlTitle']
  111.             )
  112.             ),
  113.             0
  114.             );
  115.         }
  116.  
  117.         return $result;
  118.     }
  119.  
  120.     /**
  121.       * Метод добавляющий хлебную крошку
  122.       * Если приходят пустые параметры, то эта крошка не выводится, а предыдущая хлебная крошка будет ссылкой
  123.       *
  124.       * @param int 
  125.       * @param string 
  126.       * @param segment 
  127.       * @return void 
  128.       * @access public
  129.       */
  130.  
  131.     public function addCrumb($smapID ''$smapName ''$smapSegment ''{
  132.         $this->additionalCrumbs[array(
  133.         'Id' => $smapID,
  134.         'Name' => $smapName,
  135.         'Segment' => $smapSegment
  136.         );
  137.     }
  138. }
В создании документации нам помог: phpDocumentor