Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
excelexporter.php
1
<?php
2
3
namespace
Bitrix\Main\Grid\Export
;
4
5
use
Bitrix\Main\Context
;
6
use
Bitrix\Main\Grid\Component\ComponentParams
;
7
use
Bitrix\Main\Grid\Grid
;
8
use
Bitrix\Main\Grid\Settings
;
9
use
Bitrix\Main\HttpRequest
;
10
use
Bitrix\Main\Localization\Loc
;
11
use
Bitrix\Main\Web\Uri
;
12
use
Bitrix\UI\Buttons\BaseButton
;
13
14
final
class
ExcelExporter
15
{
16
public
const
REQUEST_PARAM_NAME
=
'mode'
;
17
public
const
REQUEST_PARAM_VALUE
=
'excel'
;
18
19
public
function
isExportRequest
(?
HttpRequest
$request =
null
): bool
20
{
21
$request ??=
Context::getCurrent
()->getRequest();
22
23
return
$request->get(self::REQUEST_PARAM_NAME) ===
self::REQUEST_PARAM_VALUE
;
24
}
25
26
public
function
getControl(?
HttpRequest
$request =
null
):
BaseButton
27
{
31
$request ??=
Context::getCurrent
()->getRequest();
32
33
$uri =
new
Uri
($request->getRequestUri());
34
$uri->addParams([
35
self::REQUEST_PARAM_NAME => self::REQUEST_PARAM_VALUE,
36
// for disable composite
37
'ncc'
=> 1,
38
]);
39
40
$button =
new
BaseButton
();
41
$button->setLink((
string
)$uri);
42
$button->setText(
Loc::getMessage
(
'MAIN_GRID_EXPORT_EXCEL_BUTTON_TEXT'
));
43
44
return
$button;
45
}
46
47
public
function
process(
Grid
$grid,
string
$fileName =
'export'
): void
48
{
49
global $APPLICATION;
50
55
$APPLICATION->RestartBuffer();
56
57
$grid->
getSettings
()->setMode(
Settings::MODE_EXCEL
);
58
59
try
60
{
61
ob_start();
62
$APPLICATION->IncludeComponent(
63
'bitrix:main.ui.grid'
,
64
'excel'
,
65
ComponentParams::get
($grid)
66
);
67
$content = ob_get_contents();
68
}
69
finally
70
{
71
ob_end_clean();
72
}
73
74
header(
'Content-Type: application/vnd.ms-excel'
);
75
header(
'Content-Disposition: filename="'
. $fileName .
'.xls"'
);
76
77
echo $content;
78
79
die();
80
}
81
}
Bitrix\Main\Context\getCurrent
static getCurrent()
Definition
context.php:241
Bitrix\Main\Grid\Component\ComponentParams
Definition
componentparams.php:11
Bitrix\Main\Grid\Component\ComponentParams\get
static get(Grid $grid, array $additionParams=[])
Definition
componentparams.php:19
Bitrix\Main\Grid\Export\ExcelExporter
Definition
excelexporter.php:15
Bitrix\Main\Grid\Export\ExcelExporter\REQUEST_PARAM_NAME
const REQUEST_PARAM_NAME
Definition
excelexporter.php:16
Bitrix\Main\Grid\Export\ExcelExporter\isExportRequest
isExportRequest(?HttpRequest $request=null)
Definition
excelexporter.php:19
Bitrix\Main\Grid\Export\ExcelExporter\REQUEST_PARAM_VALUE
const REQUEST_PARAM_VALUE
Definition
excelexporter.php:17
Bitrix\Main\Grid\Grid
Definition
grid.php:74
Bitrix\Main\Grid\Grid\getSettings
getSettings()
Definition
grid.php:120
Bitrix\Main\Grid\Settings
Definition
settings.php:8
Bitrix\Main\Grid\Settings\MODE_EXCEL
const MODE_EXCEL
Definition
settings.php:10
Bitrix\Main\HttpRequest
Definition
httprequest.php:20
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Web\Uri
Definition
uri.php:17
Bitrix\UI\Buttons\BaseButton
Definition
basebutton.php:17
Bitrix\Main\Context
Definition
culture.php:9
Bitrix\Main\Grid\Export
Definition
excelexporter.php:3
modules
main
lib
grid
export
excelexporter.php
Создано системой
1.10.0