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