ContentImageController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 28
c 1
b 0
f 1
dl 0
loc 62
rs 10
wmc 8

6 Methods

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