1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
filefieldassembler.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Iblock\Grid\Row\Assembler\Property;
4
5
use Bitrix\Iblock\Grid\Column\ElementPropertyProvider;
6
use Bitrix\Iblock\PropertyTable;
7
use Bitrix\Main\Grid\Row\FieldAssembler;
8
use Bitrix\Main\Loader;
9
use CFile;
10
use CFileInput;
11
12
final
class
FileFieldAssembler
extends
FieldAssembler
13
{
14
private
int
$iblockId;
15
private
array
$files;
16
17
public
function
__construct
(
int
$iblockId)
18
{
19
$this->iblockId = $iblockId;
20
21
parent::__construct(
22
$this->getPropertyColumnsIds()
23
);
24
}
25
26
private
function
getPropertyColumnsIds():
array
27
{
28
$result
= [];
29
30
$rows
=
PropertyTable::getList
([
31
'select'
=> [
32
'ID'
,
33
],
34
'filter'
=> [
35
'=IBLOCK_ID'
=> $this->iblockId,
36
'=PROPERTY_TYPE'
=>
PropertyTable::TYPE_FILE
,
37
'USER_TYPE'
=>
null
,
38
],
39
]);
40
foreach
(
$rows
as $row)
41
{
42
$result
[] = ElementPropertyProvider::getColumnIdByPropertyId((
int
)$row[
'ID'
]);
43
}
44
45
return
$result
;
46
}
47
48
public
function
prepareRows
(
array
$rowList
):
array
49
{
50
if
(empty($this->
getColumnIds
()))
51
{
52
return
$rowList;
53
}
54
55
$fileIds = [];
56
foreach
(
$rowList
as $row)
57
{
58
foreach
($this->
getColumnIds
() as $columnId)
59
{
60
$value = $row[
'data'
][$columnId] ??
null
;
61
if
(is_array($value))
62
{
63
foreach
($value as $valueItem)
64
{
65
$fileIds[] = (int)$valueItem;
66
}
67
}
68
elseif
(isset($value))
69
{
70
$fileIds[] = (int)$value;
71
}
72
}
73
}
74
75
if
(empty($fileIds))
76
{
77
return
$rowList
;
78
}
79
80
$this->preloadFiles($fileIds);
81
82
return
parent::prepareRows(
$rowList
);
83
}
84
85
protected
function
prepareRow
(
array
$row):
array
86
{
87
$row[
'columns'
] ??= [];
88
89
foreach
($this->
getColumnIds
() as $columnId)
90
{
91
$value = $row[
'data'
][$columnId] ??
null
;
92
if
($value !==
null
|| is_array($value))
93
{
94
// edit
95
$row[
'data'
][
'~'
. $columnId] ??= $this->getDataForEdit($value);
96
97
// view
98
$row[
'columns'
][$columnId] ??= $this->getImageHtml($columnId, $value);
99
}
100
}
101
102
return
$row;
103
}
104
113
private
function
getImageHtml(
string
$columnId, $value): string
114
{
115
if
(
Loader::includeModule
(
'fileman'
))
116
{
117
return
CFileInput::Show(
118
''
,
119
$value,
120
[
121
'IMAGE'
=>
'Y'
,
122
'IMAGE_POPUP'
=>
'N'
,
123
'PATH'
=>
'N'
,
124
'FILE_SIZE'
=>
'N'
,
125
'DIMENSIONS'
=>
'N'
,
126
'MAX_SIZE'
=> [
127
'W'
=> 50,
128
'H'
=> 50,
129
],
130
'MIN_SIZE'
=> [
131
'W'
=> 1,
132
'H'
=> 1,
133
],
134
],
135
[
136
'upload'
=>
false
,
137
'medialib'
=>
false
,
138
'file_dialog'
=>
false
,
139
'cloud'
=>
false
,
140
'del'
=>
false
,
141
'description'
=>
false
,
142
]
143
);
144
}
145
146
global
$APPLICATION
;
147
151
152
try
153
{
154
ob_start();
155
156
$APPLICATION
->IncludeComponent(
'bitrix:main.file.input'
,
''
, [
157
'MODULE_ID'
=>
'catalog'
,
158
'MULTIPLE'
=>
'Y'
,
159
'ALLOW_UPLOAD'
=>
'N'
,
160
'INPUT_NAME'
=> $columnId,
161
'INPUT_VALUE'
=> $value,
162
]);
163
164
return
ob_get_contents();
165
}
166
finally
167
{
168
ob_end_clean();
169
}
170
}
171
172
private
function
getFileSrc(
int
$fileId): ?string
173
{
174
$file = $this->files[$fileId] ??
null
;
175
if
($file)
176
{
177
return
CFile::GetFileSRC($file);
178
}
179
180
return
null
;
181
}
182
183
private
function
getDataForEdit($value)
184
{
185
if
(is_array($value))
186
{
187
$result
= [];
188
189
foreach
($value as $valueItem)
190
{
191
$result
[] = $this->getFileSrc((
int
)$valueItem);
192
}
193
194
return
$result
;
195
}
196
elseif
(isset($value))
197
{
198
return
$this->getFileSrc((
int
)$value);
199
}
200
201
return
null
;
202
}
203
204
private
function
preloadFiles(
array
$fileIds): void
205
{
206
$this->files = [];
207
208
if
(empty($fileIds))
209
{
210
return
;
211
}
212
213
$rows
=
CFile::GetList
([], [
214
'@ID'
=> $fileIds,
215
]);
216
while
($row =
$rows
->Fetch())
217
{
218
$this->files[$row[
'ID'
]] = $row;
219
}
220
}
221
}
$APPLICATION
global $APPLICATION
Определения
include.php:80
Bitrix\Iblock\Grid\Row\Assembler\Property\FileFieldAssembler
Определения
filefieldassembler.php:13
Bitrix\Iblock\Grid\Row\Assembler\Property\FileFieldAssembler\prepareRows
prepareRows(array $rowList)
Определения
filefieldassembler.php:48
Bitrix\Iblock\Grid\Row\Assembler\Property\FileFieldAssembler\__construct
__construct(int $iblockId)
Определения
filefieldassembler.php:17
Bitrix\Iblock\Grid\Row\Assembler\Property\FileFieldAssembler\prepareRow
prepareRow(array $row)
Определения
filefieldassembler.php:85
Bitrix\Iblock\PropertyTable\TYPE_FILE
const TYPE_FILE
Определения
propertytable.php:67
Bitrix\Main\Grid\Row\FieldAssembler
Определения
fieldassembler.php:25
Bitrix\Main\Grid\Row\FieldAssembler\getColumnIds
getColumnIds()
Определения
fieldassembler.php:47
Bitrix\Main\Loader\includeModule
static includeModule($moduleName)
Определения
loader.php:67
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Определения
datamanager.php:431
CFile\GetList
static GetList($arOrder=[], $arFilter=[])
Определения
file.php:1069
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
$rowList
$rowList
Определения
iblock_catalog_list.php:273
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$rows
$rows
Определения
options.php:264
bitrix
modules
iblock
lib
grid
row
assembler
property
filefieldassembler.php
Создано системой
1.14.0