1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace DigitalWand\AdminHelper\Widget;
|
4
|
|
|
|
5
|
|
|
use Bitrix\Main\UserTable;
|
6
|
|
|
|
7
|
|
|
/**
|
8
|
|
|
* Виджет для вывода пользователя.
|
9
|
|
|
*
|
10
|
|
|
* Доступные опции:
|
11
|
|
|
* <ul>
|
12
|
|
|
* <li> STYLE - inline-стили
|
13
|
|
|
* <li> SIZE - значение атрибута size для input
|
14
|
|
|
* </ul>
|
15
|
|
|
*
|
16
|
|
|
* @author Nik Samokhvalov <[email protected]>
|
17
|
|
|
*/
|
18
|
|
|
class UserWidget extends NumberWidget
|
19
|
|
|
{
|
20
|
|
|
/**
|
21
|
|
|
* @inheritdoc
|
22
|
|
|
*/
|
23
|
|
|
public function getEditHtml()
|
24
|
|
|
{
|
25
|
|
|
$style = $this->getSettings('STYLE');
|
26
|
|
|
$size = $this->getSettings('SIZE');
|
27
|
|
|
|
28
|
|
|
$userId = $this->getValue();
|
29
|
|
|
|
30
|
|
|
$htmlUser = '';
|
31
|
|
|
|
32
|
|
|
if (!empty($userId) && $userId != 0) {
|
33
|
|
|
$rsUser = UserTable::getById($userId);
|
34
|
|
|
$user = $rsUser->fetch();
|
35
|
|
|
|
36
|
|
|
$htmlUser = '[<a href="user_edit.php?lang=ru&ID=' . $user['ID'] . '">' . $user['ID'] . '</a>] ('
|
37
|
|
|
. $user['EMAIL'] . ') ' . $user['NAME'] . ' ' . $user['LAST_NAME'];
|
38
|
|
|
}
|
39
|
|
|
|
40
|
|
|
return '<input type="text"
|
41
|
|
|
name="' . $this->getEditInputName() . '"
|
42
|
|
|
value="' . static::prepareToTagAttr($this->getValue()) . '"
|
43
|
|
|
size="' . $size . '"
|
44
|
|
|
style="' . $style . '"/>' . $htmlUser;
|
45
|
|
|
}
|
46
|
|
|
|
47
|
|
|
/**
|
48
|
|
|
* @inheritdoc
|
49
|
|
|
*/
|
50
|
|
|
public function getValueReadonly()
|
51
|
|
|
{
|
52
|
|
|
$userId = $this->getValue();
|
53
|
|
|
$htmlUser = '';
|
54
|
|
|
|
55
|
|
View Code Duplication |
if (!empty($userId) && $userId != 0) {
|
|
|
|
|
56
|
|
|
$rsUser = UserTable::getById($userId);
|
57
|
|
|
$user = $rsUser->fetch();
|
58
|
|
|
|
59
|
|
|
$htmlUser = '[<a href="user_edit.php?lang=ru&ID=' . $user['ID'] . '">' . $user['ID'] . '</a>]';
|
60
|
|
|
|
61
|
|
|
if ($user['EMAIL']) {
|
62
|
|
|
$htmlUser .= ' (' . $user['EMAIL'] . ')';
|
63
|
|
|
}
|
64
|
|
|
|
65
|
|
|
$htmlUser .= ' ' . static::prepareToOutput($user['NAME'])
|
66
|
|
|
. ' ' . static::prepareToOutput($user['LAST_NAME']);
|
67
|
|
|
}
|
68
|
|
|
|
69
|
|
|
return $htmlUser;
|
70
|
|
|
}
|
71
|
|
|
|
72
|
|
|
/**
|
73
|
|
|
* @inheritdoc
|
74
|
|
|
*/
|
75
|
|
|
public function generateRow(&$row, $data)
|
76
|
|
|
{
|
77
|
|
|
$userId = $this->getValue();
|
78
|
|
|
$strUser = '';
|
79
|
|
|
|
80
|
|
View Code Duplication |
if (!empty($userId) && $userId != 0) {
|
|
|
|
|
81
|
|
|
$rsUser = UserTable::getById($userId);
|
82
|
|
|
$user = $rsUser->fetch();
|
83
|
|
|
|
84
|
|
|
$strUser = '[<a href="user_edit.php?lang=ru&ID=' . $user['ID'] . '">' . $user['ID'] . '</a>]';
|
85
|
|
|
|
86
|
|
|
if ($user['EMAIL']) {
|
87
|
|
|
$strUser .= ' (' . $user['EMAIL'] . ')';
|
88
|
|
|
}
|
89
|
|
|
|
90
|
|
|
$strUser .= ' ' . static::prepareToOutput($user['NAME'])
|
91
|
|
|
. ' ' . static::prepareToOutput($user['LAST_NAME']);
|
92
|
|
|
}
|
93
|
|
|
|
94
|
|
|
if ($strUser) {
|
95
|
|
|
$row->AddViewField($this->getCode(), $strUser);
|
96
|
|
|
} else {
|
97
|
|
|
$row->AddViewField($this->getCode(), '');
|
98
|
|
|
}
|
99
|
|
|
}
|
100
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.