1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Uccello\Core\Http\Controllers\Core; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Uccello\Core\Exports\RecordsExport; |
7
|
|
|
use Uccello\Core\Models\Domain; |
8
|
|
|
use Uccello\Core\Models\Module; |
9
|
|
|
|
10
|
|
|
class ExportController extends Controller |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Check user permissions |
14
|
|
|
*/ |
15
|
|
|
protected function checkPermissions() |
16
|
|
|
{ |
17
|
|
|
$this->middleware('uccello.permissions:retrieve'); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @inheritDoc |
22
|
|
|
*/ |
23
|
|
|
public function process(?Domain $domain, Module $module, Request $request) |
24
|
|
|
{ |
25
|
|
|
// Pre-process |
26
|
|
|
$this->preProcess($domain, $module, $request); |
27
|
|
|
|
28
|
|
|
// File name |
29
|
|
|
$fileName = uctrans($module->name, $module).'_'.date('Ymd_His'); |
|
|
|
|
30
|
|
|
|
31
|
|
|
// File extension |
32
|
|
|
$fileExtension = $request->input('extension') ?? 'xlsx'; |
33
|
|
|
|
34
|
|
|
// Use special format for pdf file |
35
|
|
|
$specialFormat = $fileExtension === 'pdf' ? \Maatwebsite\Excel\Excel::MPDF : null; |
|
|
|
|
36
|
|
|
|
37
|
|
|
// Init export |
38
|
|
|
$export = (new RecordsExport) |
39
|
|
|
->forDomain($domain) |
40
|
|
|
->forModule($module); |
41
|
|
|
|
42
|
|
|
// With ID |
43
|
|
|
if ($request->input('with_id') === '1') { |
44
|
|
|
$export = $export->withId(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// With timestamps |
48
|
|
|
if ($request->input('with_timestamps') === '1') { |
49
|
|
|
$export = $export->withTimestamps(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// With descendants |
53
|
|
|
if ($request->input('with_descendants') === '1') { |
54
|
|
|
$export = $export->withDescendants(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// With hidden columns |
58
|
|
|
if ($request->input('with_hidden_columns') !== '1') { |
59
|
|
|
$columns = json_decode($request->input('columns')); |
60
|
|
|
$export = $export->withColumns($columns); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// With conditions |
64
|
|
|
if ($request->input('with_conditions') === '1') { |
65
|
|
|
// TODO: Build $conditions['search'] earlier in the export process to match filter format... |
66
|
|
|
$conditions = ['search' => json_decode($request->input('conditions'))]; |
67
|
|
|
$export = $export->withConditions($conditions); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// With order |
71
|
|
|
if ($request->input('with_order') === '1') { |
72
|
|
|
$order = json_decode($request->input('order')); |
73
|
|
|
$export = $export->withOrder($order); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
// Export records |
77
|
|
|
return $export->download($fileName.'.'.$fileExtension, $specialFormat); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.