Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
MaskImportApp.php
1<?php
3
5use Bitrix\UI\Avatar;
7
9{
10 protected int $ownerId;
11 private int $groupId;
13
14 public function init($event): void
15 {
16 $this->ownerId = (int) $event->getParameter('APP_ID');
17 if ($this->ownerId <= 0)
18 {
19 $this->errorCollection->setError(new Error('Application id is not set.'));
20 return;
21 }
22
23 if (!($app = Rest\AppTable::getById($this->ownerId)->fetch()))
24 {
25 $this->errorCollection->setError(new Error('Application is not found.'));
26 return;
27 }
28
29 $this->owner = new Avatar\Mask\Owner\RestApp($this->ownerId);
30
31 if ($group = Avatar\Mask\GroupTable::getList([
32 'select' => ['ID'],
33 'filter' => [
34 '=OWNER_TYPE' => Avatar\Mask\Owner\RestApp::class,
35 '=OWNER_ID' => $this->ownerId,
36 ]
37 ])->fetch())
38 {
39 $this->groupId = $group['ID'];
40 }
41 else
42 {
43 $this->groupId = Avatar\Mask\Group::createOrGet($this->owner, $app['APP_NAME'])->getId();
44 }
45 }
46
47 public function makeAStep(): void
48 {
49 foreach ($this->data as $res)
50 {
51 $fileInfo = $this->structure->getUnpackFile((int)$res['FILE_ID']);
52 $file = !empty($fileInfo['PATH']) ? \CFile::makeFileArray($fileInfo['PATH']) : null;
53 $file['name'] = $fileInfo['NAME'];
54 if ($file)
55 {
56 $result = Avatar\Mask\Item::create(
57 $this->owner,
58 $file,
59 [
60 'TITLE' => $res['TITLE'],
61 'DESCRIPTION' => $res['DESCRIPTION'],
62 'GROUP_ID' => $this->groupId,
63 'ACCESS_CODE' => $this->owner->getDefaultAccess()
64 ]
65 );
66 if (!$result->isSuccess())
67 {
68 $this->errorCollection->add($result->getErrors());
69 }
70 }
71 }
72 }
73}
Avatar Mask Owner DefaultOwner $owner