1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/yiimaker/yii2-email-templates |
4
|
|
|
* @copyright Copyright (c) 2017-2019 Yii Maker |
5
|
|
|
* @license BSD 3-Clause License |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace ymaker\email\templates\entities; |
9
|
|
|
|
10
|
|
|
use Yii; |
11
|
|
|
use yii\db\ActiveRecord; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* This is the model class for table "{{%email_template_translation}}". |
15
|
|
|
* |
16
|
|
|
* @property int $id |
17
|
|
|
* @property int $templateId |
18
|
|
|
* @property string $language |
19
|
|
|
* @property string $subject |
20
|
|
|
* @property string $body |
21
|
|
|
* @property string $hint |
22
|
|
|
* @property EmailTemplate $template |
23
|
|
|
* |
24
|
|
|
* @author Volodymyr Kupriienko <[email protected]> |
25
|
|
|
* @since 1.0 |
26
|
|
|
*/ |
27
|
|
|
class EmailTemplateTranslation extends ActiveRecord |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public static function tableName() |
33
|
|
|
{ |
34
|
|
|
return '{{%email_template_translation}}'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns internal form name. |
39
|
|
|
* |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
public static function internalFormName() |
43
|
|
|
{ |
44
|
|
|
$reflector = new \ReflectionClass(self::class); |
45
|
|
|
|
46
|
|
|
return $reflector->getShortName(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function formName() |
53
|
|
|
{ |
54
|
|
|
return parent::formName() . '[' . $this->language . ']'; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function init() |
61
|
|
|
{ |
62
|
|
|
$this->hint = 'All tokens wrapped in {} will be replaced by real data'; |
63
|
|
|
parent::init(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
public function rules() |
70
|
|
|
{ |
71
|
|
|
return [ |
72
|
|
|
[['templateId', 'language'], 'safe'], |
73
|
|
|
|
74
|
|
|
['subject', 'required'], |
75
|
|
|
['subject', 'string', 'max' => 255], |
76
|
|
|
|
77
|
|
|
['body', 'required'], |
78
|
|
|
['body', 'string'], |
79
|
|
|
|
80
|
|
|
['hint', 'required'], |
81
|
|
|
['hint', 'string'], |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
|
|
public function attributeLabels() |
89
|
|
|
{ |
90
|
|
|
$labels = [ |
91
|
|
|
'subject' => Yii::t('email-templates/entity', 'Subject'), |
92
|
|
|
'body' => Yii::t('email-templates/entity', 'Body'), |
93
|
|
|
'hint' => Yii::t('email-templates/entity', 'Hint'), |
94
|
|
|
]; |
95
|
|
|
|
96
|
|
|
foreach ($labels as $key => $label) { |
97
|
|
|
$labels[$key] = $this->addLabelPostfix($label); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $labels; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Adds prefix to label. |
105
|
|
|
* |
106
|
|
|
* @param string $label |
107
|
|
|
* |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
protected function addLabelPostfix($label) |
111
|
|
|
{ |
112
|
|
|
return \sprintf('%s [%s]', $label, $this->language); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* {@inheritdoc} |
117
|
|
|
*/ |
118
|
|
|
public function transactions() |
119
|
|
|
{ |
120
|
|
|
return [ |
121
|
|
|
'default' => self::OP_ALL, |
122
|
|
|
]; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return \yii\db\ActiveQuery |
127
|
|
|
*/ |
128
|
|
|
public function getTemplate() |
129
|
|
|
{ |
130
|
|
|
return $this->hasOne(EmailTemplate::class, ['id' => 'templateId']); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|