1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Helper.php
См. документацию.
1<?php
2namespace Bitrix\UI\Avatar\Mask;
3
4use Bitrix\Main;
5use Bitrix\Main\HttpRequest;
6use Bitrix\UI\Avatar;
7
8class Helper
9{
10 public const REQUEST_FIELD_NAME = 'ui_avatar_editor';
11 public static function getHTMLAttribute($fileId)
12 {
13 return ' data-bx-ui-avatar-editor-info="'.htmlspecialcharsbx(self::getJson($fileId)).'" ';
14 }
15
16 public static function getJson($fileId): string
17 {
19 static::getData($fileId)
20 );
21 }
22
23 public static function getData(?int $fileId): ?array
24 {
25 if ($fileId > 0 && ($file = \CFile::GetByID($fileId)->Fetch()))
26 {
27 $result = [
28 // 'name' => $file['FILE_NAME'],
29 // 'width' => $file['WIDTH'],
30 // 'height' => $file['HEIGHT'],
31 // 'size' => $file['FILE_SIZE'],
32 // 'type' => $file['CONTENT_TYPE'],
34 // 'meta' => $file['META']
35 ];
36
37 if ($file['VERSION_ORIGINAL_ID'] == $fileId)
38 {
39 $originalFile = \CFile::GetByID($fileId, true)->Fetch();
40 $maskId = null;
41 if (
42 ($metaData = $file['META'] ? Main\Web\Json::decode($file['META']) : [])
43 && is_array($metaData)
44 && isset($metaData['maskInfo'])
45 && $metaData['maskInfo']['id'] > 0
46 )
47 {
48 $maskId = $metaData['maskInfo']['id'];
49 }
50 else if ($res = Avatar\Model\ItemToFileTable::getList([
51 'select' => ['*'],
52 'filter' => ['FILE_ID' => $fileId],
53 'limit' => 1
54 ])->fetch())
55 {
56 $maskId = $res['ITEM_ID'];
57 }
58
59 $result = [
60 // 'name' => $originalFile['FILE_NAME'],
61 // 'width' => $originalFile['WIDTH'],
62 // 'height' => $originalFile['HEIGHT'],
63 // 'size' => $originalFile['FILE_SIZE'],
64 // 'type' => $originalFile['CONTENT_TYPE'],
65 'src' => \CFile::GetFileSRC($originalFile),
66 'maskId' => $maskId
67 ];
68 }
69 return $result;
70 }
71 return null;
72 }
73
74 public static function save(?int $originalFileId, array $file, ?Main\Engine\CurrentUser $currentUser = null): ?int
75 {
76 $originalFile = \CFile::GetByID($originalFileId)->Fetch();
77 if (!$originalFile)
78 {
79 return null;
80 }
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))
84 {
85 \CFile::Delete($originalFile['ID']);
86 $originalFile = \CFile::GetByID($originalFileId)->Fetch();
87 }
88 if ($fileIdWithMask = \CFile::SaveFile($file + ['MODULE_ID' => 'ui'], 'ui/masked'))
89 {
90 $maskId = isset($file['maskInfo']) ? $file['maskInfo']['id'] : null;
91 if ($maskId
92 && ($maskItem = Avatar\Mask\Item::getInstance($maskId))
93 && $maskItem->isReadableBy($consumer)
94 && \CFile::AddVersion($originalFileId, $fileIdWithMask, ['maskInfo' => ['id' => $maskId]])->isSuccess()
95 )
96 {
97 $maskItem->applyToFileBy($originalFileId, $fileIdWithMask, $consumer);
98 $consumer->useRecentlyMaskId($maskItem->getId());
99 return $fileIdWithMask;
100 }
101 \CFile::Delete($fileIdWithMask);
102 }
103 return null;
104 }
105
106 public static function getMaskedFile(string $fieldName, ?HttpRequest $request = null): ?array
107 {
109 $request = ($request ?? Main\Application::getInstance()->getContext()->getRequest());
110 $mask = null;
111 if ($id = $request->getPost(self::REQUEST_FIELD_NAME . $fieldName))
112 {
114 $id,
115 $request->getFile(self::REQUEST_FIELD_NAME),
116 $request->getPost(self::REQUEST_FIELD_NAME)
117 );
118 }
119 return $mask;
120 }
121
128 public static function getDataFromRequest(string $fieldName, ?HttpRequest $request = null): ?array
129 {
130 return null;
131 }
132 protected static function getMaskFromRequest($id, ?array $rawFiles, ?array $postData): ?array
133 {
134 if (!is_array($rawFiles) || !is_array($postData))
135 {
136 return null;
137 }
138
139 $orderedFiles = [];
140 array_walk($rawFiles, function($item, $subField) use (&$orderedFiles) {
141 foreach ($item as $key => $value)
142 {
143 $orderedFiles[$key] = $orderedFiles[$key] ?? [];
144 $orderedFiles[$key][$subField] = $value;
145 }
146 });
147 $result = null;
148 if (isset($orderedFiles[$id]))
149 {
150 $result = $orderedFiles[$id];
151 $maskInfo = ($postData[$id] ?? []);
152 if (isset($maskInfo['maskId']))
153 {
154 $result['maskInfo'] = ['id' => $maskInfo['maskId']];
155 }
156 }
157 return $result;
158 }
159
177 public static function addSystemMask(array $file, array $descriptionParams): ?Item
178 {
180 new Owner\System(),
181 $file,
182 [
183 'GROUP_ID' => $descriptionParams['GROUP_ID'] ?? null,
184 'TITLE' => $descriptionParams['TITLE'] ?? null,
185 'DESCRIPTION' => $descriptionParams['DESCRIPTION'] ?? null,
186 'SORT' => $descriptionParams['SORT'] ?? 0,
187 ]
188 )->getData();
189
190 return reset($result);
191 }
192
193 public static function setSystemGroup(string $title, ?string $description): ?Group
194 {
195 return Group::createOrGet(new Owner\System(), $title, $description);
196 }
197}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static getInstance()
Определения application.php:98
static get()
Определения currentuser.php:33
static getSrc($file=array())
Определения fileinputunclouder.php:13
static encode($data, $options=null)
Определения json.php:22
static createOrGet(DefaultOwner $owner, string $title, ?string $description=null)
Определения Group.php:73
static addSystemMask(array $file, array $descriptionParams)
Определения Helper.php:177
static getDataFromRequest(string $fieldName, ?HttpRequest $request=null)
Определения Helper.php:128
static getHTMLAttribute($fileId)
Определения Helper.php:11
static getData(?int $fileId)
Определения Helper.php:23
const REQUEST_FIELD_NAME
Определения Helper.php:10
static getMaskFromRequest($id, ?array $rawFiles, ?array $postData)
Определения Helper.php:132
static save(?int $originalFileId, array $file, ?Main\Engine\CurrentUser $currentUser=null)
Определения Helper.php:74
static setSystemGroup(string $title, ?string $description)
Определения Helper.php:193
static getJson($fileId)
Определения Helper.php:16
static getInstance($id)
Определения Item.php:190
static create(Owner\DefaultOwner $owner, array $file, ?array $descriptionParams=[])
Определения Item.php:152
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
Определения action.php:3
Определения cookie.php:3
if(empty($signedUserToken)) $key
Определения quickway.php:257
$title
Определения pdf.php:123
$postData
Определения index.php:29