Passed
Push — master ( a41561...55654e )
by Julito
12:02
created

UserAdmin::configureFormFields()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 106
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 55
c 0
b 0
f 0
nop 1
dl 0
loc 106
rs 8.9818
nc 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\UserBundle\Admin;
5
6
use Sonata\AdminBundle\Datagrid\DatagridMapper;
7
use Sonata\AdminBundle\Form\FormMapper;
8
use Sonata\UserBundle\Admin\Model\UserAdmin as BaseUserAdmin;
9
10
/**
11
 * Class UserAdmin.
12
 *
13
 * @package Chamilo\UserBundle\Admin
14
 */
15
class UserAdmin extends BaseUserAdmin
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected function configureFormFields(FormMapper $formMapper): void
21
    {
22
        // define group zoning
23
        $formMapper
24
            ->tab('User')
25
            ->with('Profile', ['class' => 'col-md-6'])->end()
26
            ->with('General', ['class' => 'col-md-6'])->end()
27
            //->with('Social', array('class' => 'col-md-6'))->end()
28
            ->end()
29
            ->tab('Security')
30
            ->with('Status', ['class' => 'col-md-4'])->end()
31
            ->with('Groups', ['class' => 'col-md-4'])->end()
32
            ->with('Keys', ['class' => 'col-md-4'])->end()
33
            ->with('Roles', ['class' => 'col-md-12'])->end()
34
            ->end()
35
            ->tab('ExtraFields')
36
            ->with('ExtraFields', ['class' => 'col-md-4'])->end()
37
            ->end();
38
39
        $now = new \DateTime();
40
41
        $formMapper
42
            ->tab('User')
43
            ->with('General')
44
                ->add('username')
45
                ->add('email')
46
                /*->add(
47
                    'plainPassword',
48
                    'text',
49
                    array(
50
                        'required' => (!$this->getSubject() || is_null(
51
                                $this->getSubject()->getId()
52
                            )),
53
                    )
54
                )*/
55
            ->end()
56
            ->with('Profile')
57
                /*->add(
58
                    'dateOfBirth',
59
                    'sonata_type_date_picker',
60
                    array(
61
                        'years' => range(1900, $now->format('Y')),
62
                        'dp_min_date' => '1-1-1900',
63
                        'dp_max_date' => $now->format('c'),
64
                        'required' => false,
65
                    )
66
                )*/
67
            ->add('firstname', null, ['required' => false])
68
            ->add('lastname', null, ['required' => false])
69
            ->add('website', 'url', array('required' => false))
70
            ->add('biography', 'text', array('required' => false))
71
            /*->add(
72
                'gender',
73
                'sonata_user_gender',
74
                array(
75
                    'required' => true,
76
                    'translation_domain' => $this->getTranslationDomain(),
77
                )
78
            )*/
79
            //->add('locale', 'locale', array('required' => false))
80
            //->add('timezone', 'timezone', array('required' => false))
81
            //->add('phone', null, array('required' => false))
82
            ->end()
83
            /*->with('Social')
84
            ->add('facebookUid', null, array('required' => false))
85
            ->add('facebookName', null, array('required' => false))
86
            ->add('twitterUid', null, array('required' => false))
87
            ->add('twitterName', null, array('required' => false))
88
            ->add('gplusUid', null, array('required' => false))
89
            ->add('gplusName', null, array('required' => false))
90
            ->end()*/
91
            ->end();
92
93
        if ($this->getSubject() && !$this->getSubject()->hasRole('ROLE_SUPER_ADMIN')) {
94
            $formMapper
95
                ->tab('Security')
96
                ->with('Status')
97
                ->add('locked', null, ['required' => false])
98
                ->add('expired', null, ['required' => false])
99
                ->add('enabled', null, ['required' => false])
100
                ->add('credentialsExpired', null, ['required' => false])
101
                ->end()
102
                ->with('Groups')
103
                ->add(
104
                    'groups',
105
                    'sonata_type_model',
106
                    [
107
                        'required' => false,
108
                        'expanded' => true,
109
                        'multiple' => true,
110
                    ]
111
                )
112
                ->end()
113
                ->with('Roles')
114
                ->add(
115
                    'realRoles',
116
                    'sonata_security_roles',
117
                    [
118
                        'label' => 'form.label_roles',
119
                        'expanded' => true,
120
                        'multiple' => true,
121
                        'required' => false,
122
                    ]
123
                )
124
                ->end()
125
                ->end();
126
        }
127
128
        /*$formMapper
129
            ->tab('Security')
130
            ->with('Keys')
131
            ->add('token', null, array('required' => false))
132
            ->add('twoStepVerificationCode', null, array('required' => false))
133
            ->end()
134
            ->end();*/
135
//
136
//        $formMapper
137
//            ->tab('ExtraFields')
138
//            ->with('ExtraFields')
139
//            ->add(
140
//                'extraFields',
141
//                'sonata_type_collection',
142
//                array(
143
//                    'cascade_validation' => true,
144
//                    /*'type_options' => array(
145
//                        // Prevents the "Delete" option from being displayed
146
//                        'delete' => false,
147
//                        'delete_options' => array(
148
//                            // You may otherwise choose to put the field but hide it
149
//                            'type'         => 'hidden',
150
//                            // In that case, you need to fill in the options as well
151
//                            'type_options' => array(
152
//                                'mapped'   => false,
153
//                                'required' => false,
154
//                            )
155
//                        )
156
//                    )*/
157
//                ),
158
//                array(
159
//                    'allow_delete' => true,
160
//                    'by_reference' => false,
161
//                    'edit' => 'inline',
162
//                    'inline' => 'table',
163
//                    'admin_code' => 'sonata.admin.user_field_values'
164
//                    /* 'edit' => 'inline',
165
//                     'inline' => 'table',
166
//                     'sortable' => 'position',*/
167
//                )
168
//            )
169
//            ->end()
170
//            ->end();
171
    }
172
173
    /**
174
     * @param DatagridMapper $datagridMapper
175
     */
176
    protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
177
    {
178
        $datagridMapper
179
            ->add('username')
180
            ->add('firstname')
181
            ->add('lastname')
182
            ->add('email')
183
            ->add('officialCode')
184
            ->add('groups')
185
            ->add('active')
186
            //->add('registrationDate', 'doctrine_orm_datetime_range', array('input_type' => 'timestamp'))
187
        ;
188
    }
189
}
190