Conditions | 5 |
Paths | 16 |
Total Lines | 30 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
27 | public function getPrimaryField($item, $config = null) |
||
28 | { |
||
29 | /* If config is not overridden then load crudapi config */ |
||
30 | if ($config === null) { |
||
31 | $config = config('crudapi'); |
||
32 | } |
||
33 | if (!isset($config['models']['fields']['default'])) { |
||
34 | $defaultField = 'name'; |
||
35 | } else { |
||
36 | $defaultField = $config['models']['fields']['default']; |
||
37 | } |
||
38 | |||
39 | /* Get the items Class */ |
||
40 | $class = get_class($item); |
||
41 | |||
42 | $stripped_class = str_replace($this->crudApi->namespace, '', $class); |
||
43 | // if class starts with a \ remove it. |
||
44 | if (substr($stripped_class, 0, 1) == '\\') { |
||
45 | $stripped_class = substr($stripped_class, 1); |
||
46 | } |
||
47 | |||
48 | $primaryFields = $config['models']['fields']['primary']; |
||
49 | |||
50 | if (array_key_exists($stripped_class, $primaryFields)) { |
||
51 | return $primaryFields[$stripped_class]; |
||
52 | } else { |
||
53 | //return the default |
||
54 | return $defaultField; |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 |