<?php

namespace common\modules\school\controllers;

use Yii;

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\modules\rbac\models\AuthAssignment; 


class CourseController extends BaseController
{
    public static function actionsTitles()
    {
        return [
            'Index'	 => 'Курсы',
            'View'	 => 'Курс',
        ];
    }
    
    public function actionIndex()
    {
        $searchModel  = new SearchCourses();
        $search = \Yii::$app->request->queryParams;
        $dataProvider = $searchModel->search($search);		
        
        $modelUser = new User();
        $form = new \common\components\BaseForm('/common/modules/users/forms/RegistrationUserForm', $modelUser);
        $formPopup = new \common\components\BaseForm('/common/modules/users/forms/RegistrationUserPopupForm', $modelUser);
        return $this->render('index', ['dataProvider' => $dataProvider, 'form' => $form->out, 'formPopup' => $formPopup->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]);
    }
}
