<?php

namespace common\modules\support\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;

use common\modules\support\models\redmine\Issue;
use common\modules\support\models\redmine\IssueSearch;

/**
 * Default controller for the `support` module
 */
class SupportController extends Controller
{
	public $meta_title;
    public $meta_description;
    public $meta_keywords;
    
	public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'user' => 'support',
                'only' => ['index'],
                'rules' => [
                    [
                        'allow' => true,
                        'actions' => ['index'],
                        'roles' => ['@'],
                    ],
                ],
            ],
        ];
    }

	public static function actionsTitles()
    {
        return [
            'Index'          => 'Техническая поддержка',
        ];
    }

    public function actionIndex()
    {
        $searchModel = new IssueSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    public function actionCreate()
    {
        $model = new Issue();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }
}
