Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
FileCollection.php
1<?php
2
4
12use Bitrix\Im\V2\Common\MigrationStatusCheckerTrait;
13use Bitrix\Im\V2\Common\SidebarFilterProcessorTrait;
18
24{
25 use SidebarFilterProcessorTrait;
26 use MigrationStatusCheckerTrait;
27
28 protected static string $migrationOptionName = 'im_link_file_migration';
29
30 public static function getCollectionElementClass(): string
31 {
32 return FileItem::class;
33 }
34
35 public static function find(
36 array $filter = [],
37 array $order = ['ID' => 'DESC'],
38 ?int $limit = null,
39 ?Context $context = null
40 ): self
41 {
42 $context = $context ?? Locator::getContext();
43
44 $fileOrder = ['ID' => 'DESC'];
45
46 if (isset($order['ID']))
47 {
48 $fileOrder['ID'] = $order['ID'];
49 }
50
51 $query = LinkFileTable::query();
52 static::addRightsCheckToQuery($query, $context->getUserId(), ['FILE.ID', 'FILE.CREATED_BY']);
53 $query
54 ->setSelect(['ID', 'DISK_FILE_ID', 'SUBTYPE', 'AUTHOR_ID', 'MESSAGE_ID', 'CHAT_ID', 'DATE_CREATE'])
55 ->setOrder($fileOrder)
56 ;
57 if (isset($limit))
58 {
59 $query->setLimit($limit);
60 }
61 static::processFilters($query, $filter, $fileOrder);
62 $collection = new static($query->fetchCollection());
63 $collection->fillFiles();
64
65 return $collection;
66 }
67
68 public function fillFiles(): FileCollection
69 {
70 $diskFilesIds = $this->getEntityIds();
71
72 $entities = \Bitrix\Im\V2\Entity\File\FileCollection::initByDiskFilesIds($diskFilesIds);
73
74 foreach ($this as $file)
75 {
76 if ($entities->getById($file->getEntityId()) !== null)
77 {
78 $file->setEntity($entities->getById($file->getEntityId()));
79 }
80 }
81
82 return $this;
83 }
84
85 public function getPopupData(array $excludedList = []): PopupData
86 {
87 $data = new PopupData([new UserPopupItem(), new FilePopupItem()], $excludedList);
88
89 return parent::getPopupData($excludedList)->merge($data);
90 }
91
92 public function save(bool $isGroupSave = false): Result
93 {
94 if (!static::isMigrationFinished())
95 {
97 }
98
99 return parent::save($isGroupSave);
100 }
101
102 protected static function processFilters(Query $query, array $filter, array $order): void
103 {
104 static::processSidebarFilters($query, $filter, $order);
105
106 if (isset($filter['SEARCH_FILE_NAME']))
107 {
108 $query->whereLike('FILE.NAME', "{$filter['SEARCH_FILE_NAME']}%");
109 }
110
111 if (isset($filter['SUBTYPE']))
112 {
113 if (is_array($filter['SUBTYPE']))
114 {
115 $subtypes = array_filter($filter['SUBTYPE'], static fn (string $subtype) => FileItem::isSubtypeValid($subtype));
116 $query->whereIn('SUBTYPE', $subtypes);
117 }
118 elseif (FileItem::isSubtypeValid($filter['SUBTYPE']))
119 {
120 $query->where('SUBTYPE', $filter['SUBTYPE']);
121 }
122 }
123 }
124
125 protected static function addRightsCheckToQuery(Query $query, int $userId, array $specificColumns): Query
126 {
127 $securityContext = new \Bitrix\Disk\Security\DiskSecurityContext($userId);
128 $parameters = [];
129 $parameters = \Bitrix\Disk\Driver::getInstance()
130 ->getRightsManager()
131 ->addRightsCheck($securityContext, $parameters, $specificColumns)
132 ;
133
135 $field = $parameters['runtime'][0];
136 $field->configureValueType(Fields\IntegerField::class);
137 $query
138 ->registerRuntimeField($field)
139 ->where('RIGHTS_CHECK', 1);
140
141 return $query;
142 }
143}
registerRuntimeField($name, $fieldInfo=null)
Definition query.php:831
addError(Error $error)
Definition result.php:50