1
|
|
|
<?php |
2
|
|
|
namespace Itstructure\MFUploader\models\album; |
3
|
|
|
|
4
|
|
|
use yii\helpers\ArrayHelper; |
5
|
|
|
use Itstructure\MFUploader\behaviors\BehaviorMediafile; |
6
|
|
|
use Itstructure\MFUploader\interfaces\UploadModelInterface; |
7
|
|
|
use Itstructure\MFUploader\models\{ActiveRecord, OwnerMediafile}; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* This is the model class for audio album. |
11
|
|
|
* |
12
|
|
|
* @property array $audio Audio field. Corresponds to the file type of audio. |
13
|
|
|
* In the thml form field should also be called. |
14
|
|
|
* Can have the values according with the selected type of: |
15
|
|
|
* FileSetter::INSERTED_DATA_ID |
16
|
|
|
* FileSetter::INSERTED_DATA_URL |
17
|
|
|
* |
18
|
|
|
* @package Itstructure\MFUploader\models\album |
19
|
|
|
* |
20
|
|
|
* @author Andrey Girnik <[email protected]> |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
class AudioAlbum extends Album |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Audio field. Corresponds to the file type of audio. |
26
|
|
|
* In the thml form field should also be called. |
27
|
|
|
* Can have the values according with the selected type of: |
28
|
|
|
* FileSetter::INSERTED_DATA_ID |
29
|
|
|
* FileSetter::INSERTED_DATA_URL |
30
|
|
|
* |
31
|
|
|
* @var array audio(array of 'mediafile id' or 'mediafile url'). |
32
|
|
|
*/ |
33
|
|
|
public $audio; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function rules() |
39
|
|
|
{ |
40
|
|
|
return ArrayHelper::merge(parent::rules(), [ |
41
|
|
|
[ |
42
|
|
|
UploadModelInterface::FILE_TYPE_AUDIO, |
43
|
|
|
function($attribute) { |
44
|
|
|
if (!is_array($this->{$attribute})) { |
45
|
|
|
$this->addError($attribute, 'Audio field content must be an array.'); |
46
|
|
|
} |
47
|
|
|
}, |
48
|
|
|
'skipOnError' => false, |
49
|
|
|
], |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @inheritdoc |
55
|
|
|
*/ |
56
|
|
|
public function behaviors() |
57
|
|
|
{ |
58
|
|
|
return ArrayHelper::merge(parent::behaviors(), [ |
59
|
|
|
'mediafile' => [ |
60
|
|
|
'class' => BehaviorMediafile::class, |
61
|
|
|
'name' => self::ALBUM_TYPE_AUDIO, |
62
|
|
|
'attributes' => [ |
63
|
|
|
UploadModelInterface::FILE_TYPE_THUMB, |
64
|
|
|
UploadModelInterface::FILE_TYPE_AUDIO, |
65
|
|
|
], |
66
|
|
|
] |
67
|
|
|
]); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get album's audio. |
72
|
|
|
* |
73
|
|
|
* @return ActiveRecord[] |
74
|
|
|
*/ |
75
|
|
|
public function getAudioFiles() |
76
|
|
|
{ |
77
|
|
|
return OwnerMediafile::getMediaFiles($this->type, $this->id, static::getFileType(self::ALBUM_TYPE_AUDIO)); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
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.