<?php
/**
 * Модель для таблицы fxstreet_news (удалённая БД newsdb @ mps.bmfn.net)
 *
 * @property int    $id
 * @property string $guid
 * @property string $title
 * @property string $link
 * @property string $image_url
 * @property string $pubDate
 * @property string $description
 * @property string $full_content
 */
class FxstreetNews extends CActiveRecord
{
    /**
     * Использует отдельный коннект 'newsDb', основная БД не затрагивается
     */
    public function getDbConnection()
    {
        return Yii::app()->newsDb;
    }

    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return 'fxstreet_news';
    }

    /**
     * @param int $limit 0 = без ограничения
     * @return FxstreetNews[]
     */
    public static function getAll($limit = 50)
    {
        $criteria = new CDbCriteria();
        $criteria->select = 'id, guid, title, link, image_url, pubDate, description, full_content';
        $criteria->order  = 'pubDate DESC';

        if ($limit > 0) {
            $criteria->limit = $limit;
        }

        return self::model()->findAll($criteria);
    }
}