Passed
Push — master ( 46bb46...96f0ff )
by Matthijs
23:45 queued 17:36
created

ProductAmountSeriesController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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;
0 ignored issues
show
Bug introduced by
The type Hideyo\Ecommerce\Framewo...oductAmountSeriesFacade 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...
13
use Hideyo\Ecommerce\Framework\Services\Product\ProductFacade as ProductService;
14
use Illuminate\Http\Request;
15
use Notification;
16
use Datatables;
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...
17
use Form;
18
19
class ProductAmountSeriesController extends Controller
20
{
21
    public function index(Request $request, $productId)
22
    {
23
        $product = ProductService::find($productId);
24
        if ($request->wantsJson()) {
25
            $query = ProductAmountSeriesService::getModel()->select(
26
                ['id', 'series_start', 'series_value', 'active','series_max']
27
            )->where('product_id', '=', $productId);
28
            
29
            $datatables = Datatables::of($query)
30
31
            ->addColumn('active', function ($query) {
32
                if ($query->active) {
33
                    return '<a href="#" class="change-active" data-url="/admin/html-block/change-active/'.$query->id.'"><span class="glyphicon glyphicon-ok icon-green"></span></a>';
34
                }
35
                
36
                return '<a href="#" class="change-active" data-url="/admin/html-block/change-active/'.$query->id.'"><span class="glyphicon glyphicon-remove icon-red"></span></a>';
37
            })
38
            ->addColumn('action', function ($query) use ($productId) {
39
                $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'));
40
                $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;
41
                
42
                return $links;
43
            });
44
45
            return $datatables->make(true);
46
47
        }
48
        
49
        return view('backend.product-amount-series.index')->with(array('product' => $product));
50
    }
51
52
    public function store(Request $request, $productId)
53
    {
54
        $result  = ProductAmountSeriesService::create($request->all(), $productId);
55
        return ProductService::notificationRedirect(array('product.product-amount-series.index', $productId), $result, 'The product amount series is inserted.');
56
    }
57
58
    public function edit(Request $request, $productId, $id)
59
    {
60
        $product = ProductService::find($productId);
61
        $productAmountSeries = ProductAmountSeriesService::find($id);
62
63
        return view('backend.product-amount-series.edit')->with(
64
            array(
65
                'productAmountSeries' => $productAmountSeries, 
66
                'product' => $product, 
67
            )
68
        );
69
    }
70
71
    public function update(Request $request, $productId, $id)
72
    {
73
        $result  = ProductAmountSeriesService::updateById($request->all(), $productId, $id);
74
        return ProductService::notificationRedirect(array('product.product-amount-series.index', $productId), $result, 'The product amount series is updated.');
75
    }
76
77
    public function destroy($productId, $id)
78
    {
79
        $result  = ProductAmountSeriesService::destroy($id);
80
81
        if ($result) {
82
            Notification::success('The product amount series is deleted.');
83
            return redirect()->route('product.product-amount-series.index', $productId);
84
        }
85
    }
86
}
87