Repository navigation
Expand file tree
/
Copy pathSettingsController.php
More file actions
71 lines (61 loc) · 1.75 KB
/
Copy pathSettingsController.php
File metadata and controls
71 lines (61 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace ProcessMaker\Http\Controllers\Admin;
use Illuminate\Http\Request;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\Models\Setting;
use ProcessMaker\Traits\HasControllerAddons;
class SettingsController extends Controller
{
use HasControllerAddons;
/**
* Get the list of settings.
*
* @return Factory|View
*/
public function index()
{
if (Setting::notHidden()->count()) {
$addons = $this->getPluginAddons('index', []);
return view('admin.settings.index', compact('addons'));
} else {
abort(404);
}
}
/**
* Download an exported JSON file of settings.
*
* @return Factory|View
*/
public function export(Request $request)
{
$query = Setting::query();
$group = $request->input('group');
if (!empty($group)) {
if ($group === 'System') {
$fileName = 'System.json';
$query->whereNull('group');
} else {
$fileName = "{$group}.json";
$query->where('group', $group);
}
} else {
$fileName = 'Settings.json';
}
$settings = $query->get()->toArray();
$file = [
'type' => 'settings_package',
'version' => '1',
'settings' => array_map(function ($setting) {
return [
'key' => $setting['key'],
'config' => $setting['config'],
];
}, $settings),
];
return response()->streamDownload(function () use ($file) {
echo json_encode($file);
}, $fileName, [
'Content-type' => 'application/json',
]);
}
}