Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
FileCollection.php
1<?php
2
4
5use Bitrix\Disk\File;
6use Bitrix\Disk\Driver;
7use Bitrix\Disk\Internals\FileTable;
8use Bitrix\Disk\Storage;
9use Bitrix\Im\Model\EO_FileTemporary;
10use Bitrix\Im\Model\EO_FileTemporary_Collection;
17
23{
28 public function __construct(?array $diskFiles = null, ?int $chatId = null)
29 {
30 parent::__construct();
31
32 if ($diskFiles !== null)
33 {
34 foreach ($diskFiles as $diskFile)
35 {
36 $this[] = new FileItem($diskFile, $chatId);
37 }
38 }
39 }
40
41 public static function getRestEntityName(): string
42 {
43 return 'files';
44 }
45
51 public static function initByDiskFilesIds(array $diskFilesIds, ?int $chatId = null): self
52 {
53 if (empty($diskFilesIds) || !Loader::includeModule('disk'))
54 {
55 return new static();
56 }
57
58 $diskFiles = File::getModelList([
59 'filter' => Query::filter()->whereIn('ID', $diskFilesIds)->where('TYPE', FileTable::TYPE)
60 ]);
61
62 return new static($diskFiles, $chatId);
63 }
64
65 public function getCopies(?Storage $storage = null): self
66 {
67 $userId = $this->getContext()->getUserId();
68 $storage = $storage ?? Driver::getInstance()->getStorageByUserId($userId);
69 $copies = new static();
70
71 foreach ($this as $fileEntity)
72 {
73 $copy = $fileEntity->getCopy($storage);
74 if ($copy !== null)
75 {
76 $copies[] = $copy;
77 }
78 }
79
80 return $copies;
81 }
82
83 public function addToTmp(string $source): Result
84 {
85 $tmpCollection = new EO_FileTemporary_Collection();
86
87 foreach ($this as $file)
88 {
89 $tmpEntity = new EO_FileTemporary(['DISK_FILE_ID' => $file->getId(), 'SOURCE' => $source]);
90 $tmpCollection->add($tmpEntity);
91 }
92
93 $addResult = $tmpCollection->save(true);
94
95 if (!$addResult->isSuccess())
96 {
97 return (new Result())->addErrors($addResult->getErrors());
98 }
99
100 return new Result();
101 }
102
103 public function getFileDiskAttributes(int $chatId, array $options = []): array
104 {
105 $resultData = [];
106 foreach ($this as $file)
107 {
108 $resultData[$file->getDiskFileId()] = \CIMDisk::GetFileParams($chatId, $file->getDiskFile(), $options = []);
109 }
110
111 return $resultData;
112 }
113
114 public function getPopupData(array $excludedList = []): PopupData
115 {
116 $data = new PopupData([new UserPopupItem()], $excludedList);
117
118 return parent::getPopupData($excludedList)->merge($data);
119 }
120}
getFileDiskAttributes(int $chatId, array $options=[])
__construct(?array $diskFiles=null, ?int $chatId=null)
static initByDiskFilesIds(array $diskFilesIds, ?int $chatId=null)