Users::getTitle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Admin\Sections;
4
5
use AdminColumn;
0 ignored issues
show
Bug introduced by
The type AdminColumn was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use AdminDisplay;
0 ignored issues
show
Bug introduced by
The type AdminDisplay was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use AdminForm;
0 ignored issues
show
Bug introduced by
The type AdminForm was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use AdminFormElement;
0 ignored issues
show
Bug introduced by
The type AdminFormElement was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use App\Role;
10
use SleepingOwl\Admin\Contracts\Initializable;
11
use SleepingOwl\Admin\Form\Buttons\Cancel;
12
//use SleepingOwl\Admin\Form\Buttons\Save;
13
use SleepingOwl\Admin\Form\Buttons\SaveAndClose;
14
use SleepingOwl\Admin\Section;
15
16
class Users extends Section implements Initializable
17
{
18
    public function initialize()
19
    {
20
    }
21
22
    protected $checkAccess = true;
23
    protected $alias = 'users';
24
25
    public function getIcon()
26
    {
27
        return 'fa fa-user';
28
    }
29
30
    public function getTitle()
31
    {
32
        return 'Пользователи';
33
    }
34
35
    public function getEditTitle()
36
    {
37
        return 'Редактирование пользователя';
38
    }
39
40
    public function getCreateTitle()
41
    {
42
        return 'Добавление пользователя';
43
    }
44
45
    public function onDisplay()
46
    {
47
        $display = AdminDisplay::datatables()
48
      ->setHtmlAttribute('class', 'table-primary table-hover')
49
      ->setDisplaySearch(true);
50
51
        $display->setColumns([
52
      AdminColumn::text('id', '#')
53
        ->setWidth('50px')
54
        ->setHtmlAttribute('class', 'text-center'),
55
      AdminColumn::gravatar('email', 'Ava'),
56
      AdminColumn::link('email', 'Email'),
57
      AdminColumn::text('name', 'Имя'),
58
      AdminColumn::text('roles.name', 'Права')
59
        ->setWidth('150px')
60
        ->setOrderable(false)
61
        ->setSearchCallback(function ($column, $query, $search) {
62
            return $query->orWhereHas('roles', function ($q) use ($search) {
63
                $q->where('name', 'like', '%'.$search.'%');
64
            });
65
        }),
66
      AdminColumn::boolean('active', 'Вход'),
67
      AdminColumn::text('created_at', 'Создан')
68
        ->setWidth('160px')
69
        ->setSearchable(false),
70
    ]);
71
72
        return $display;
73
    }
74
75
    public function onEdit($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

75
    public function onEdit(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
    {
77
        $form = AdminForm::panel()->addBody([
78
      AdminFormElement::columns()->addColumn([
79
        AdminFormElement::text('name', 'Имя')
80
          ->addValidationRule('max:190', __('adm.valid.max190'))
81
          ->required(),
82
        AdminFormElement::text('email', 'Почта')
83
          ->required()
84
          ->unique()
85
          ->addValidationRule('max:190', __('adm.valid.max190')),
86
        AdminFormElement::select('role_id', 'Права', Role::class)
87
          ->setDisplay('name')
88
          ->required()
89
          ->setSortable(false),
90
        AdminFormElement::select('lang', 'Язык сайта', config('app.locales'))
91
          ->required()
92
          ->setSortable(false),
93
        AdminFormElement::password('newpassword', 'Пароль (не заполнить - не сменится)')
94
          ->allowEmptyValue()
95
          ->addValidationRule('nullable')
96
          ->addValidationRule('between:8,50', 'От 8 до 50 символов'),
97
      ], 8)->addColumn([
98
        AdminFormElement::text('id', '#')
99
          ->setReadonly(1),
100
        AdminFormElement::checkbox('blocked', 'Блокировать пользователя'),
101
        AdminFormElement::html('<hr>'),
102
        AdminFormElement::text('created_at', 'Создан')
103
          ->setReadonly(1),
104
        AdminFormElement::text('signup_ip', 'IP регистрации')
105
          ->setReadonly(1),
106
        AdminFormElement::text('confirm_ip', 'IP активации почты')
107
          ->setReadonly(1),
108
109
      ]),
110
      AdminFormElement::html('<hr>'),
111
      AdminFormElement::checkbox('active', 'Включен'),
112
    ]);
113
114
        $form->getButtons()->setButtons([
115
      // 'save'  => new Save(),
116
      'save_and_close'  => new SaveAndClose(),
117
      'cancel'          => (new Cancel()),
118
    ]);
119
120
        return $form;
121
    }
122
123
    public function onCreate()
124
    {
125
        return $this->onEdit(null);
126
    }
127
128
    public function onDelete($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

128
    public function onDelete(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
129
    {
130
    }
131
}
132