Completed
Push — master ( 0daec9...07eda8 )
by Paweł
02:54
created

Account::extraFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 06.05.2018
6
 */
7
8
namespace app\modules\api\v1\models;
9
10
11
use yii\behaviors\AttributeTypecastBehavior;
12
use yii\helpers\ArrayHelper;
13
use yii\helpers\Url;
14
15
class Account extends \app\models\Account
16
{
17
    public function behaviors()
18
    {
19
        return ArrayHelper::merge(parent::behaviors(), [
20
            'type' => [
21
                'class' => AttributeTypecastBehavior::class,
22
                'typecastAfterValidate' => false,
23
                'typecastAfterSave' => true,
24
                'typecastAfterFind' => true,
25
            ],
26
        ]);
27
    }
28
29
    public function fields()
30
    {
31
        return [
32
            'id',
33
            'uid',
34
            'username',
35
            'monitoring',
36
            'disabled',
37
            'name',
38
            'profile_pic_url' => function () {
39
                return Url::to($this->profile_pic_url, true);
40
            },
41
            'full_name',
42
            'biography',
43
            'external_url',
44
            'instagram_id',
45
            'notes',
46
            'updated_at',
47
            'created_at',
48
49
//            'followed_by' => 'as_followed_by',
50
//            'follows' => 'as_follows',
51
//            'media' => 'as_media',
52
//            'er' => 'as_er',
53
        ];
54
    }
55
56
    public function extraFields()
57
    {
58
        return [
59
            'lastAccountStats',
60
        ];
61
    }
62
63
    /**
64
     * @return \yii\db\ActiveQuery
65
     */
66
    public function getLastAccountStats()
67
    {
68
        return $this->hasOne(AccountStats::class, ['account_id' => 'id'])
69
            ->orderBy('account_stats.id DESC')
70
            ->limit(1);
71
    }
72
}