1 | <?php |
||
24 | class XlsHandler |
||
25 | { |
||
26 | /** |
||
27 | * Instance of the project. |
||
28 | * |
||
29 | * @var Project |
||
30 | */ |
||
31 | protected $project; |
||
32 | |||
33 | /** |
||
34 | * Collection of project issues. |
||
35 | * |
||
36 | * @var Project\Issue[] |
||
37 | */ |
||
38 | protected $issues; |
||
39 | |||
40 | /** |
||
41 | * Columns to export from the issues table. |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $columns = [ |
||
46 | 'id' => '', |
||
47 | 'title' => '', |
||
48 | 'time_quote' => '', |
||
49 | 'created_at' => '', |
||
50 | 'updated_at' => '', |
||
51 | 'closed_at' => '', |
||
52 | 'status' => '', |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * Columns in the output file. |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $header = [ |
||
61 | 'tinyissue.id', |
||
62 | 'tinyissue.title', |
||
63 | 'tinyissue.time_quote', |
||
64 | 'tinyissue.label_created', |
||
65 | 'tinyissue.updated', |
||
66 | 'tinyissue.label_closed', |
||
67 | 'tinyissue.status', |
||
68 | ]; |
||
69 | |||
70 | /** |
||
71 | * Set an instance of a project model. |
||
72 | * |
||
73 | * @param Project $project |
||
74 | * |
||
75 | * @return $this |
||
76 | */ |
||
77 | public function setProject(Project $project) |
||
78 | { |
||
79 | $this->project = $project; |
||
80 | |||
81 | return $this; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param Exporter $exporter |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | public function handle(Exporter $exporter) |
||
90 | { |
||
91 | $params = $exporter->getParams(); |
||
92 | |||
93 | $this->setProject($exporter->getParams('route.project')); |
||
|
|||
94 | |||
95 | $query = $this->project->issues()->select(array_keys($this->columns)); |
||
96 | |||
97 | // Filter issues |
||
98 | $this->project->filterTitleOrBody($query, $params['keyword']); |
||
99 | $this->project->filterAssignTo($query, $params['keyword']); |
||
100 | $this->project->filterTitleOrBody($query, $params['keyword']); |
||
101 | |||
102 | // Fetch issues |
||
103 | $this->issues = $query->get(); |
||
104 | |||
105 | // Create CSV file |
||
106 | $exporter->sheet($this->project->name, function (LaravelExcelWorksheet $sheet) { |
||
107 | |||
108 | // Global sheet styles |
||
109 | $this->globalStyle($sheet); |
||
110 | |||
111 | // Title |
||
112 | $sheet->mergeCells('A1:G1'); |
||
113 | $sheet->setHeight(1, 50); |
||
1 ignored issue
–
show
|
|||
114 | $sheet->cell('A1', function (CellWriter $cell) { |
||
115 | $this->sheetTitle($cell); |
||
116 | }); |
||
117 | |||
118 | // Header |
||
119 | $sheet->row(2, array_map('trans', $this->header)); |
||
120 | |||
121 | // Rows |
||
122 | $index = 3; |
||
123 | foreach ($this->issues as $issue) { |
||
124 | $this->sheetRow($sheet, $index, $issue); |
||
125 | ++$index; |
||
126 | } |
||
127 | }); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Setup sheet global styles. |
||
132 | * |
||
133 | * @param LaravelExcelWorksheet $sheet |
||
134 | * |
||
135 | * @return void |
||
136 | */ |
||
137 | protected function globalStyle(LaravelExcelWorksheet $sheet) |
||
138 | { |
||
139 | // Font size & family |
||
140 | $sheet->setFontSize(15); |
||
141 | $sheet->setFontFamily('Calibri'); |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * Sheet title in the first row. |
||
146 | * |
||
147 | * @param CellWriter $cell |
||
148 | * |
||
149 | * @return void |
||
150 | */ |
||
151 | public function sheetTitle(CellWriter $cell) |
||
152 | { |
||
153 | $cell->setFontWeight('bold'); |
||
154 | $cell->setBorder('none', 'none', 'none', 'thin'); |
||
155 | $title = trans('tinyissue.export_xls_title', ['name' => $this->project->name, 'count' => count($this->issues)]); |
||
156 | $cell->setValue($title); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Sheet data row. |
||
161 | * |
||
162 | * @param LaravelExcelWorksheet $sheet |
||
163 | * @param int $index |
||
164 | * @param Project\Issue $issue |
||
165 | * |
||
166 | * @return void |
||
167 | */ |
||
168 | protected function sheetRow(LaravelExcelWorksheet $sheet, $index, Project\Issue $issue) |
||
188 | } |
||
189 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: