HtmlBlockController   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 39
c 2
b 0
f 1
dl 0
loc 92
rs 10
wmc 14

9 Methods

Rating   Name   Duplication   Size   Complexity  
A copy() 0 7 1
A destroy() 0 7 2
A create() 0 3 1
A store() 0 4 1
A update() 0 4 1
A changeActive() 0 4 1
A storeCopy() 0 10 2
A edit() 0 3 1
A index() 0 30 4
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * HtmlBlockController
5
 *
6
 * This is the controller of the htmlBlocks 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\HtmlBlock\HtmlBlockFacade as HtmlBlockService;
17
18
class HtmlBlockController extends Controller
19
{
20
    public function index(Request $request)
21
    {
22
        if ($request->wantsJson()) {
23
24
            $query = HtmlBlockService::getModel()->where('shop_id', '=', auth('hideyobackend')->user()->selected_shop_id);
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
25
            
26
            $datatables = DataTables::of($query)
27
28
            ->addColumn('active', function ($query) {
29
                if ($query->active) {
30
                    return '<a href="#" class="change-active" data-url="/admin/html-block/change-active/'.$query->id.'"><span class="glyphicon glyphicon-ok icon-green"></span></a>';
31
                }
32
                return '<a href="#" class="change-active" data-url="/admin/html-block/change-active/'.$query->id.'"><span class="glyphicon glyphicon-remove icon-red"></span></a>';
33
            })
34
            ->addColumn('image', function ($query) {
35
                if ($query->image_file_name) {
36
                    return '<img src="'.config('hideyo.public_path').'/html_block/'.$query->id.'/'.$query->image_file_name.'" width="200px" />';
37
                }
38
            })
39
            ->addColumn('action', function ($query) {
40
                $deleteLink = Form::deleteajax(url()->route('html-block.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
41
                $copy = '<a href="/admin/html-block/'.$query->id.'/copy" class="btn btn-default btn-sm btn-info"><i class="entypo-pencil"></i>Copy</a>';
42
                $links = '<a href="'.url()->route('html-block.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> '.$copy.' '.$deleteLink;
43
                return $links;
44
            });
45
46
            return $datatables->rawColumns(['active', 'image', 'action'])->make(true);
47
        }
48
        
49
        return view('backend.html-block.index')->with('htmlBlock', HtmlBlockService::selectAll());
50
    }
51
52
    public function create()
53
    {
54
        return view('backend.html-block.create')->with(array());
55
    }
56
57
    public function store(Request $request)
58
    {
59
        $result  = HtmlBlockService::create($request->all());
60
        return HtmlBlockService::notificationRedirect('html-block.index', $result, 'The html block was inserted.');     
61
    }
62
63
    public function changeActive($htmlBlockId)
64
    {
65
        $result = HtmlBlockService::changeActive($htmlBlockId);
66
        return response()->json($result);
67
    }
68
69
    public function edit($htmlBlockId)
70
    {
71
        return view('backend.html-block.edit')->with(array('htmlBlock' => HtmlBlockService::find($htmlBlockId)));
72
    }
73
74
    public function update(Request $request, $htmlBlockId)
75
    {
76
        $result  = HtmlBlockService::updateById($request->all(), $htmlBlockId);
77
            return HtmlBlockService::notificationRedirect('html-block.index', $result, 'The html block was updated.');     
78
    }
79
80
    public function copy($htmlBlockId)
81
    {
82
        $htmlBlock = HtmlBlockService::find($htmlBlockId);
83
84
        return view('backend.html-block.copy')->with(
85
            array(
86
            'htmlBlock' => $htmlBlock
87
            )
88
        );
89
    }
90
    
91
    public function storeCopy(Request $request, $htmlBlockId)
92
    {
93
        $htmlBlock = HtmlBlockService::find($htmlBlockId);
94
95
        if($htmlBlock) {
96
            $result  = HtmlBlockService::createCopy($request->all(), $htmlBlockId);
97
            return HtmlBlockService::notificationRedirect('html-block.index', $result, 'The html block was inserted.');      
98
        }
99
100
        return redirect()->back()->withInput();
101
    }
102
103
    public function destroy($htmlBlockId)
104
    {
105
        $result  = HtmlBlockService::destroy($htmlBlockId);
106
107
        if ($result) {
108
            flash('The html block was deleted.');
109
            return redirect()->route('html-block.index');
110
        }
111
    }
112
}
113