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