Passed
Push — master ( 889c97...54235f )
by Matthijs
26:54 queued 20:50
created

OrderStatusController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * OrderStatusController
5
 *
6
 * This is the controller of the order statuses 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 Auth;
14
use Notification;
15
use Hideyo\Ecommerce\Framework\Services\Order\OrderStatusEmailTemplateFacade as OrderStatusEmailTemplateService;
16
use Hideyo\Ecommerce\Framework\Services\Order\OrderStatusFacade as OrderStatusService;
17
18
class OrderStatusController extends Controller
19
{
20
    public function index(Request $request)
21
    {
22
        if ($request->wantsJson()) {
23
24
            $query = OrderStatusService::getModel()->select(
25
                ['id', 'color','title']
26
            )->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...
27
            
28
            $datatables = \Datatables::of($query)
0 ignored issues
show
Bug introduced by
The type Datatables was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
30
            ->addColumn('title', function ($query) {
31
     
32
                if ($query->color) {
33
                    return '<span style="background-color:'.$query->color.'; padding: 10px; line-height:30px; text-align:center; color:white;">'.$query->title.'</span>';
34
                }
35
                    return $query->title;
36
            })
37
38
39
            ->addColumn('action', function ($query) {
40
                $deleteLink = \Form::deleteajax('/admin/order-status/'. $query->id, 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
41
                $links = '<a href="/admin/order-status/'.$query->id.'/edit" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
42
            
43
                return $links;
44
            });
45
46
            return $datatables->make(true);
47
48
49
        }
50
        
51
        return view('backend.order-status.index')->with('content', OrderStatusService::selectAll());
52
    }
53
54
    public function create()
55
    {
56
        return view('backend.order-status.create')->with(array('templates' => OrderStatusEmailTemplateService::selectAllByShopId(auth('hideyobackend')->user()->selected_shop_id)->pluck('title', '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...
57
    }
58
59
    public function store(Request $request)
60
    {
61
        $result  = OrderStatusService::create($request->all());
62
        return OrderStatusService::notificationRedirect('order-status.index', $result, 'The order status was inserted.');
63
    }
64
65
    public function edit($orderStatusId)
66
    {
67
        $orderStatus = OrderStatusService::find($orderStatusId);
68
69
        $populatedData = array();
70
           
71
        return view('backend.order-status.edit')->with(
72
            array(
73
            'orderStatus' => $orderStatus,
74
            'populatedData' => $populatedData,
75
            'templates' => OrderStatusEmailTemplateService::selectAllByShopId(auth('hideyobackend')->user()->selected_shop_id)->pluck('title', '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...
76
            )
77
        );
78
    }
79
80
    public function update(Request $request, $orderStatusId)
81
    {
82
        $result  = OrderStatusService::updateById($request->all(), $orderStatusId);
83
        return OrderStatusService::notificationRedirect('order-status.index', $result, 'The order status was updated.');
84
    }
85
86
    public function destroy($orderStatusId)
87
    {
88
        $result  = OrderStatusService::destroy($orderStatusId);
89
90
        if ($result) {
91
            Notification::success('The order status was deleted.');
92
            return redirect()->route('order-status.index');
93
        }
94
    }
95
}
96