Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
dataexport.php
1<?php
9
11
17{
26 public static function toCsv(array $columns, $list, $rowCallback = null)
27 {
29
30 $eol = "\n";
31 $columnNames = [];
32 $isFirstLinePrinted = false;
33
34 if (defined('BX_UTF') && BX_UTF)
35 {
36 echo chr(239) . chr(187) . chr(191);
37 }
38
39 foreach ($list as $item)
40 {
41 if ($rowCallback)
42 {
43 $item = call_user_func_array($rowCallback, [$item]);
44 }
45
46 $row = [];
47 foreach ($columns as $column)
48 {
49 if (!array_key_exists($column['id'], $item))
50 {
51 continue;
52 }
53
54 if (!$isFirstLinePrinted)
55 {
56 $columnNames[] = str_replace('"', '""', $column['name']);
57 }
58
59 $row[] = str_replace('"', '""', trim($item[$column['id']]));
60 }
61
62 if (!$isFirstLinePrinted)
63 {
64 echo '"' . implode('";"', $columnNames) . '"';
65 $isFirstLinePrinted = true;
66 }
67 echo $eol;
68 echo '"' . implode('";"', $row) . '"';
69 }
70
71 exit;
72 }
73
74 protected static function flushHeaders()
75 {
76 $GLOBALS['APPLICATION']->RestartBuffer();
77
78 header('Content-Description: File Transfer');
79 header('Content-Type: text/csv; charset='.LANG_CHARSET);
80 header('Content-Disposition: attachment; filename=address_list.csv');
81 header('Content-Transfer-Encoding: binary');
82 header('Expires: 0');
83 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
84 header('Pragma: public');
85 }
86}
static toCsv(array $columns, $list, $rowCallback=null)
$GLOBALS['____1444769544']
Definition license.php:1