<?php

class AlbumsSectionController extends NodeSectionController
{
    /** @var SportRoot */
    public $sportRoot;

    public function init()
    {
        parent::init();
        $this->sportRoot = SportRoot::model()->with('i18n')->findByPk($this->getRootNode()->data_id);
        $this->headerGalleryId = $this->sportRoot->header_gallery_id;
    }

    public function actionAlbum($link)
    {
        /** @var $albumsSection AlbumsSection */
        $albumsSection = AlbumsSection::model()->with('i18n')->findByPk($this->getNode()->data_id);
        $this->sectionGalleryId = $albumsSection->header_gallery_id;


        /** @var $album Album */
        $album = Album::model()->with('i18n')->model()->findByAttributes(array('link' => $link));
        $this->pageName = $album->i18n->page_name;
        $this->setSEOParams($album->i18n->title, $album->i18n->keywords, $album->i18n->description);
        $this->render('album', array('album' => $album));
    }

    public function actionAlbums()
    {
        /** @var $albumsSection AlbumsSection */
        $albumsSection = AlbumsSection::model()->with('i18n')->findByPk($this->getNode()->data_id);

        $this->sectionGalleryId = $albumsSection->header_gallery_id;

        $this->pageName = $albumsSection->i18n->page_name;
        $this->setSEOParams($albumsSection->i18n->title, $albumsSection->i18n->keywords, $albumsSection->i18n->description);

        $albums = Album::model()->with('i18n')->findAll(array(
            'order' => 'date desc',
            'condition' => 'not hidden and albums_section_id =' . $albumsSection->id,
        ));
        $this->render('albums', array('albums' => $albums));
    }
}
