NewsGroupController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 20
c 2
b 0
f 1
dl 0
loc 51
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A destroy() 0 7 2
A store() 0 4 1
A update() 0 4 1
A index() 0 18 2
A edit() 0 3 1
A create() 0 3 1
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * NewsGroupController
5
 *
6
 * This is the controller of the newss 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
14
use Hideyo\Ecommerce\Framework\Services\News\NewsFacade as NewsService;
15
16
class NewsGroupController extends Controller
17
{
18
    public function index(Request $request)
19
    {
20
        if ($request->wantsJson()) {
21
22
            $query = NewsService::getGroupModel()->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...
23
24
            $datatables = \DataTables::of($query)
25
            ->addColumn('action', function ($query) {
26
                $deleteLink = \Form::deleteajax(url()->route('news-group.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
27
                $links = '<a href="'.url()->route('news-group.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
28
            
29
                return $links;
30
            });
31
32
            return $datatables->make(true);
33
        }
34
        
35
        return view('backend.news_group.index')->with('newsGroup', NewsService::selectAll());
36
    }
37
38
    public function create()
39
    {
40
        return view('backend.news_group.create')->with(array());
41
    }
42
43
    public function store(Request $request)
44
    {
45
        $result  = NewsService::createGroup($request->all());
46
        return NewsService::notificationRedirect('news-group.index', $result, 'The news group was inserted.');
47
    }
48
49
    public function edit($newsGroupId)
50
    {
51
        return view('backend.news_group.edit')->with(array('newsGroup' => NewsService::findGroup($newsGroupId)));
52
    }
53
54
    public function update(Request $request, $newsGroupId)
55
    {
56
        $result  = NewsService::updateGroupById($request->all(), $newsGroupId);
57
        return NewsService::notificationRedirect('news-group.index', $result, 'The news group was updated.');
58
    }
59
60
    public function destroy($newsGroupId)
61
    {
62
        $result  = NewsService::destroyGroup($newsGroupId);
63
64
        if ($result) {
65
            flash('The news group was deleted.');
66
            return redirect()->route('news-group.index');
67
        }
68
    }
69
}
70