Completed
Push — master ( 9fd96a...347dc9 )
by Alexey
02:28
created

DefaultController::actionAbout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace modules\main\controllers\frontend;
4
5
use Yii;
6
use yii\web\Controller;
7
use modules\main\models\frontend\ContactForm;
8
use modules\main\Module;
9
10
/**
11
 * Class DefaultController
12
 * @package modules\main\controllers\frontend
13
 */
14
class DefaultController extends Controller
15
{
16
    /**
17
     * @inheritdoc
18
     * @return array
19
     */
20
    public function actions()
21
    {
22
        return [
23
            'error' => [
24
                'class' => 'yii\web\ErrorAction',
25
            ],
26
            'captcha' => [
27
                'class' => 'yii\captcha\CaptchaAction',
28
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
29
                'backColor' => 0xF1F1F1,
30
                'foreColor' => 0xEE7600,
31
            ],
32
        ];
33
    }
34
35
    /**
36
     * Renders the index view for the module
37
     * @return string
38
     */
39
    public function actionIndex()
40
    {
41
        return $this->render('index');
42
    }
43
44
    /**
45
     * Displays contact page.
46
     *
47
     * @return mixed|\yii\web\Response
48
     */
49
    public function actionContact()
50
    {
51
        $model = new ContactForm();
52
        if (Yii::$app->user->isGuest)
53
            $model->scenario = $model::SCENARIO_GUEST;
54
55
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
56
            return $this->processSendEmail($model);
57
        }
58
59
        return $this->render('contact', [
60
            'model' => $model,
61
        ]);
62
    }
63
64
    /**
65
     * @param ContactForm $model
66
     * @return \yii\web\Response
67
     */
68
    protected function processSendEmail($model)
69
    {
70
        if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
71
            Yii::$app->session->setFlash('success', Module::t('module', 'Thank you for contacting us. We will respond to you as soon as possible.'));
72
        } else {
73
            Yii::$app->session->setFlash('error', Module::t('module', 'There was an error sending email.'));
74
        }
75
        return $this->refresh();
76
    }
77
78
    /**
79
     * Displays about page.
80
     *
81
     * @return mixed
82
     */
83
    public function actionAbout()
84
    {
85
        return $this->render('about');
86
    }
87
}
88