Completed
Pull Request — master (#201)
by
unknown
02:10
created

ExcelExport   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 56
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDate() 0 4 1
A getBaseName() 0 4 1
A setBaseName() 0 5 1
A setDate() 0 5 1
A initialize() 0 10 2
1
<?php
2
3
namespace Nayjest\Grids\Components;
4
5
use App\Jobs\ExportExcel;
6
use Event;
7
use Nayjest\Grids\Components\Base\RenderableComponent;
8
use Nayjest\Grids\Grid;
9
10
class ExcelExport extends RenderableComponent
11
{
12
    private $baseName;
13
    private $date;
14
    private $config;
15
16
    const NAME = 'excel_export';
17
    protected $template = '*.components.excel_export';
18
19
    const INPUT_PARAM = 'xlsx';
20
21
    /**
22
     * @return mixed
23
     */
24
    public function getDate()
25
    {
26
        return $this->date;
27
    }
28
29
    /**
30
     * @return mixed
31
     */
32
    public function getBaseName()
33
    {
34
        return $this->baseName;
35
    }
36
37
    /**
38
     * @param mixed $baseName
39
     */
40
    public function setBaseName($baseName)
41
    {
42
        $this->baseName = $baseName;
43
        return $this;
44
    }
45
46
    /**
47
     * @param mixed $date
48
     */
49
    public function setDate($date)
50
    {
51
        $this->date = $date;
52
        return $this;
53
    }
54
55
    public function initialize(Grid $grid)
56
    {
57
        parent::initialize($grid);
58
        Event::listen(Grid::EVENT_PREPARE, function (Grid $grid) {
59
        $this->config = $grid->getConfig();
60
            if ($grid->getInputProcessor()->getValue(static::INPUT_PARAM, false)) {
61
                dispatch(new ExportExcel($this->getDate(), $this->getBaseName(), $this->config));
62
            }
63
        });
64
    }
65
}