<?php

namespace common\modules\school\controllers;

use common\components\BaseController;
use common\modules\school\models\Courses;
use common\modules\school\models\SearchCourses;
use common\modules\school\models\SearchLessons;
use common\modules\users\models\User;
use common\models\LoginForm;

class CourseController extends BaseController
{
    public static function actionsTitles()
    {
        return [
            'Index'	 => 'Курсы',
            'View'	 => 'Курс',
        ];
    }
    
    public function actionIndex()
    {
        \Yii::$app->view->registerMetaTag([
            'property' => 'og:title',
            'content' => 'Школа аналитики'
        ]);
        $searchModel  = new SearchCourses();
        $search = \Yii::$app->request->queryParams;
        $dataProvider = $searchModel->search($search);		
        
        $modelUser = new User();
        $modelLogin = new LoginForm();
        
        $form = new \common\components\BaseForm('/common/modules/users/forms/RegistrationUserForm', $modelUser);
        $formPopup = new \common\components\BaseForm('/common/modules/users/forms/RegistrationUserPopupForm', $modelUser);
        $formLogin = new \common\components\BaseForm('/common/modules/users/forms/LoginForm', $modelLogin);
        $formLoginPopup = new \common\components\BaseForm('/common/modules/users/forms/LoginPopupForm', $modelLogin);
        return $this->render('index', ['dataProvider' => $dataProvider, 'form' => $form->out, 'formLogin' => $formLogin->out,
            'formPopup' => $formPopup->out, 'formLoginPopup' => $formLoginPopup->out]);
    }
    
    public function actionView($id)
    {
        $model = Courses::findOne($id);
        
        $searchModel  = new SearchLessons();
        $search['course_id'] = $id;
        $dataProvider = $searchModel->search($search);
        return $this->render('view', ['dataProvider' => $dataProvider, 'model' => $model]);
    }
}
