Completed
Push — master ( 80fd4c...ece9a3 )
by Paweł
03:01
created

Media::getMediaStats()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace app\models;
4
5
use Yii;
6
use yii\behaviors\TimestampBehavior;
7
use yii\helpers\ArrayHelper;
8
9
/**
10
 * This is the model class for table "media".
11
 *
12
 * @property int $id
13
 * @property int $account_id
14
 * @property string $shortcode
15
 * @property int $is_video
16
 * @property string $caption
17
 * @property string $instagram_id
18
 * @property string $taken_at
19
 * @property string $updated_at
20
 * @property string $created_at
21
 * @property int $likes
22
 * @property int $comments
23
 * @property int $account_followed_by
24
 * @property int $account_follows
25
 *
26
 * @property Account $account
27
 * @property MediaAccount[] $mediaAccounts
28
 * @property Account[] $accounts
29
 * @property MediaTag[] $mediaTags
30
 * @property Tag[] $tags
31
 */
32
class Media extends \yii\db\ActiveRecord
33
{
34
    public function behaviors()
35
    {
36
        return ArrayHelper::merge(parent::behaviors(), [
37
            'time' => TimestampBehavior::class,
38
        ]);
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public static function tableName()
45
    {
46
        return 'media';
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function rules()
53
    {
54
        return [
55
            [['account_id', 'likes', 'comments', 'account_followed_by', 'account_follows'], 'integer'],
56
            [['is_video'], 'boolean'],
57
            [['shortcode'], 'required'],
58
            [['caption'], 'string'],
59
            [['taken_at', 'updated_at', 'created_at'], 'safe'],
60
            [['shortcode', 'instagram_id'], 'string', 'max' => 255],
61
            [['shortcode'], 'unique'],
62
            [['account_id'], 'exist', 'skipOnError' => true, 'targetClass' => Account::class, 'targetAttribute' => ['account_id' => 'id']],
63
        ];
64
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69
    public function attributeLabels()
70
    {
71
        return [
72
            'id' => 'ID',
73
            'account_id' => 'Account ID',
74
            'shortcode' => 'Shortcode',
75
            'is_video' => 'Is Video',
76
            'caption' => 'Caption',
77
            'instagram_id' => 'Instagram ID',
78
            'taken_at' => 'Taken At',
79
            'updated_at' => 'Updated At',
80
            'created_at' => 'Created At',
81
            'likes' => 'Likes',
82
            'comments' => 'Comments',
83
            'account_followed_by' => 'Account Followed By',
84
            'account_follows' => 'Account Follows',
85
        ];
86
    }
87
88
    /**
89
     * @return \yii\db\ActiveQuery
90
     */
91
    public function getAccount()
92
    {
93
        return $this->hasOne(Account::class, ['id' => 'account_id']);
94
    }
95
96
97
    /**
98
     * @return \yii\db\ActiveQuery
99
     */
100
    public function getMediaAccounts()
101
    {
102
        return $this->hasMany(MediaAccount::class, ['media_id' => 'id']);
103
    }
104
105
    /**
106
     * @return \yii\db\ActiveQuery
107
     */
108
    public function getAccounts()
109
    {
110
        return $this->hasMany(Account::class, ['id' => 'account_id'])->viaTable('media_account', ['media_id' => 'id']);
111
    }
112
113
114
    /**
115
     * @return \yii\db\ActiveQuery
116
     */
117
    public function getMediaTags()
118
    {
119
        return $this->hasMany(MediaTag::class, ['media_id' => 'id']);
120
    }
121
122
    /**
123
     * @return \yii\db\ActiveQuery
124
     */
125
    public function getTags()
126
    {
127
        return $this->hasMany(Tag::class, ['id' => 'tag_id'])->viaTable('media_tag', ['media_id' => 'id']);
128
    }
129
130
    /**
131
     * @inheritdoc
132
     * @return MediaQuery the active query used by this AR class.
133
     */
134
    public static function find()
135
    {
136
        return new MediaQuery(get_called_class());
137
    }
138
}
139