ClientAddressController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 33
c 1
b 0
f 1
dl 0
loc 71
rs 10
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A destroy() 0 7 2
A update() 0 4 1
A create() 0 4 1
A store() 0 4 1
A index() 0 36 4
A edit() 0 4 1
1
<?php namespace App\Http\Controllers\Backend;
2
3
use App\Http\Controllers\Controller;
4
5
/**
6
 * ClientAddressController
7
 *
8
 * This is the controller for the client addresses
9
 * @author Matthijs Neijenhuijs <[email protected]>
10
 * @version 0.1
11
 */
12
13
use Hideyo\Ecommerce\Framework\Services\Client\ClientFacade as ClientService;
14
use Illuminate\Http\Request;
15
use Form;
16
use DataTables;
17
18
class ClientAddressController extends Controller
19
{
20
    public function index(Request $request, $clientId)
21
    {
22
        $client = ClientService::find($clientId);
23
        if ($request->wantsJson()) {
24
25
            $addresses = ClientService::getAddressModel()->with(array('clientDeliveryAddress', 'clientBillAddress'))->where('client_id', '=', $clientId);
26
            
27
            $datatables = DataTables::of($addresses)
28
            ->addColumn('housenumber', function ($addresses) {
29
                return $addresses->housenumber.$addresses->housenumber_suffix;
30
            })
31
            ->addColumn('delivery', function ($addresses) {
32
                if ($addresses->clientDeliveryAddress()->count()) {
33
                    return '<span class="glyphicon glyphicon-ok icon-green"></span>';
34
                }
35
                
36
                return '<span class="glyphicon glyphicon-remove icon-red"></span>';   
37
            })
38
            ->addColumn('bill', function ($addresses) {
39
                if ($addresses->clientBillAddress()->count()) {
40
                          return '<span class="glyphicon glyphicon-ok icon-green"></span>';
41
                }
42
43
                return '<span class="glyphicon glyphicon-remove icon-red"></span>';
44
            })
45
            ->addColumn('action', function ($addresses) use ($clientId) {
46
                $deleteLink = Form::deleteajax(url()->route('client.addresses.destroy', array('clientId' => $clientId, 'clientAddressId' => $addresses->id)), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
47
                $links = '<a href="'.url()->route('client.addresses.edit', array('clientId' => $clientId, 'clientAddressId' => $addresses->id)).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
48
            
49
                return $links;
50
            });
51
52
            return $datatables->rawColumns(['bill', 'delivery', 'action'])->make(true);
53
        }
54
        
55
        return view('backend.client_address.index')->with(array('client' => $client));
56
    }
57
58
    public function create($clientId)
59
    {
60
        $client = ClientService::find($clientId);
61
        return view('backend.client_address.create')->with(array('client' => $client));
62
    }
63
64
    public function store(Request $request, $clientId)
65
    {
66
        $result  = ClientService::createAddress($request->all(), $clientId);
67
        return ClientService::notificationRedirect(array('client.addresses.index', $clientId), $result, 'The client adress is inserted.');
68
    }
69
70
    public function edit($clientId, $id)
71
    {
72
        $client = ClientService::find($clientId);
73
        return view('backend.client_address.edit')->with(array('clientAddress' => ClientService::findAddress($id), 'client' => $client));
74
    }
75
76
    public function update(Request $request, $clientId, $id)
77
    {
78
        $result  = ClientService::editAddress($clientId, $id, $request->all());
79
        return ClientService::notificationRedirect(array('client.addresses.index', $clientId), $result, 'The client adress is updated.'); 
80
    }
81
82
    public function destroy($clientId, $id)
83
    {
84
        $result  = ClientService::destroyAddress($id);
85
86
        if ($result) {
87
            flash('The client address is deleted.');
88
            return redirect()->route('client.addresses.index', $clientId);
89
        }
90
    }
91
}
92