SiteController::actionAbout()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TerabyteSoft\App\Basic\Controllers;
4
5
use TerabyteSoft\App\Basic\Forms\ContactForm;
6
use yii\base\Model;
7
use Yiisoft\Yii\Captcha\CaptchaAction;
8
use yii\web\Controller;
9
use yii\web\ErrorAction;
10
use yii\web\filters\AccessControl;
11
use yii\web\filters\VerbFilter;
12
use yii\web\Response;
13
14
/**
15
 * SiteController.
16
 *
17
 * Controller web application basic
18
 **/
19
class SiteController extends Controller
20
{
21
    /**
22
     * actions.
23
     *
24
     * @return array actions config
25
     **/
26
    public function actions(): array
27
    {
28
        return [
29
            'error' => [
30
                '__class' => ErrorAction::class,
31
                'view' => $this->app->params['app.basic.error.view.pathmap'],
32
             ],
33
            'captcha' => [
34
                '__class'         => CaptchaAction::class,
35
                'fixedVerifyCode' => $this->app->params['app.basic.captcha.fixedVerifyCode'],
36
            ],
37
        ];
38
    }
39
40
    /**
41
     * actionIndex.
42
     *
43
     * displays homepage
44
     *
45
     * @return string
46
     **/
47
    public function actionIndex(): string
48
    {
49
        return $this->render('Index');
50
    }
51
52
    /**
53
     * actionAbout.
54
     *
55
     * displays about page
56
     *
57
     * @return string
58
     **/
59
    public function actionAbout(): string
60
    {
61
        return $this->render('About');
62
    }
63
64
    /**
65
     * actionContact.
66
     *
67
     * displays contact page
68
     *
69
     * @return response|string
70
     **/
71
    public function actionContact()
72
    {
73
        $model = new ContactForm();
74
75
        if ($model->load($this->app->request->post()) && $model->validate()) {
76
            $this->sendContact($this->app->params['app.basic.email'], $model);
77
            $this->app->session->setFlash('contactFormSubmitted');
78
79
            return $this->refresh();
80
        }
81
82
        return $this->render('Contact', [
83
            'model' => $model,
84
        ]);
85
    }
86
87
    /**
88
     * sendContactForm.
89
     *
90
     * sends an email to the specified email address using the information collected by this model
91
     *
92
     * @param string $email the target email address
93
     * @param Model  $model
94
     *
95
     * @return bool whether the model passes validation
96
     **/
97
    public function sendContact(string $email, Model $model): void
98
    {
99
        $this->app->mailer->compose()
100
            ->setTo($email)
101
            ->setFrom([$model->email => $model->name])
102
            ->setSubject($model->subject)
103
            ->setTextBody($model->body)
104
            ->send();
105
    }
106
}
107