1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\controllers; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\filters\{AccessControl, VerbFilter}; |
7
|
|
|
use yii\helpers\ArrayHelper; |
8
|
|
|
use yii\web\NotFoundHttpException; |
9
|
|
|
use app\models\{Contact, Feedback}; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ContactController |
13
|
|
|
* |
14
|
|
|
* @package app\controllers |
15
|
|
|
*/ |
16
|
|
|
class ContactController extends BaseController |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @return array |
20
|
|
|
*/ |
21
|
|
|
public function behaviors() |
22
|
|
|
{ |
23
|
|
|
return ArrayHelper::merge(parent::behaviors(), [ |
24
|
|
|
'access' => [ |
25
|
|
|
'class' => AccessControl::class, |
26
|
|
|
'rules' => [ |
27
|
|
|
[ |
28
|
|
|
'allow' => true, |
29
|
|
|
'actions' => ['index', 'captcha'], |
30
|
|
|
'roles' => ['?', '@'], |
31
|
|
|
], |
32
|
|
|
], |
33
|
|
|
], |
34
|
|
|
'verbs' => [ |
35
|
|
|
'class' => VerbFilter::class, |
36
|
|
|
'actions' => [ |
37
|
|
|
'index' => ['get', 'post'], |
38
|
|
|
'captcha' => ['get'], |
39
|
|
|
], |
40
|
|
|
], |
41
|
|
|
]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function actions() |
45
|
|
|
{ |
46
|
|
|
return ArrayHelper::merge(parent::actions(), [ |
47
|
|
|
'captcha' => [ |
48
|
|
|
'class' => 'yii\captcha\CaptchaAction', |
49
|
|
|
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, |
50
|
|
|
], |
51
|
|
|
]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Displays contacts page. |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
* |
59
|
|
|
* @throws NotFoundHttpException |
60
|
|
|
*/ |
61
|
|
|
public function actionIndex() |
62
|
|
|
{ |
63
|
|
|
$feedback = new Feedback(); |
64
|
|
|
$feedback->setScenario(Feedback::SCENARIO_CONTACT); |
65
|
|
|
|
66
|
|
|
if ($feedback->load(Yii::$app->request->post()) && $feedback->contact(Yii::$app->params['adminEmail'])) { |
|
|
|
|
67
|
|
|
|
68
|
|
|
Yii::$app->session->setFlash('contactFormSubmitted'); |
|
|
|
|
69
|
|
|
|
70
|
|
|
return $this->refresh(); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$model = Contact::getDefaultContacts(); |
74
|
|
|
|
75
|
|
|
if (null === $model) { |
76
|
|
|
throw new NotFoundHttpException('Contacts not fount.'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$this->setMetaParams($model); |
|
|
|
|
80
|
|
|
|
81
|
|
|
return $this->render('index', [ |
82
|
|
|
'model' => $model, |
83
|
|
|
'feedback' => $feedback |
84
|
|
|
]); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|