|
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
|
|
|
* |
|
30
|
|
|
* @method BannerTranslation getTranslation($language = null) |
|
31
|
|
|
* |
|
32
|
|
|
* @author Vladimir Kuprienko <[email protected]> |
|
33
|
|
|
* @since 1.0 |
|
34
|
|
|
*/ |
|
35
|
|
|
class Banner extends ActiveRecord |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* @inheritdoc |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function tableName() |
|
41
|
|
|
{ |
|
42
|
|
|
return '{{%banner}}'; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @inheritdoc |
|
47
|
|
|
*/ |
|
48
|
|
|
public function behaviors() |
|
49
|
|
|
{ |
|
50
|
|
|
return [ |
|
51
|
|
|
'translateable' => [ |
|
52
|
|
|
'class' => TranslateableBehavior::class, |
|
53
|
|
|
'translationAttributes' => $this->getTranslationAttributes(), |
|
54
|
|
|
], |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Returns list of translation attributes. |
|
60
|
|
|
* |
|
61
|
|
|
* @return string[] |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getTranslationAttributes() |
|
64
|
|
|
{ |
|
65
|
|
|
return [ |
|
66
|
|
|
'content', |
|
67
|
|
|
'hint', |
|
68
|
|
|
'alt', |
|
69
|
|
|
'file_name', |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return \yii\db\ActiveQuery |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getTranslations() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->hasMany(BannerTranslation::class, ['banner_id' => 'id']); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Increments views counter. |
|
83
|
|
|
*/ |
|
84
|
|
|
public function incrementViewsCounter() |
|
85
|
|
|
{ |
|
86
|
|
|
self::updateAllCounters( |
|
87
|
|
|
['views_count' => 1], |
|
88
|
|
|
'slug = :slug', |
|
89
|
|
|
[':slug' => $this->slug] |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|