PaymentMethodController   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 37
c 3
b 0
f 1
dl 0
loc 79
rs 10
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 4 1
A update() 0 4 1
A destroy() 0 7 2
A index() 0 35 5
A edit() 0 7 1
A create() 0 6 1
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * PaymentMethodController
5
 *
6
 * This is the controller for the shop payment methods
7
 * @author Matthijs Neijenhuijs <[email protected]>
8
 * @version 0.1
9
 */
10
use App\Http\Controllers\Controller;
11
use Illuminate\Http\Request;
12
use Form;
13
use DataTables;
14
use Hideyo\Ecommerce\Framework\Services\PaymentMethod\PaymentMethodFacade as PaymentMethodService;
15
use Hideyo\Ecommerce\Framework\Services\TaxRate\TaxRateFacade as TaxRateService;
16
use Hideyo\Ecommerce\Framework\Services\Order\OrderStatusFacade as OrderStatusService;
17
18
class PaymentMethodController extends Controller
19
{
20
    public function index(Request $request)
21
    {
22
        if ($request->wantsJson()) {
23
24
            $query = PaymentMethodService::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
            ->with(array('orderConfirmedOrderStatus', 'orderPaymentCompletedOrderStatus', 'orderPaymentFailedOrderStatus'));
26
            
27
            $datatables = DataTables::of($query)
28
29
            ->addColumn('orderconfirmed', function ($query) {
30
                if ($query->orderConfirmedOrderStatus) {
31
                    return $query->orderConfirmedOrderStatus->title;
32
                }
33
            })
34
            ->addColumn('paymentcompleted', function ($query) {
35
                if ($query->orderPaymentCompletedOrderStatus) {
36
                    return $query->orderPaymentCompletedOrderStatus->title;
37
                }
38
            })
39
            ->addColumn('paymentfailed', function ($query) {
40
                if ($query->orderPaymentFailedOrderStatus) {
41
                    return $query->orderPaymentFailedOrderStatus->title;
42
                }
43
            })
44
            ->addColumn('action', function ($query) {
45
                $deleteLink = Form::deleteajax(url()->route('payment-method.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-sm btn-danger'));
46
                $links = '<a href="'.url()->route('payment-method.edit', $query->id).'" class="btn btn-sm btn-success"><i class="fi-pencil"></i>Edit</a>  '.$deleteLink;
47
                return $links;
48
            });
49
50
51
            return $datatables->make(true);
52
        }
53
        
54
        return view('backend.payment_method.index')->with('paymentMethod', PaymentMethodService::selectAll());
55
    }
56
57
    public function create()
58
    {
59
        return view('backend.payment_method.create')->with(
60
            array(
61
                'taxRates' => TaxRateService::selectAll()->pluck('title', 'id'),
62
                'orderStatuses' => OrderStatusService::selectAll()->pluck('title', 'id')                
63
            )
64
        );
65
    }
66
67
    public function store(Request $request)
68
    {
69
        $result  = PaymentMethodService::create($request->all());
70
        return PaymentMethodService::notificationRedirect('payment-method.index', $result, 'The payment method was inserted.');
71
    }
72
73
    public function edit($paymentMethodId)
74
    {
75
        return view('backend.payment_method.edit')->with(
76
            array(
77
                'paymentMethod' => PaymentMethodService::find($paymentMethodId),
78
                'taxRates' => TaxRateService::selectAll()->pluck('title', 'id'),
79
                'orderStatuses' => OrderStatusService::selectAll()->pluck('title', 'id')
80
            )
81
        );
82
    }
83
84
    public function update(Request $request, $paymentMethodId)
85
    {
86
        $result  = PaymentMethodService::updateById($request->all(), $paymentMethodId);
87
        return PaymentMethodService::notificationRedirect('payment-method.index', $result, 'The payment method was updated.');
88
    }
89
90
    public function destroy($paymentMethodId)
91
    {
92
        $result  = PaymentMethodService::destroy($paymentMethodId);
93
94
        if ($result) {
95
            flash('The payment method was deleted.');
96
            return redirect()->route('payment-method.index');
97
        }
98
    }
99
}
100