Passed
Push — dev5a ( 328ab1...cf3a23 )
by Ron
07:38
created

GetEquipment::getAllEquipment()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 12
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
3
namespace App\Domains\Equipment;
4
5
use App\SystemTypes;
6
use App\SystemCategories;
7
8
use Illuminate\Support\Facades\Log;
9
10
class GetEquipment
11
{
12
    //  Pull all equpment types - sorting by category is optional
13 8
    public function getAllEquipment($incCat = false)
14
    {
15 8
        if($incCat)
16
        {
17 6
            $list = SystemCategories::with('SystemTypes')->get();
18
        }
19
        else
20
        {
21 2
            $list = SystemTypes::all();
22
        }
23
24 8
        return $list;
25
    }
26
27
    //  Return an array that can be easily assigned by vue v-for
28 2
    public function getEquipmentArray()
29
    {
30 2
        $list = SystemTypes::orderBy('cat_id', 'ASC')->orderBy('name', 'ASC')->get();
31
32 2
        $newList = [];
33 2
        foreach($list as $item)
34
        {
35
            $newList[] = [
36
                'value' => $item->sys_id,
37
                'text'  => $item->name,
38
            ];
39
        }
40
41 2
        return $newList;
42
    }
43
44
    //  Get the list of categories
45 4
    public function getCatList()
46
    {
47 4
        return SystemCategories::all();
48
    }
49
50
    //  Get all fields attached to the equipment
51 4
    public function getEquipmentData($sysID)
52
    {
53 4
        return SystemTypes::where('sys_id', $sysID)->with('SystemDataFields')->first();
54
    }
55
}
56