OrderStateTrait::getOrder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Distilleries\Expendable\States;
4
5
use Illuminate\Http\Request;
6
7
trait OrderStateTrait
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12 2
    public function getOrder()
13
    {
14 2
        $rows = $this->model->orderBy($this->model->orderFieldName(), 'asc')->get();
15
16 2
        $this->layoutManager->add([
17 2
            'content' => view('expendable::admin.form.state.order', [
18 2
                'rows' => $rows,
19
            ]),
20
        ]);
21
22 2
        return $this->layoutManager->render();
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 2
    public function postOrder(Request $request)
29
    {
30 2
        $ids = $request->input('ids');
31
32 2
        $order = 1;
33 2
        foreach ($ids as $id) {
34 2
            $instance = $this->model->find($id);
35 2
            if (!empty($instance)) {
36 2
                $instance->{$this->model->orderFieldName()} = $order;
37 2
                $instance->save();
38 2
                $order++;
39
            }
40
        }
41
42 2
        return response()->json(['error' => false]);
43
    }
44
}
45