Location: PHPKode > projects > Energine > energine-2.2/core2a/modules/share/components/NewsFeed.class.php
<?php
/**
 * Содержит класс NewsFeed
 *
 * @package energine
 * @subpackage share
 * @author dr.Pavka
 * @copyright ColoCall 2007
 * @version $Id: NewsFeed.class.php,v 1.11 2008/04/03 11:58:56 pavka Exp $
 */

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

/**
 * Лента новостей
 *
 * @package energine
 * @subpackage share
 */
class NewsFeed extends Feed {
    /**
     * Конструктор класса
     *
     * @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);
        $this->setTableName('share_news');
        $this->setOrder(array('news_date'=>QAL::DESC));
    }

    /**
     * Добавляем поле - флаг указывающий на то - существует ли текст новости
     *
     * @return void
     * @access protected
     */

     protected function main() {
        parent::main();
        $hasTextField = new FieldDescription('has_text');
        $hasTextField->setType(FieldDescription::FIELD_TYPE_BOOL);
        $this->getDataDescription()->addFieldDescription($hasTextField);

        $hasTextField = new Field('has_text');

        foreach ($this->getData()->getFieldByName('news_id') as $id) {
            $hasTextField->addRowData(simplifyDBResult($this->dbh->select($this->getTranslationTableName(), array('news_text_rtf is not null as has_text'), array('news_id'=>$id)), 'has_text', true));
        }

        $this->getData()->addField($hasTextField);
     }

    /**
	 * View
	 *
	 * @return type
	 * @access protected
	 */

    protected function view() {

        $params = $this->getActionParams();
        list($day, $month, $year) = $params;
        $this->setFilter(array('news_date'=>sprintf('%s-%s-%s', $year, $month, $day)));

        $this->setType(self::COMPONENT_TYPE_FORM);
        $this->setDataDescription($this->createDataDescription());
        $this->setBuilder($this->createBuilder());
        $this->createPager();
        $data = $this->createData();
        if ($data instanceof Data) {
            $this->setData($data);
            list($newsTitle) = $data->getFieldByName('news_title')->getData();
            $this->document->componentManager->getComponentByName('breadCrumbs')->addCrumb('', $newsTitle);
        }
        else {
            throw new SystemException('ERR_404', SystemException::ERR_404);
        }
        if ($toolbar = $this->createToolbar()) {
            $this->setToolbar($toolbar);
        }
        foreach ($this->getDataDescription()->getFieldDescriptions() as $fieldDescription) {
            $fieldDescription->setMode(FieldDescription::FIELD_MODE_READ);
        }

    }
}
Return current item: Energine