Location: PHPKode > projects > Energine > energine-2.2/core2a/modules/share/components/TagList.class.php
<?php
/**
 * Содержит класс TagLibrary
 *
 * @package energine
 * @subpackage share
 * @author dr.Pavka
 * @copyright ColoCall 2007
 * @version $Id: TagList.class.php,v 1.4 2007/12/17 14:16:14 pavka Exp $
 */

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

/**
 * Компонент реализующий работу с тегами
 *
 * @package energine
 * @subpackage share
 */
class TagList extends DataSet {
    /**
     * Конструктор класса
     *
     * @param string $name
     * @param string $module
     * @param Document $document
     * @param array $params
     * @access public
     */
    public function __construct($name, $module, Document $document, array $params = null) {
        parent::__construct($name, $module, $document, $params);
    }

    /**
     * Добавлены:
     * Параметр current
     *
     * @return array
     * @access protected
     */
    protected function defineParams() {
        return array_merge(
        parent::defineParams(),
        array(
        'current' => true
        )
        );
    }

    /**
     * Создаем Описание данных
     *
     * @return DataDescription
     * @access protected
     */

    protected function createDataDescription() {
        $result = new DataDescription();
        $tagField = new FieldDescription('tag_name');
        $tagField->setType(FieldDescription::FIELD_TYPE_STRING);
        $result->addFieldDescription($tagField);

        $smapNameField = new FieldDescription('smap_name');
        $smapNameField->setType(FieldDescription::FIELD_TYPE_STRING);
        $result->addFieldDescription($smapNameField);

        $smapURLField = new FieldDescription('smap_url');
        $smapURLField->setType(FieldDescription::FIELD_TYPE_STRING);
        $result->addFieldDescription($smapURLField);

        return $result;
    }

    /**
     * Загружаем данные
     *
     * @return mixed
     * @access protected
     */

    protected function loadData() {
        $result = false;

        $condition = '';

        if ($this->getParam('current')) {
            $condition = 'AND map.tag_id in (SELECT tag_id From share_tag_map WHERE smap_id = '.$this->document->getID().') '.
            'AND smap_id != '. $this->document->getID().' ';
        }

        $request = 'SELECT tag_name, smap_id '.
            'FROM `share_tags` tag '.
            'LEFT JOIN share_tag_map map ON map.tag_id=tag.tag_id '.
            'WHERE smap_id is not null '.
            $condition.
            'ORDER by tag_name DESC';

        $res = $this->dbh->selectRequest($request);
        if (is_array($res)) {
            $sitemap = Sitemap::getInstance();
            //использован foreach вместо array_map потому что нужно удалять елементы массива
            foreach ($res as $data) {
                if ($sitemap->getDocumentRights($data['smap_id']) != ACCESS_NONE) {
                	$pageInfo = $sitemap->getDocumentInfo($data['smap_id']);
                    $result[] = array(
                        'smap_url' => $sitemap->getURLByID($data['smap_id']),
                        'smap_name' => $pageInfo['Name'],
                        'tag_name' => $data['tag_name']
                    );
                }
            }
        }

        return $result;
    }
}
Return current item: Energine