|
1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* RedirectController |
|
5
|
|
|
* |
|
6
|
|
|
* This is the controller of the redirects of the shop |
|
7
|
|
|
* @author Matthijs Neijenhuijs <[email protected]> |
|
8
|
|
|
* @version 0.1 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
use App\Http\Controllers\Controller; |
|
12
|
|
|
use Hideyo\Ecommerce\Framework\Services\Redirect\RedirectFacade as RedirectService; |
|
13
|
|
|
use Hideyo\Ecommerce\Framework\Services\Shop\ShopFacade as ShopService; |
|
14
|
|
|
use Illuminate\Http\Request; |
|
15
|
|
|
use Excel; |
|
|
|
|
|
|
16
|
|
|
use DataTables; |
|
17
|
|
|
|
|
18
|
|
|
class RedirectController extends Controller |
|
19
|
|
|
{ |
|
20
|
|
|
public function index(Request $request) |
|
21
|
|
|
{ |
|
22
|
|
|
if ($request->wantsJson()) { |
|
23
|
|
|
$query = RedirectService::selectAll(); |
|
24
|
|
|
$datatables = DataTables::of($query) |
|
25
|
|
|
|
|
26
|
|
|
->addColumn('url', function ($query) { |
|
27
|
|
|
return '<a href="'.$query->url.'" target="_blank">'.$query->url.'</a>'; |
|
28
|
|
|
}) |
|
29
|
|
|
|
|
30
|
|
|
->addColumn('action', function ($query) { |
|
31
|
|
|
$deleteLink = \Form::deleteajax(url()->route('redirect.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger')); |
|
32
|
|
|
$links = '<a href="'.url()->route('redirect.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> '.$deleteLink; |
|
33
|
|
|
|
|
34
|
|
|
return $links; |
|
35
|
|
|
}); |
|
36
|
|
|
|
|
37
|
|
|
return $datatables->make(true); |
|
38
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return view('backend.redirect.index')->with('redirect', RedirectService::selectAll()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function create() |
|
45
|
|
|
{ |
|
46
|
|
|
$shops = ShopService::selectAll()->pluck('title', 'id')->toArray(); |
|
47
|
|
|
return view('backend.redirect.create')->with(array('shops' => $shops)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function store() |
|
51
|
|
|
{ |
|
52
|
|
|
$result = RedirectService::create($request->all()); |
|
|
|
|
|
|
53
|
|
|
return RedirectService::notificationRedirect('redirect.index', $result, 'The redirect was inserted.'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function edit($redirectId) |
|
57
|
|
|
{ |
|
58
|
|
|
$shops = ShopService::selectAll()->pluck('title', 'id'); |
|
59
|
|
|
return view('backend.redirect.edit')->with(array( |
|
60
|
|
|
'redirect' => RedirectService::find($redirectId), |
|
61
|
|
|
'shops' => $shops |
|
62
|
|
|
)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getImport() |
|
66
|
|
|
{ |
|
67
|
|
|
return view('backend.redirect.import')->with(array()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function postImport() |
|
71
|
|
|
{ |
|
72
|
|
|
$file = $request->file('file'); |
|
|
|
|
|
|
73
|
|
|
Excel::load($file, function ($reader) { |
|
74
|
|
|
|
|
75
|
|
|
$results = $reader->get(); |
|
76
|
|
|
|
|
77
|
|
|
if ($results->count()) { |
|
78
|
|
|
$result = RedirectService::importCsv($results, auth('hideyobackend')->user()->selected_shop_id); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
flash('The redirects are imported.'); |
|
81
|
|
|
|
|
82
|
|
|
return redirect()->route('redirect.index'); |
|
83
|
|
|
} else { |
|
84
|
|
|
flash('The redirects imported are failed.'); |
|
85
|
|
|
return redirect()->route('redirect.import'); |
|
86
|
|
|
} |
|
87
|
|
|
}); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function getExport() |
|
91
|
|
|
{ |
|
92
|
|
|
$result = RedirectService::selectAll(); |
|
93
|
|
|
|
|
94
|
|
|
Excel::create('redirects', function ($excel) use ($result) { |
|
95
|
|
|
|
|
96
|
|
|
$excel->sheet('Redirects', function ($sheet) use ($result) { |
|
97
|
|
|
$newArray = array(); |
|
98
|
|
|
foreach ($result as $row) { |
|
99
|
|
|
$newArray[$row->id] = array( |
|
100
|
|
|
'active' => $row->active, |
|
101
|
|
|
'url' => $row->url, |
|
102
|
|
|
'redirect_url' => $row->redirect_url |
|
103
|
|
|
); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
$sheet->fromArray($newArray); |
|
107
|
|
|
}); |
|
108
|
|
|
})->download('xls'); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function update($redirectId) |
|
112
|
|
|
{ |
|
113
|
|
|
$result = RedirectService::updateById($request->all(), $redirectId); |
|
|
|
|
|
|
114
|
|
|
return RedirectService::notificationRedirect('redirect.index', $result, 'The redirect was updated.'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function destroy($redirectId) |
|
118
|
|
|
{ |
|
119
|
|
|
$result = RedirectService::destroy($redirectId); |
|
120
|
|
|
|
|
121
|
|
|
if ($result) { |
|
122
|
|
|
flash('Redirect item is deleted.'); |
|
123
|
|
|
return redirect()->route('redirect.index'); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths