Passed
Push — master ( 2232db...f4b030 )
by Matthijs
20:23 queued 14:47
created

OrderStatusEmailTemplateController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A edit() 0 3 1
A update() 0 4 1
A index() 0 20 2
A destroy() 0 7 2
A create() 0 3 1
A store() 0 4 1
A showAjaxTemplate() 0 3 1
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * OrderStatusEmailTemplateController
5
 *
6
 * This is the controller of the content weight types 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\Order\OrderStatusEmailTemplateFacade as OrderStatusEmailTemplateService;
13
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 OrderStatusEmailTemplateController extends Controller
20
{
21
    public function index(Request $request)
22
    {
23
        if ($request->wantsJson()) {
24
25
            $query = OrderStatusEmailTemplateService::getModel()->select(
26
                ['id', 'title', 'subject']
27
            )->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...
28
            
29
            $datatables = Datatables::of($query)
30
            ->addColumn('action', function ($query) {
31
                $deleteLink = Form::deleteajax('/admin/order-status-email-template/'. $query->id, 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
32
                $links = '<a href="/admin/order-status-email-template/'.$query->id.'/edit" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
33
            
34
                return $links;
35
            });
36
37
            return $datatables->make(true);
38
        }
39
        
40
        return view('backend.order-status-email-template.index')->with(array('orderHtmlTemplate' =>  OrderStatusEmailTemplateService::selectAll()));
41
    }
42
43
    public function create()
44
    {
45
        return view('backend.order-status-email-template.create')->with(array());
46
    }
47
48
    public function store(Request $request)
49
    {
50
        $result  = OrderStatusEmailTemplateService::create($request->all());
51
        return OrderStatusEmailTemplateService::notificationRedirect('order-status-email-template.index', $result, 'The template was inserted.');
52
    }
53
54
    public function edit($templateId)
55
    {
56
        return view('backend.order-status-email-template.edit')->with(array('orderHtmlTemplate' => OrderStatusEmailTemplateService::find($templateId)));
57
    }
58
59
    public function showAjaxTemplate($templateId)
60
    {
61
        return response()->json(OrderStatusEmailTemplateService::find($templateId));
62
    }
63
64
    public function update(Request $request, $templateId)
65
    {
66
        $result  = OrderStatusEmailTemplateService::updateById($request->all(), $templateId);
67
        return OrderStatusEmailTemplateService::notificationRedirect('order-status-email-template.index', $result, 'The template was updated.');
68
    }
69
70
    public function destroy($templateId)
71
    {
72
        $result  = OrderStatusEmailTemplateService::destroy($templateId);
73
74
        if ($result) {
75
            Notification::success('template was deleted.');
76
            return redirect()->route('order-status-email-template.index');
77
        }
78
    }
79
}
80