1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
FileCollection.php
См. документацию.
1<?php
2
4
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 static function getByDiskFileId(int $diskFileId): self
69 {
70 $entity = LinkFileTable::query()
71 ->setSelect(['ID', 'MESSAGE_ID', 'CHAT_ID', 'SUBTYPE', 'DISK_FILE_ID', 'DATE_CREATE', 'AUTHOR_ID'])
72 ->where('DISK_FILE_ID', $diskFileId)
73 ->fetchCollection()
74 ;
75
76 return (new static($entity))->fillFiles();
77 }
78
79 public static function getByMessageIds(array $messageIds): self
80 {
81 $messageIds = array_map('intval', $messageIds);
82
83 if (empty($messageIds))
84 {
85 return new self();
86 }
87
88 $entities = LinkFileTable::query()
89 ->setSelect(['ID', 'MESSAGE_ID', 'CHAT_ID', 'SUBTYPE', 'DISK_FILE_ID', 'DATE_CREATE', 'AUTHOR_ID'])
90 ->whereIn('MESSAGE_ID', $messageIds)
91 ->fetchCollection()
92 ;
93
94 return new self($entities);
95 }
96
97 public function fillFiles(): FileCollection
98 {
99 $diskFilesIds = $this->getEntityIds();
100
102
103 foreach ($this as $file)
104 {
105 if ($entities->getById($file->getEntityId()) !== null)
106 {
107 $file->setEntity($entities->getById($file->getEntityId()));
108 }
109 }
110
111 return $this;
112 }
113
114 public function getPopupData(array $excludedList = []): PopupData
115 {
116 $data = new PopupData([new UserPopupItem(), new FilePopupItem()], $excludedList);
117
118 return parent::getPopupData($excludedList)->merge($data);
119 }
120
121 public function save(bool $isGroupSave = false): Result
122 {
123 if (!static::isMigrationFinished())
124 {
125 return (new Result())->addError(new FileError(FileError::SAVE_BEFORE_MIGRATION_ERROR));
126 }
127
128 return parent::save($isGroupSave);
129 }
130
131 protected static function processFilters(Query $query, array $filter, array $order): void
132 {
133 static::processSidebarFilters($query, $filter, $order);
134
135 if (isset($filter['SEARCH_FILE_NAME']))
136 {
137 $query->whereLike('FILE.NAME', "{$filter['SEARCH_FILE_NAME']}%");
138 }
139
140 $subtypes = [];
141
142 if (isset($filter['SUBTYPE']))
143 {
144 $subtypes = Subtype::getSubtypeFilter($filter['SUBTYPE']);
145 }
146 elseif (isset($filter['GROUP']))
147 {
148 $subtypes = SubtypeGroup::getSubtypeFilter($filter['GROUP']);
149 }
150
151 if (count($subtypes) > 1)
152 {
153 $query->whereIn('SUBTYPE', $subtypes);
154 }
155 elseif (count($subtypes) === 1)
156 {
157 $query->where('SUBTYPE', array_values($subtypes)[0]);
158 }
159 }
160
161 protected static function addRightsCheckToQuery(Query $query, int $userId, array $specificColumns): Query
162 {
163 $securityContext = new \Bitrix\Disk\Security\DiskSecurityContext($userId);
164 $parameters = [];
165 $parameters = \Bitrix\Disk\Driver::getInstance()
166 ->getRightsManager()
167 ->addRightsCheck($securityContext, $parameters, $specificColumns)
168 ;
169
171 $field = $parameters['runtime'][0];
172 $field->configureValueType(Fields\IntegerField::class);
173 $query
174 ->registerRuntimeField($field)
175 ->where('RIGHTS_CHECK', 1);
176
177 return $query;
178 }
179}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static initByDiskFilesIds(array $diskFilesIds, ?int $chatId=null)
Определения FileCollection.php:57
const SAVE_BEFORE_MIGRATION_ERROR
Определения FileError.php:18
Определения result.php:20
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
$entity
$filter
Определения iblock_catalog_list.php:54
$context
Определения csv_new_setup.php:223
trait MigrationStatusCheckerTrait
Определения MigrationStatusCheckerTrait.php:8
Определения culture.php:9
Определения chain.php:3
$order
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936