|
- <?php
-
-
-
- namespace common\forms;
-
- use domain\Producer\Producer\Producer;
- use Yii;
- use yii\base\Model;
-
-
- class ContactForm extends Model
- {
-
- public $name;
- public $email;
- public $subject;
- public $body;
- public $verifyCode;
- public $isTest;
-
-
-
- public function rules()
- {
- return [
- [['name', 'email', 'subject', 'body'], 'required', 'message' => 'Champs obligatoire'],
- ['email', 'email', 'message' => 'Email incorrect'],
- ['isTest', 'string'],
- ['verifyCode', 'captcha', 'message' => 'Veuillez recopier le code de vérification', 'when' => function($model) {
- return $model->isTest != 'isTest';
- }],
- ];
- }
-
-
-
- public function attributeLabels()
- {
- return [
- 'name' => 'Nom',
- 'email' => 'Email',
- 'subject' => 'Sujet',
- 'body' => 'Message',
- 'verifyCode' => 'Code de vérification',
- ];
- }
-
-
-
- public function sendEmail(Producer $producer)
- {
- return Yii::$app->mailerService->sendProducer(
- $producer,
- 'Contact : ' . $this->subject,
- 'contact',
- [
- 'content' => $this->body,
- 'name' => $this->name,
- 'email' => $this->email
- ],
- $this->email
- );
- }
-
- public function sendEmailShopSupport(Producer $producer)
- {
- return Yii::$app->mailerService->sendAdmin(
- 'Support > '.$producer->name.' : ' . $this->subject,
- 'contact',
- [
- 'content' => $this->body,
- 'name' => $this->name,
- 'email' => $this->email
- ],
- $this->email
- );
- }
-
- public function sendEmailAdmin()
- {
- return Yii::$app->mailerService->sendAdmin(
- 'Contact : ' . $this->subject,
- 'contact',
- [
- 'content' => $this->body,
- 'name' => $this->name,
- 'email' => $this->email
- ],
- $this->email
- );
- }
- }
|