Passed
Push — master ( 921397...8beaa4 )
by Thomas
11:40 queued 13s
created

TabulatorExportButton::getExportFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace LeKoala\Tabulator;
4
5
use LeKoala\ExcelImportExport\ExcelGridFieldExportButton;
0 ignored issues
show
Bug introduced by
The type LeKoala\ExcelImportExpor...elGridFieldExportButton was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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) {
0 ignored issues
show
introduced by
$record is always a sub-type of SilverStripe\ORM\DataObject.
Loading history...
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);
0 ignored issues
show
Bug introduced by
$data of type SilverStripe\View\ArrayData is incompatible with the type array expected by parameter $customFields of SilverStripe\View\ViewableData::renderWith(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
        return $this->renderWith($this->getViewerTemplates(), /** @scrutinizer ignore-type */ $data);
Loading history...
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