Banner   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 59
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 4 1
A behaviors() 0 9 1
A getTranslationAttributes() 0 10 1
A getTranslations() 0 4 1
A incrementViewsCounter() 0 8 1
1
<?php
2
/**
3
 * @link https://github.com/yiimaker/yii2-banner
4
 * @copyright Copyright (c) 2017 Yii Maker
5
 * @license BSD 3-Clause License
6
 */
7
8
namespace ymaker\banner\common\models\entities;
9
10
use yii\db\ActiveRecord;
11
use creocoder\translateable\TranslateableBehavior;
12
13
/**
14
 * This is the model class for table "{{%banner}}".
15
 *
16
 * @property int $id
17
 * @property string $slug
18
 * @property bool $published
19
 * @property int $views_count
20
 * @property int $created_at
21
 * @property int $updated_at
22
 * @property string $valid_from
23
 * @property string $valid_until
24
 *
25
 * @property BannerTranslation[] $translations
26
 * @property string $content
27
 * @property string $file_name
28
 * @property string $alt
29
 * @property string $link
30
 *
31
 * @method BannerTranslation getTranslation($language = null)
32
 *
33
 * @author Vladimir Kuprienko <[email protected]>
34
 * @since 1.0
35
 */
36
class Banner extends ActiveRecord
37
{
38
    /**
39
     * @inheritdoc
40
     */
41
    public static function tableName()
42
    {
43
        return '{{%banner}}';
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function behaviors()
50
    {
51
        return [
52
            'translateable' => [
53
                'class' => TranslateableBehavior::class,
54
                'translationAttributes' => $this->getTranslationAttributes(),
55
            ],
56
        ];
57
    }
58
59
    /**
60
     * Returns list of translation attributes.
61
     *
62
     * @return string[]
63
     */
64
    public function getTranslationAttributes()
65
    {
66
        return [
67
            'content',
68
            'hint',
69
            'alt',
70
            'file_name',
71
            'link',
72
        ];
73
    }
74
75
    /**
76
     * @return \yii\db\ActiveQuery
77
     */
78
    public function getTranslations()
79
    {
80
        return $this->hasMany(BannerTranslation::class, ['banner_id' => 'id']);
81
    }
82
83
    /**
84
     * Increments views counter.
85
     */
86
    public function incrementViewsCounter()
87
    {
88
        self::updateAllCounters(
89
            ['views_count' => 1],
90
            'slug = :slug',
91
            [':slug' => $this->slug]
92
        );
93
    }
94
}
95