Completed
Push — master ( 0ca4f0...992805 )
by Damien
07:27
created

Cp   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 105
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMappingFieldOptions() 0 40 3
B getMappingAutoSuggestions() 0 59 4
1
<?php
2
3
4
namespace flipbox\saml\core\services;
5
6
7
use craft\base\Component;
8
use craft\elements\User;
9
use flipbox\saml\core\helpers\MappingHelper;
10
11
class Cp extends Component
12
{
13
14
    public function getMappingFieldOptions()
15
    {
16
        $user = new User();
17
        $options = [
18
            [
19
                'label' => $user->getAttributeLabel('firstName'),
20
                'value' => 'firstName',
21
            ],
22
            [
23
                'label' => $user->getAttributeLabel('lastName'),
24
                'value' => 'lastName',
25
            ],
26
            [
27
                'label' => $user->getAttributeLabel('email'),
28
                'value' => 'email',
29
            ],
30
            [
31
                'label' => $user->getAttributeLabel('username'),
32
                'value' => 'username',
33
            ],
34
            [
35
                'label' => $user->getAttributeLabel('uid'),
36
                'value' => 'uid',
37
            ],
38
            [
39
                'label' => $user->getAttributeLabel('id'),
40
                'value' => 'id',
41
            ],
42
        ];
43
        foreach ($user->getFieldLayout()->getFields() as $field) {
44
            if (MappingHelper::isSupportedField($field)) {
45
                $options[] = [
46
                    'label' => $field->name,
47
                    'value' => $field->handle,
48
                ];
49
            }
50
        }
51
52
        return $options;
53
    }
54
55
    public function getMappingAutoSuggestions()
56
    {
57
        $user = new User();
58
        $options = [
59
            [
60
                'hint' => $user->getAttributeLabel('firstName'),
61
                'name' => '{firstName}',
62
            ],
63
            [
64
                'hint' => $user->getAttributeLabel('lastName'),
65
                'name' => '{lastName}',
66
            ],
67
            [
68
                'hint' => $user->getAttributeLabel('email'),
69
                'name' => '{email}',
70
            ],
71
            [
72
                'hint' => $user->getAttributeLabel('username'),
73
                'name' => '{username}',
74
            ],
75
            [
76
                'hint' => $user->getAttributeLabel('uid'),
77
                'name' => '{uid}',
78
            ],
79
            [
80
                'hint' => $user->getAttributeLabel('id'),
81
                'name' => '{id}',
82
            ],
83
        ];
84
85
        $contentOptions = [];
86
        foreach ($user->getFieldLayout()->getFields() as $field) {
87
            if (! MappingHelper::isSupportedField($field)) {
88
                continue;
89
            }
90
91
            $fieldType = get_class($field);
92
            $contentOptions[] = [
93
                'hint' => $field->name . " ($fieldType)",
94
                'name' => '{' . $field->handle . '}',
95
            ];
96
        }
97
98
        $return = [
99
            [
100
                'label' => 'Standard Fields',
101
                'data' => $options,
102
            ],
103
        ];
104
105
        if (! empty($contentOptions)) {
106
            $return[] = [
107
                'label' => 'Content Fields',
108
                'data' => $contentOptions,
109
            ];
110
        }
111
112
        return $return;
113
    }
114
115
}