ProductAmountSeriesController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A edit() 0 9 1
A store() 0 4 1
A destroy() 0 7 2
A update() 0 4 1
A index() 0 26 3
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * ProductAmountSeriesController
5
 *
6
 * This is the controller of the product amount series of the shop
7
 * @author Matthijs Neijenhuijs <[email protected]>
8
 * @version 0.1
9
 */
10
11
use App\Http\Controllers\Controller;
12
use Hideyo\Ecommerce\Framework\Services\Product\ProductAmountSeriesFacade as ProductAmountSeriesService;
13
use Hideyo\Ecommerce\Framework\Services\Product\ProductFacade as ProductService;
14
use Illuminate\Http\Request;
15
use DataTables;
16
use Form;
17
18
class ProductAmountSeriesController extends Controller
19
{
20
    public function index(Request $request, $productId)
21
    {
22
        $product = ProductService::find($productId);
23
        if ($request->wantsJson()) {
24
            $query = ProductAmountSeriesService::getModel()->where('product_id', '=', $productId);
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
                
33
                return '<a href="#" class="change-active" data-url="/admin/html-block/change-active/'.$query->id.'"><span class="glyphicon glyphicon-remove icon-red"></span></a>';
34
            })
35
            ->addColumn('action', function ($query) use ($productId) {
36
                $deleteLink = Form::deleteajax(url()->route('product.product-amount-series.destroy', array('productId' => $productId, 'id' => $query->id)), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
37
                $links = '<a href="'.url()->route('product.product-amount-series.edit', array('productId' => $productId, 'id' => $query->id)).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
38
                
39
                return $links;
40
            });
41
42
            return $datatables->rawColumns(['active', 'action'])->make(true);
43
        }
44
        
45
        return view('backend.product-amount-series.index')->with(array('product' => $product));
46
    }
47
48
    public function store(Request $request, $productId)
49
    {
50
        $result  = ProductAmountSeriesService::create($request->all(), $productId);
51
        return ProductService::notificationRedirect(array('product.product-amount-series.index', $productId), $result, 'The product amount series is inserted.');
52
    }
53
54
    public function edit(Request $request, $productId, $id)
55
    {
56
        $product = ProductService::find($productId);
57
        $productAmountSeries = ProductAmountSeriesService::find($id);
58
59
        return view('backend.product-amount-series.edit')->with(
60
            array(
61
                'productAmountSeries' => $productAmountSeries, 
62
                'product' => $product, 
63
            )
64
        );
65
    }
66
67
    public function update(Request $request, $productId, $id)
68
    {
69
        $result  = ProductAmountSeriesService::updateById($request->all(), $productId, $id);
70
        return ProductService::notificationRedirect(array('product.product-amount-series.index', $productId), $result, 'The product amount series is updated.');
71
    }
72
73
    public function destroy($productId, $id)
74
    {
75
        $result  = ProductAmountSeriesService::destroy($id);
76
77
        if ($result) {
78
            flash('The product amount series is deleted.');
79
            return redirect()->route('product.product-amount-series.index', $productId);
80
        }
81
    }
82
}
83