SportController.php 2.14 KB
<?php

class SportController extends NodeSiteController
{
    /** @var SportRoot */
    public $sportRoot;

    public function init()
    {
        parent::init();

        $this->sportRoot = SportRoot::model()->with('i18n')->findByPk($this->getNode()->data_id);
        $this->headerGalleryId = $this->sportRoot->header_gallery_id;
    }

    public function actionIndex()
    {
        $this->render('index', array(
            'show_silk_way' => $this->sportRoot->show_silk_way,

            'study_title' => $this->sportRoot->i18n->study_title,
            'study_image' => $this->sportRoot->i18n->study_image,
            'study_content' => $this->sportRoot->i18n->study_content,
            'study_button' => $this->sportRoot->i18n->study_button,

            'awards_content' => $this->sportRoot->i18n->awards_content,
            'awards_button' => $this->sportRoot->i18n->study_button,

            'champions_content' => $this->sportRoot->i18n->champions_content,

            'qualifications_content' => $this->sportRoot->i18n->qualifications_content,

            'study_link' => $this->sportRoot->i18n->study_link,
            'awards_link' => $this->sportRoot->i18n->awards_link,
            'team_link' => $this->sportRoot->i18n->team_link,
        ));
    }

    /**
     * @param int $limit
     * @return News[]
     */
    public static function getLatestNews($limit = 3)
    {
        return News::model()->with('i18n')->findAll(array(
            'order' => 'date desc',
            'condition' => 'not t.hidden and t.news_category_id=2',
            'limit' => $limit,
        ));
    }

    /**
     * @param string $country
     * @return SportEvent[]
     */
    public static function getNearestEvents($country = 'all')
    {
        $criteria = new CDbCriteria(array(
            'order' => 'start_date asc',
            'condition' => 'end_date>=:today',
            'limit' => 3,
            'params' => array(
                ':today' => date('Y-m-d'),
            )
        ));
        if ($country != 'all') {
            $criteria->addCondition('country_id = ' . $country);
        }
        return SportEvent::model()->with('i18n')->findAll($criteria);
    }

}