Completed
Push — dev5 ( 8afe4d...7a94ca )
by Ron
09:32
created

SystemsTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllSystems() 0 18 2
A getFields() 0 9 1
1
<?php
2
3
namespace App\Http\Traits;
4
5
use App\SystemTypes;
6
use App\SystemCustDataFields;
7
use Illuminate\Support\Facades\Log;
8
9
trait SystemsTrait
10
{
11
    //  Get a list of all systems
12
    public function getAllSystems()
13
    {
14
        $sysList = SystemTypes::select('system_types.*', 'system_categories.name AS cat_name')
15
            ->join('system_categories', 'system_types.cat_id', '=', 'system_categories.cat_id')
16
            
17
            ->orderBy('cat_name', 'ASC')
18
            ->get();
19
        
20
        $sysArr = [];
21
        foreach($sysList as $sys)
22
        {
23
            $sysArr[$sys->cat_name][] = [
24
                'sys_id' => $sys->sys_id,
25
                'name'   => $sys->name
26
            ];
27
        }
28
        
29
        return $sysArr;
30
    }
31
    
32
    //  Get the data fields attached to a system
33
    public function getFields($id)
34
    {
35
        $sysFields = SystemCustDataFields::where('sys_id', $id)
36
            ->join('system_cust_data_types', 'system_cust_data_types.data_type_id', '=', 'system_cust_data_fields.data_type_id')
37
            ->select('system_cust_data_types.data_type_id', 'system_cust_data_types.name', 'field_id', 'hidden', 'order')
38
            ->orderBy('order', 'ASC')
39
            ->get();
40
        
41
        return $sysFields;
42
    }
43
}
44