EmailTemplateQuery   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 4
c 1
b 0
f 0
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A withTranslation() 0 5 1
A byKey() 0 3 1
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\queries;
9
10
use yii\db\ActiveQuery;
11
12
/**
13
 * Query class for [[\ymaker\email\templates\models\entities\EmailTemplate]] model.
14
 *
15
 * @author Volodymyr Kupriienko <[email protected]>
16
 * @since 1.0
17
 */
18
class EmailTemplateQuery extends ActiveQuery
19
{
20
    /**
21
     * Add by key condition.
22
     *
23
     * @param string $key Email template key.
24
     *
25
     * @return EmailTemplateQuery
26
     */
27
    public function byKey($key)
28
    {
29
        return $this->where(['key' => $key]);
30
    }
31
32
    /**
33
     * Get with translation by language.
34
     *
35
     * @param string $language
36
     *
37
     * @return EmailTemplateQuery
38
     */
39
    public function withTranslation($language)
40
    {
41
        return $this->with(['translations' => function ($query) use ($language) {
42
            /* @var ActiveQuery $query */
43
            $query->andWhere(['language' => $language]);
44
        }]);
45
    }
46
}
47