23 public static function getData(?
int $fileId): ?array
25 if ($fileId > 0 && ($file = \CFile::GetByID($fileId)->Fetch()))
33 'src' => \CFile::GetFileSRC($file),
37 if ($file[
'VERSION_ORIGINAL_ID'] == $fileId)
39 $originalFile = \CFile::GetByID($fileId,
true)->Fetch();
42 ($metaData = $file[
'META'] ? Main\Web\Json::decode($file[
'META']) : [])
43 && is_array($metaData)
44 && isset($metaData[
'maskInfo'])
45 && $metaData[
'maskInfo'][
'id'] > 0
48 $maskId = $metaData[
'maskInfo'][
'id'];
52 'filter' => [
'FILE_ID' => $fileId],
56 $maskId = $res[
'ITEM_ID'];
65 'src' => \CFile::GetFileSRC($originalFile),
74 public static function save(?
int $originalFileId, array $file, ?Main\Engine\
CurrentUser $currentUser =
null): ?int
76 $originalFile = \CFile::GetByID($originalFileId)->Fetch();
81 $currentUser = is_null($currentUser) ? Main\Engine\CurrentUser::get() : $currentUser;
82 $consumer = Avatar\Mask\Consumer::createFromId($currentUser->getId());
83 while (((
int)$originalFile[
'ID'] !== (
int)$originalFileId))
85 \CFile::Delete($originalFile[
'ID']);
86 $originalFile = \CFile::GetByID($originalFileId)->Fetch();
88 if ($fileIdWithMask = \CFile::SaveFile($file + [
'MODULE_ID' =>
'ui'],
'ui/masked'))
90 $maskId = isset($file[
'maskInfo']) ? $file[
'maskInfo'][
'id'] :
null;
92 && ($maskItem = Avatar\Mask\Item::getInstance($maskId))
93 && $maskItem->isReadableBy($consumer)
94 && \CFile::AddVersion($originalFileId, $fileIdWithMask, [
'maskInfo' => [
'id' => $maskId]])->isSuccess()
97 $maskItem->applyToFileBy($originalFileId, $fileIdWithMask, $consumer);
98 $consumer->useRecentlyMaskId($maskItem->getId());
99 return $fileIdWithMask;
101 \CFile::Delete($fileIdWithMask);
134 if (!is_array($rawFiles) || !is_array($postData))
140 array_walk($rawFiles,
function($item, $subField) use (&$orderedFiles) {
141 foreach ($item as $key => $value)
143 $orderedFiles[$key] = $orderedFiles[$key] ?? [];
144 $orderedFiles[$key][$subField] = $value;
148 if (isset($orderedFiles[$id]))
150 $result = $orderedFiles[$id];
151 $maskInfo = ($postData[$id] ?? []);
152 if (isset($maskInfo[
'maskId']))
154 $result[
'maskInfo'] = [
'id' => $maskInfo[
'maskId']];