Completed
Push — master ( fb650b...46ddf1 )
by Vladimir
05:41
created

EmailTemplate::getTranslationAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
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 ymaker\email\templates\queries\EmailTemplateQuery;
13
use creocoder\translateable\TranslateableBehavior;
14
15
/**
16
 * This is the model class for table "{{%email_template}}".
17
 *
18
 * @property int $id
19
 * @property string $key
20
 *
21
 * @property EmailTemplateTranslation[] $translations
22
 *
23
 * @author Vladimir Kuprienko <[email protected]>
24
 * @since 1.0
25
 */
26
class EmailTemplate extends ActiveRecord
27
{
28
    /**
29
     * @inheritdoc
30
     */
31
    public static function tableName()
32
    {
33
        return '{{%email_template}}';
34
    }
35
36
    /**
37
     * @inheritdoc
38
     * @return EmailTemplateQuery the newly created [[EmailTemplateQuery]] instance.
39
     */
40
    public static function find()
41
    {
42
        return Yii::createObject(EmailTemplateQuery::class, [get_called_class()]);
43
    }
44
45
    /**
46
     * Find model ID by key.
47
     *
48
     * @param string $key Model key.
49
     * @return false|null|string
50
     */
51
    public static function findId($key)
52
    {
53
        return static::find()
54
            ->select('id')
55
            ->byKey($key)
56
            ->scalar();
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public function behaviors()
63
    {
64
        return [
65
            'translateable' => [
66
                'class' => TranslateableBehavior::class,
67
                'translationAttributes' => $this->getTranslationAttributes(),
68
            ],
69
        ];
70
    }
71
72
    /**
73
     * Returns list of translation attributes.
74
     *
75
     * @return string[]
76
     */
77
    public function getTranslationAttributes()
78
    {
79
        return [
80
            'language',
81
            'subject',
82
            'body',
83
            'hint',
84
        ];
85
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90
    public function rules()
91
    {
92
        return [
93
            [['key'], 'required'],
94
            [['key'], 'string', 'max' => 255],
95
            [['key'], 'unique'],
96
        ];
97
    }
98
99
    /**
100
     * @inheritdoc
101
     */
102
    public function attributeLabels()
103
    {
104
        return [
105
            'id'    => Yii::t('email-templates/entity', 'ID'),
106
            'key'   => Yii::t('email-templates/entity', 'Key'),
107
        ];
108
    }
109
110
    /**
111
     * @inheritdoc
112
     */
113
    public function transactions()
114
    {
115
        return [
116
            'default' => self::OP_ALL,
117
        ];
118
    }
119
120
    /**
121
     * @return \yii\db\ActiveQuery
122
     */
123
    public function getTranslations()
124
    {
125
        return $this->hasMany(EmailTemplateTranslation::class, ['templateId' => 'id']);
126
    }
127
}
128