Completed
Push — master ( c0984a...820d33 )
by Andrey
02:04
created

OwnerAlbum::getTextAlbums()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Itstructure\MFUploader\models;
4
5
use yii\db\ActiveQuery;
6
use yii\base\InvalidArgumentException;
7
use yii\helpers\ArrayHelper;
8
use Itstructure\MFUploader\models\album\Album;
9
10
/**
11
 * This is the model class for table "owners_albums".
12
 *
13
 * @property int $albumId Album id.
14
 * @property Album $album
15
 *
16
 * @package Itstructure\MFUploader\models
17
 *
18
 * @author Andrey Girnik <[email protected]>
19
 */
20
class OwnerAlbum extends Owner
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public static function tableName()
26
    {
27
        return 'owners_albums';
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 View Code Duplication
    public function rules()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        return ArrayHelper::merge(parent::rules(), [
36
            [
37
                'albumId',
38
                'required',
39
            ],
40
            [
41
                'albumId',
42
                'integer',
43
            ],
44
            [
45
                [
46
                    'albumId',
47
                    'ownerId',
48
                    'owner',
49
                    'ownerAttribute',
50
                ],
51
                'unique',
52
                'targetAttribute' => [
53
                    'albumId',
54
                    'ownerId',
55
                    'owner',
56
                    'ownerAttribute',
57
                ],
58
            ],
59
            [
60
                ['albumId'],
61
                'exist',
62
                'skipOnError' => true,
63
                'targetClass' => Album::class,
64
                'targetAttribute' => ['albumId' => 'id'],
65
            ],
66
        ]);
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function attributeLabels()
73
    {
74
        return ArrayHelper::merge(parent::attributeLabels(), [
75
            'albumId' => 'Album ID',
76
        ]);
77
    }
78
79
    /**
80
     * @return \yii\db\ActiveQuery
81
     */
82
    public function getAlbum()
83
    {
84
        return $this->hasOne(Album::class, ['id' => 'albumId']);
85
    }
86
87
    /**
88
     * Get all albums by owner.
89
     *
90
     * @param string $owner
91
     * @param int    $ownerId
92
     * @param string $ownerAttribute
93
     *
94
     * @return Album[]
95
     */
96 View Code Duplication
    public static function getAlbums(string $owner, int $ownerId, string $ownerAttribute = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
    {
98
        return static::getAlbumsQuery([
99
            'owner' => $owner,
100
            'ownerId' => $ownerId,
101
            'ownerAttribute' => $ownerAttribute,
102
        ])->all();
103
    }
104
105
    /**
106
     * Get all albums Query by owner.
107
     *
108
     * @param array $args. It can be an array of the next params: owner{string}, ownerId{int}, ownerAttribute{string}.
0 ignored issues
show
Bug introduced by
There is no parameter named $args.. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
109
     *
110
     * @return ActiveQuery
111
     */
112
    public static function getAlbumsQuery(array $args = []): ActiveQuery
113
    {
114
        return Album::find()
115
            ->where([
116
                'id' => self::getEntityIdsQuery('albumId', $args)->asArray()
117
            ]);
118
    }
119
120
    /**
121
     * Get image albums by owner.
122
     *
123
     * @param string $owner
124
     * @param int    $ownerId
125
     *
126
     * @return Album[]
127
     */
128
    public static function getImageAlbums(string $owner, int $ownerId)
129
    {
130
        return static::getAlbums($owner, $ownerId, Album::ALBUM_TYPE_IMAGE);
131
    }
132
133
    /**
134
     * Get audio albums by owner.
135
     *
136
     * @param string $owner
137
     * @param int    $ownerId
138
     *
139
     * @return Album[]
140
     */
141
    public static function getAudioAlbums(string $owner, int $ownerId)
142
    {
143
        return static::getAlbums($owner, $ownerId, Album::ALBUM_TYPE_AUDIO);
144
    }
145
146
    /**
147
     * Get video albums by owner.
148
     *
149
     * @param string $owner
150
     * @param int    $ownerId
151
     *
152
     * @return Album[]
153
     */
154
    public static function getVideoAlbums(string $owner, int $ownerId)
155
    {
156
        return static::getAlbums($owner, $ownerId, Album::ALBUM_TYPE_VIDEO);
157
    }
158
159
    /**
160
     * Get application albums by owner.
161
     *
162
     * @param string $owner
163
     * @param int    $ownerId
164
     *
165
     * @return Album[]
166
     */
167
    public static function getAppAlbums(string $owner, int $ownerId)
168
    {
169
        return static::getAlbums($owner, $ownerId, Album::ALBUM_TYPE_APP);
170
    }
171
172
    /**
173
     * Get text albums by owner.
174
     *
175
     * @param string $owner
176
     * @param int    $ownerId
177
     *
178
     * @return Album[]
179
     */
180
    public static function getTextAlbums(string $owner, int $ownerId)
181
    {
182
        return static::getAlbums($owner, $ownerId, Album::ALBUM_TYPE_TEXT);
183
    }
184
185
    /**
186
     * Get other albums by owner.
187
     *
188
     * @param string $owner
189
     * @param int    $ownerId
190
     *
191
     * @return Album[]
192
     */
193
    public static function getOtherAlbums(string $owner, int $ownerId)
194
    {
195
        return static::getAlbums($owner, $ownerId, Album::ALBUM_TYPE_OTHER);
196
    }
197
}
198