Banner   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 85
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 4 1
A rules() 0 18 1
A attributeLabels() 0 12 1
A transactions() 0 6 1
A getTranslations() 0 4 1
A behaviors() 0 6 1
A loadDefaultValues() 0 5 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\backend\models\entities;
9
10
use yii\behaviors\TimestampBehavior;
11
use ymaker\banner\backend\Module as BannerModule;
12
use ymaker\banner\common\models\entities\Banner as CommonBanner;
13
14
/**
15
 * This is the model class for table "{{%banner}}".
16
 *
17
 * @author Vladimir Kuprienko <[email protected]>
18
 * @since 1.0
19
 */
20
class Banner extends CommonBanner
21
{
22
    /**
23
     * @inheritdoc
24
     */
25
    public static function find()
26
    {
27
        return parent::find()->with('translations');
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function behaviors()
34
    {
35
        $behaviors = parent::behaviors();
36
        $behaviors['timestamp'] = TimestampBehavior::class;
37
        return $behaviors;
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function loadDefaultValues($skipIfSet = true)
44
    {
45
        $this->slug = 'banner-' . (self::find()->count() + 1);
46
        return parent::loadDefaultValues($skipIfSet);
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function rules()
53
    {
54
        return [
55
            ['slug', 'required'],
56
            ['slug', 'unique'],
57
            ['slug', 'string', 'max' => 255],
58
59
            ['published', 'boolean'],
60
            ['published', 'default', 'value' => true],
61
62
            ['views_count', 'integer'],
63
            ['views_count', 'default', 'value' => 0],
64
65
            [['created_at', 'updated_at'], 'safe'],
66
67
            [['valid_from', 'valid_until'], 'safe'],
68
        ];
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74
    public function attributeLabels()
75
    {
76
        return [
77
            'slug'          => BannerModule::t('Slug'),
78
            'views_count'   => BannerModule::t('Views count'),
79
            'published'     => BannerModule::t('Published'),
80
            'created_at'    => BannerModule::t('Created at'),
81
            'updated_at'    => BannerModule::t('Updated at'),
82
            'valid_from'    => BannerModule::t('Valid from'),
83
            'valid_until'   => BannerModule::t('Valid until'),
84
        ];
85
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90
    public function transactions()
91
    {
92
        return [
93
            self::SCENARIO_DEFAULT => self::OP_ALL,
94
        ];
95
    }
96
97
    /**
98
     * @inheritdoc
99
     */
100
    public function getTranslations()
101
    {
102
        return $this->hasMany(BannerTranslation::class, ['banner_id' => 'id']);
103
    }
104
}
105