forked from skeeks-cms/cms-mailer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMailerSettings.php
More file actions
98 lines (82 loc) · 3.03 KB
/
MailerSettings.php
File metadata and controls
98 lines (82 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* @author Semenov Alexander <[email protected]>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 17.04.2016
*/
namespace skeeks\cms\mail;
use skeeks\cms\base\Component;
use yii\helpers\ArrayHelper;
use yii\validators\EmailValidator;
use yii\widgets\ActiveForm;
/**
* Class MailerSettings
* @package skeeks\cms\mail
*/
class MailerSettings extends Component
{
/**
* @var string E-Mail адрес или список адресов через запятую на который будут дублироваться все исходящие сообщения.
*/
public $notifyEmailsHidden = '';
/**
* @var string E-Mail адрес или список адресов через запятую на который будут дублироваться все исходящие сообщения.
*/
public $notifyEmails = '';
static public function descriptorConfig()
{
return ArrayHelper::merge(parent::descriptorConfig(), [
'name' => \Yii::t('skeeks/mail', 'Mailer')
]);
}
public function rules()
{
return ArrayHelper::merge(parent::rules(), [
[['notifyEmailsHidden'], 'string'],
[['notifyEmails'], 'string'],
[['notifyEmailsHidden'], function($attribute)
{
if ($emails = explode(',', $this->notifyEmailsHidden))
{
foreach ($emails as $email)
{
$validator = new EmailValidator();
if (!$validator->validate($email, $error))
{
$this->addError($attribute, $email . ' — ' . \Yii::t('skeeks/mail', 'Incorrect email address'));
return false;
}
}
}
}],
[['notifyEmails'], function($attribute)
{
if ($emails = explode(',', $this->notifyEmails))
{
foreach ($emails as $email)
{
$validator = new EmailValidator();
if (!$validator->validate($email, $error))
{
$this->addError($attribute, $email . ' — ' . \Yii::t('skeeks/mail', 'Incorrect email address'));
return false;
}
}
}
}],
]);
}
public function attributeLabels()
{
return ArrayHelper::merge(parent::attributeLabels(), [
'notifyEmails' => \Yii::t('skeeks/mail', 'Duplicate all sent letters'),
'notifyEmailsHidden' => \Yii::t('skeeks/mail', 'Duplicate all sent letters as hidden'),
]);
}
public function renderConfigForm(ActiveForm $form)
{
echo $form->field($this, 'notifyEmails')->textarea();
echo $form->field($this, 'notifyEmailsHidden')->textarea();
}
}