1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LeKoala\Tabulator; |
4
|
|
|
|
5
|
|
|
use LeKoala\ExcelImportExport\ExcelGridFieldExportButton; |
|
|
|
|
6
|
|
|
use SilverStripe\ORM\DataObject; |
7
|
|
|
use SilverStripe\ORM\RelationList; |
8
|
|
|
use SilverStripe\View\ArrayData; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* This component provides a button for exporting data |
12
|
|
|
* Depends on excel-import-export module |
13
|
|
|
*/ |
14
|
|
|
class TabulatorExportButton extends AbstractTabulatorTool |
15
|
|
|
{ |
16
|
|
|
protected $exportFormat = 'xlsx'; |
17
|
|
|
protected $btn; |
18
|
|
|
|
19
|
|
|
public function __construct() |
20
|
|
|
{ |
21
|
|
|
parent::__construct(); |
22
|
|
|
$this->btn = new ExcelGridFieldExportButton(); |
23
|
|
|
$this->btn->setIsLimited(false); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function forTemplate() |
27
|
|
|
{ |
28
|
|
|
$grid = $this->tabulatorGrid; |
29
|
|
|
$singleton = singleton($grid->getModelClass()); |
30
|
|
|
$context = []; |
31
|
|
|
if ($grid->getList() instanceof RelationList) { |
32
|
|
|
$record = $grid->getForm()->getRecord(); |
33
|
|
|
if ($record && $record instanceof DataObject) { |
|
|
|
|
34
|
|
|
$context['Parent'] = $record; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if (!$singleton->canCreate(null, $context)) { |
39
|
|
|
return false; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if (!$this->buttonName) { |
43
|
|
|
// provide a default button name, can be changed by calling {@link setButtonName()} on this component |
44
|
|
|
$this->buttonName = _t('Tabulator.ExportRecords', 'Export'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$data = new ArrayData([ |
48
|
|
|
'ButtonName' => $this->buttonName, |
49
|
|
|
'ButtonClasses' => 'btn-secondary font-icon-export no-ajax', |
50
|
|
|
'Icon' => $this->isAdmini() ? 'list_alt' : '', |
51
|
|
|
]); |
52
|
|
|
return $this->renderWith($this->getViewerTemplates(), $data); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getButton(): ExcelGridFieldExportButton |
56
|
|
|
{ |
57
|
|
|
return $this->btn; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function index() |
61
|
|
|
{ |
62
|
|
|
return $this->btn->handleExport($this->tabulatorGrid); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the value of exportFormat |
67
|
|
|
*/ |
68
|
|
|
public function getExportFormat(): mixed |
69
|
|
|
{ |
70
|
|
|
return $this->exportFormat; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Set the value of exportFormat |
75
|
|
|
* |
76
|
|
|
* @param mixed $exportFormat |
77
|
|
|
*/ |
78
|
|
|
public function setExportFormat($exportFormat): self |
79
|
|
|
{ |
80
|
|
|
$this->exportFormat = $exportFormat; |
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths