Location: PHPKode > projects > Energine > energine-2.2/core2a/modules/share/components/ChildDivisions.class.php
<?php
/**
 * Содержит класс ChildDivisions
 *
 * @package energine
 * @author dr.Pavka
 * @copyright ColoCall 2006
 * @version $Id: ChildDivisions.class.php,v 1.11 2008/01/18 14:50:42 pavka Exp $
 */


//require_once('core/modules/share/components/DataSet.class.php');

/**
 * Класс передназначен для вівода дочерних разделов текущего раздела
 *
 * @package energine
 * @subpackage share
 *
 */
class ChildDivisions extends DataSet  {

    /**
     * Конструктор класса
     *
     * @return void
     */
    public function __construct($name, $module, Document $document,  array $params = null) {
        parent::__construct($name, $module, $document,  $params);
        $this->setType(self::COMPONENT_TYPE_LIST);
        if ($this->getParam('id')) {
        	$this->setParam('active', false);
        	$this->setParam('recordsPerPage', false);
        }
    }

    /**
	 * Добавлен параметр id - идентификатор страницы
	 *
	 * @return int
	 * @access protected
	 */

    protected function defineParams() {
        $result = array_merge(parent::defineParams(),
        array(
        'id'=>false,
        'showFinal' => false,
        'active' => true
        ));
        return $result;
    }

    /**
     * Устанавливаем перечень полей
     *
     * @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);

        $field = new FieldDescription('DescriptionRtf');
        $field->setType(FieldDescription::FIELD_TYPE_TEXT);
        $result->addFieldDescription($field);

        return $result;
     }
    /**
	 * Переопределенный метод загрузки данных
	 *
	 * @return mixed
	 * @access protected
	 */

    protected function loadData() {
        $sitemap = Sitemap::getInstance();
        $this->setTitle($this->translate('TXT_CHILD_DIVISIONS'));

        if (!$this->getParam('id')) {
            $id = $this->document->getID();
        }
        else {
            $id = $this->getParam('id');
        }

        $data = $sitemap->getChilds($id);
        $data = (empty($data))?false:$data;
        if(is_array($data)) {
            if ($this->getParam('recordsPerPage')) {
                if ($this->pager->getCurrentPage()>1) {
                    $this->document->componentManager->getComponentByName('breadCrumbs')->addCrumb();
                }
                $this->pager->setRecordsCount(sizeof($data));
                $limit = $this->pager->getLimit();
                $data = array_slice($data, $limit[0], $limit[1], true);
            }
            foreach ($data as $id => $current) {
                $data[$id] = array(
                'Id' => $id,
                'Segment' => $current['Segment'],
                'Name' => $current['Name'],
                'DescriptionRtf' => $current['DescriptionRtf']
                );
            }

        }

        return $data;
    }
}
Return current item: Energine