|
1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
|
2
|
|
|
/** |
|
3
|
|
|
* NewsImageController |
|
4
|
|
|
* |
|
5
|
|
|
* This is the controller for the images of a news item |
|
6
|
|
|
* @author Matthijs Neijenhuijs <[email protected]> |
|
7
|
|
|
* @version 0.1 |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
use App\Http\Controllers\Controller; |
|
11
|
|
|
use Illuminate\Http\Request; |
|
12
|
|
|
use DataTables; |
|
13
|
|
|
use Form; |
|
14
|
|
|
|
|
15
|
|
|
use Hideyo\Ecommerce\Framework\Services\News\NewsFacade as NewsService; |
|
16
|
|
|
|
|
17
|
|
|
class NewsImageController extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
public function index(Request $request, $newsId) |
|
20
|
|
|
{ |
|
21
|
|
|
$news = NewsService::find($newsId); |
|
22
|
|
|
if ($request->wantsJson()) { |
|
23
|
|
|
|
|
24
|
|
|
$image = NewsService::getImageModel()->where('news_id', '=', $newsId); |
|
25
|
|
|
|
|
26
|
|
|
$datatables = DataTables::of($image) |
|
27
|
|
|
|
|
28
|
|
|
->addColumn('thumb', function ($image) { |
|
29
|
|
|
return '<img src="/files/news/100x100/'.$image->news_id.'/'.$image->file.'" />'; |
|
30
|
|
|
}) |
|
31
|
|
|
->addColumn('action', function ($image) use ($newsId) { |
|
32
|
|
|
$deleteLink = Form::deleteajax(url()->route('news-images.destroy', array('newsId' => $newsId, 'id' => $image->id)), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger')); |
|
33
|
|
|
$links = '<a href="'.url()->route('news-images.edit', array('newsId' => $newsId, 'id' => $image->id)).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> '.$deleteLink; |
|
34
|
|
|
|
|
35
|
|
|
return $links; |
|
36
|
|
|
}); |
|
37
|
|
|
|
|
38
|
|
|
return $datatables->make(true); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return view('backend.news_image.index')->with(array('news' => $news)); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function create($newsId) |
|
45
|
|
|
{ |
|
46
|
|
|
$news = NewsService::find($newsId); |
|
47
|
|
|
return view('backend.news_image.create')->with(array('news' => $news)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function store(Request $request, $newsId) |
|
51
|
|
|
{ |
|
52
|
|
|
$result = NewsService::createImage($request->all(), $newsId); |
|
53
|
|
|
return NewsService::notificationRedirect(array('news-images.index', $newsId), $result, 'The news image was inserted.'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function edit($newsId, $newsImageId) |
|
57
|
|
|
{ |
|
58
|
|
|
$news = NewsService::find($newsId); |
|
59
|
|
|
return view('backend.news_image.edit')->with(array('newsImage' => NewsService::findImage($newsImageId), 'news' => $news)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function update(Request $request, $newsId, $newsImageId) |
|
63
|
|
|
{ |
|
64
|
|
|
$result = NewsService::updateImageById($request->all(), $newsId, $newsImageId); |
|
65
|
|
|
return NewsService::notificationRedirect(array('news-images.index', $newsId), $result, 'The news image was updated.'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function destroy($newsId, $newsImageId) |
|
69
|
|
|
{ |
|
70
|
|
|
$result = NewsService::destroyImage($newsImageId); |
|
71
|
|
|
|
|
72
|
|
|
if ($result) { |
|
73
|
|
|
flash('The file was deleted.'); |
|
74
|
|
|
return redirect()->route('news-images.index', $newsId); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|