Passed
Push — master ( 23cda4...8c993e )
by Vladimir
02:15
created

EmailTemplateTranslation::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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 yii2deman\tools\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
     * @inheritdoc
41
     */
42
    public function init()
43
    {
44
        $this->hint = 'All tokens wrapped in {} will be replaced by real data';
45
        parent::init();
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function rules()
52
    {
53
        return [
54
            [['templateId'], 'required'],
55
            [['templateId'], 'integer'],
56
57
            [['language'], 'required'],
58
            [['language'], 'string', 'max' => 16],
59
60
            [['subject'], 'required'],
61
            [['subject'], 'string', 'max' => 255],
62
63
            [['body'], 'required'],
64
            [['body'], 'string'],
65
66
            [['hint'], 'required'],
67
            [['hint'], 'string'],
68
        ];
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74
    public function transactions()
75
    {
76
        return [
77
            'default' => self::OP_ALL,
78
        ];
79
    }
80
81
    /**
82
     * @inheritdoc
83
     */
84
    public function attributeLabels()
85
    {
86
        return [
87
            'id'            => Yii::t('email-templates/entity', 'ID'),
88
            'templateId'    => Yii::t('email-templates/entity', 'Template ID'),
89
            'language'      => Yii::t('email-templates/entity', 'Language'),
90
            'subject'       => Yii::t('email-templates/entity', 'Subject'),
91
            'body'          => Yii::t('email-templates/entity', 'Body'),
92
        ];
93
    }
94
95
    /**
96
     * @inheritdoc
97
     */
98
    public function attributeHints()
99
    {
100
        /* @var LanguageProviderInterface $languageProvider */
101
        $languageProvider = Yii::$container->get(LanguageProviderInterface::class);
102
        $label = Yii::t('email-templates/entity', 'Original')
103
            . ' ['
104
            . $languageProvider->getLanguageLabel($this->language)
105
            . ']: ';
106
107
        return [
108
            'subject' => $label . $this->subject,
109
            'body' => $label . $this->body,
110
        ];
111
    }
112
113
    /**
114
     * @return \yii\db\ActiveQuery
115
     */
116
    public function getTemplate()
117
    {
118
        return $this->hasOne(EmailTemplate::class, ['id' => 'templateId']);
119
    }
120
}
121