-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFilesBehavior.php
More file actions
41 lines (36 loc) · 955 Bytes
/
Copy pathFilesBehavior.php
File metadata and controls
41 lines (36 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace sokrat\uploadcare;
use Yii;
/**
* Class FilesBehavior
* Save file group and set group UUID or files UUID array as attribute value
* @package sokrat\uploadcare
*/
class FilesBehavior extends FileBehavior
{
/**
* If true set group UUID to attribute value, otherwise set files UUID array
* @var bool
*/
public $groupUUID = true;
/**
* @param $attribute
* @return array|string
*/
public function getValue($attribute)
{
/** @var \Uploadcare\Group $group */
$group = Yii::$app->uploadcare->getGroup($this->owner->$attribute);
$group->store();
if ($this->groupUUID) {
return $group->getUuid();
} else {
$files = [];
foreach ($group->getFiles() as $file) {
/** @var \UploadCare\File $file */
$files[] = $file->getUuid();
}
return $files;
}
}
}