9use \Bitrix\Main\Engine\Response;
10use \Bitrix\Main\UI\PageNavigation;
16 return static::getList(
17 Avatar\Model\ItemTable::query()
20 Avatar\
Mask\Owner\System::class,
21 Avatar\
Mask\Owner\RestApp::class
32 return static::getList(
33 Avatar\Model\ItemTable::query()
35 '=OWNER_TYPE' => Avatar\
Mask\Owner\User::class,
36 '=OWNER_ID' => $currentUser->getId()
46 return static::getList(
47 Avatar\Model\ItemTable::query()
49 '=SHARED_FOR.USER_ACCESS.USER_ID' => $currentUser->getId(),
50 '=OWNER_TYPE' => Avatar\
Mask\Owner\User::class,
51 '!=OWNER_ID' => $currentUser->getId()
54 ->addOrder(
'SHARED_FOR.ID',
'DESC')
63 return static::getList(
64 Avatar\Model\ItemTable::query()
65 ->setSelect([
'ID',
'FILE_ID',
'TITLE',
'DESCRIPTION',
'SORT'])
66 ->setOrder([
'RECENTLY_USED_BY.ID' =>
'DESC',
'ID' =>
'DESC'])
68 '=RECENTLY_USED_BY.USER_ID' => $currentUser->getId()
70 ->addOrder(
'RECENTLY_USED_BY.ID',
'DESC')
84 if (count($query->getSelect()) <= 0)
87 ->setSelect([
'ID',
'GROUP_ID',
'FILE_ID',
'TITLE',
'DESCRIPTION',
'SORT'])
88 ->setOrder([
'GROUP_ID' =>
'ASC',
'SORT' =>
'ASC',
'ID' =>
'DESC'])
92 ->setLimit($pageNavigation->
getLimit())
97 while (($res = $dbRes->fetch()) && $res)
99 if ($file = \CFile::GetFileArray($res[
'FILE_ID']))
101 $groupId = (int) ($res[
'GROUP_ID'] ?? 0);
102 if (!isset($result[$groupId]))
104 $result[$groupId] = [
'items' => []];
106 $result[$groupId][
'items'][] = [
108 'title' => $res[
'TITLE'],
109 'description' => $res[
'DESCRIPTION'],
110 'src' => $file[
'SRC'],
112 'editable' => Avatar\Mask\Item::getInstance($res[
'ID'])->isEditableBy(
119 $groupIds = array_keys($result);
120 if (array_sum($groupIds) > 0)
122 $dbRes = Avatar\Model\GroupTable::getList([
137 while ($res = $dbRes->fetch())
139 if (isset($result[$res[
'ID']]))
141 $result[$res[
'ID']][
'title'] = $res[
'TITLE'];
142 $result[$res[
'ID']][
'id'] = $res[
'ID'];
147 return new Response\DataType\Page(
'groupedItems', array_values($result),
null);
153 if ($result->isSuccess())
155 [
'item' => $item] = $result->getData();
156 return Response\AjaxJson::createSuccess(
157 [
'accessCode' => Main\UI\EntitySelector\Converter::convertFromFinderCodes($item->getAccessCode())]
160 return Response\AjaxJson::createDenied();
166 $consumer = Avatar\Mask\Consumer::createFromId($currentUser->getId());
168 if (!($item = Avatar\
Mask\Item::getInstance($id)))
170 $result->addError(
new Main\
Error(
"Mask with id {$id} is not found.",
'Not found.'));
172 elseif (!$item->isEditableBy($consumer))
174 $result->addError(
new Main\
Error(
"Mask with id {$id} is not editable.",
'Access denied.'));
178 $result->setData([
'item' => $item]);
185 $destCodesList = Main\UI\EntitySelector\Converter::convertToFinderCodes($accessCode);
186 $file = ($file[
'changed'] ===
'Y' ? $this->
getRequest()->getFile(
'file') :
null);
190 if ($result->isSuccess())
192 [
'item' => $item] = $result->getData();
194 $result = $item->update([
196 'ACCESS_CODE' => $destCodesList
197 ] + (!empty($file) ? [
198 'FILE' => $file] : [])
204 $result = Avatar\Mask\Item::create(
205 new Avatar\
Mask\Owner\User($currentUser->getId()),
209 'ACCESS_CODE' => $destCodesList
212 if ($result->isSuccess())
214 $id = $result->getId();
217 if ($result->isSuccess())
219 $responsePage = static::getList(
220 Avatar\Model\ItemTable::query()
228 if (($groupedItems = $responsePage->getItems())
229 && ($itemsFromOneGroup = reset($groupedItems))
230 && isset($itemsFromOneGroup[
'items'])
231 && ($itemData = reset($itemsFromOneGroup[
'items']))
235 if ($result->isSuccess())
237 [
'item' => $item] = $result->getData();
238 $itemData[
'accessCode'] = Main\UI\EntitySelector\Converter::convertFromFinderCodes($item->getAccessCode());
240 return Response\AjaxJson::createSuccess(
246 return Response\AjaxJson::createError($result->getErrorCollection());
252 if ($result->isSuccess())
255 [
'item' => $item] = $result->getData();
258 if ($result->isSuccess())
260 return Response\AjaxJson::createSuccess(
264 return Response\AjaxJson::createError($result->getErrorCollection());
270 $pageNav->setPageSize($recentlyUsedListSize);
272 return new Response\DataType\Page(
'initialInfo', [
273 'recentlyUsedItems' => static::getRecentlyUsedListAction($pageNav, $currentUser)->getItems(),
274 'systemItems' => static::getSystemListAction($pageNavigation, $currentUser)->getItems(),
275 'myOwnItems' => static::getUserListAction($pageNavigation, $currentUser)->getItems(),
276 'sharedItems' => static::getSharedListAction($pageNavigation, $currentUser)->getItems(),
277 'restMarketInfo' => Main\Loader::includeModule(
'rest') ? [
279 'exportUrl' => Rest\
Configuration\Helper::getInstance()->enabledZipMod() ? Rest\Marketplace\Url::getConfigurationExportElementUrl(
280 UI\Integration\Rest\MaskManifest::CODE,
281 $currentUser->getId()
283 'importUrl' => Rest\Marketplace\Url::getConfigurationImportManifestUrl(
284 UI\Integration\Rest\MaskManifest::CODE
286 'marketUrl' => Rest\Marketplace\Url::getCategoryUrl(
'user_frame')
295 $consumer = Avatar\Mask\Consumer::createFromId($currentUser->getId());
296 if (Avatar\
Mask\Item::getInstance($id)->isReadableBy($consumer))
298 $consumer->useRecentlyMaskId($id);
300 return Response\AjaxJson::createSuccess();
306 return Response\AjaxJson::createSuccess();
getMaskAccessCodeAction($id, Main\Engine\CurrentUser $currentUser)
useRecentlyAction($id, Main\Engine\CurrentUser $currentUser)
getMaskInitialInfoAction($recentlyUsedListSize, PageNavigation $pageNavigation, Main\Engine\CurrentUser $currentUser)
getUserListAction(PageNavigation $pageNavigation, Main\Engine\CurrentUser $currentUser)
getRecentlyUsedListAction(PageNavigation $pageNavigation, Main\Engine\CurrentUser $currentUser)
checkEditability($id, Main\Engine\CurrentUser $currentUser)
cleanUpAction(Main\Engine\CurrentUser $currentUser)
saveAction($id, $title, $accessCode, $file, Main\Engine\CurrentUser $currentUser)
getList(Main\ORM\Query\Query $query, PageNavigation $pageNavigation, Main\Engine\CurrentUser $currentUser)
getSystemListAction(PageNavigation $pageNavigation, Main\Engine\CurrentUser $currentUser)
getSharedListAction(PageNavigation $pageNavigation, Main\Engine\CurrentUser $currentUser)
deleteAction($id, Main\Engine\CurrentUser $currentUser)
static createFromId(int $userId)