<?php
/**
 * @var $this SportController
 * @var $albums Album[]
 */
/** @var $items Album[] */
$byYear = array();
foreach ($albums as $album) {

    $y = (int)substr($album->date, 0, 4);
    if (!isset($byYear[$y])) $byYear[$y] = array();
    $byYear[$y][] = $album;
}
?>
<?php $this->renderPartial('//snippets/headerGallery'); ?>

<div class="wrapper content-wrapper">
    <div class="col-wrapper">
        <div class="col2 aside-no-title">
            <?php $this->renderPartial('//snippets/bajaBanner');?>
            <?php $this->renderPartial('//sport/_sidebar');?>
        </div>
        <div class="col7">
            <h1><?php echo CHtml::encode($this->pageName);?></h1>
            <?php foreach ($byYear as $year => $items): ?>
            <h2><?php echo $year?> год</h2>

            <div class="sport-gallery-list">
                <?php foreach ($items as $item): ?>
                <div class="sport-gallery-item">
                    <div class="sport-gallery-preview">
                        <?php echo CHtml::link(CHtml::image($item->imageBehavior->getFileUrl('preview')), array('albumsSection/album', 'link' => $item->link))?>

                    </div>
                    <div class="sport-gallery-name">
                        <p>
                            <?php echo CHtml::link($item->i18n->name, array('albumsSection/album', 'link' => $item->link))?>
                            <br/>
                            <?php
                            $photoCount = $item->photoGalleryBehavior->getGalleryPhotoCount();
                            $videoCount = $item->videoGalleryBehavior->getGalleryPhotoCount();
                            echo Yii::t('site', '{n} фотографий|{n} фотографии|{n} фотографии|{n} фотографии', $photoCount), ', ';
                            echo Yii::t('site', '{n} видео|{n} видео|{n} видео|{n} видео', $videoCount)
                            ?></p>
                    </div>
                </div>
                <?php endforeach;?>
            </div>
            <?php endforeach; ?>
        </div>
        <div class="col3">
            <?php $this->renderPartial('//sport/_nearestEvents');?>
            <?php $this->renderPartial('//sport/_mediaFeed');?>
            <p class="section-title">
                <?php
                echo Yii::t('site', 'Актуальные новости автоспорта');
                echo CHtml::link('', array('site/feed'), array('class' => 'rss-icon'));
                ?></p>
            <?php foreach (SportController::getLatestNews() as $item): ?>
            <div class="news-item">
                <div class="preview-img">
                    <?php echo CHtml::link(CHtml::image($item->imageBehavior->getFileUrl('preview')), array('news/view', 'link' => $item->link, 'node_id' => Node::idByDataId('newsRoot', $item->newsCategory->news_root_id)))?>
                </div>
                <div class="news-content">
                    <p>
                        <?php
                        $timestamp = CDateTimeParser::parse($item->date, 'yyyy-MM-dd hh:mm:ss');
                        echo CHtml::link($item->i18n->name, array('news/view', 'link' => $item->link, 'node_id' => Node::idByDataId('newsRoot', $item->newsCategory->news_root_id)));
                        echo '<br/> — ';
                        echo Yii::app()->getDateFormatter()->format('d MMMM yyyy', $timestamp);
                        ?>
                    </p>
                </div>
            </div>
            <?php endforeach;?>

            <span><?php
                /** @var $cat NewsCategory */
                $cat = NewsCategory::model()->findByPk(2);
                echo CHtml::link(Yii::t('site', 'Архив новостей'), array('news/category', 'link' => $cat->link, 'node_id' => Node::idByDataId('newsRoot', $cat->news_root_id)));
                ?>»</span>
        </div>
    </div>
</div>
