Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
intranetnewuser.php
1
<?php
2
3
namespace
Bitrix\Socialnetwork\Livefeed
;
4
5
use
Bitrix\Iblock\SectionTable
;
6
use
Bitrix\Main\Config\Option
;
7
use
Bitrix\Main\Loader
;
8
use
Bitrix\Main\Localization\Loc
;
9
use
Bitrix\Main\ModuleManager
;
10
use
Bitrix\Main\UserTable
;
11
use
Bitrix\Socialnetwork\LogTable
;
12
13
Loc::loadMessages
(__FILE__);
14
15
class
IntranetNewUser
extends
Provider
16
{
17
public
const
PROVIDER_ID
=
'INTRANET_NEW_USER'
;
18
public
const
CONTENT_TYPE_ID
=
'INTRANET_NEW_USER'
;
19
20
public
static
function
getId
(): string
21
{
22
return
static::PROVIDER_ID;
23
}
24
25
public
function
getEventId
(): array
26
{
27
return
[
'intranet_new_user'
];
28
}
29
30
public
function
getType
(): string
31
{
32
return
Provider::TYPE_POST
;
33
}
34
35
public
function
getCommentProvider
():
Provider
36
{
37
return
new
LogComment
();
38
}
39
40
public
function
initSourceFields
()
41
{
42
static
$cache = [];
43
44
$ratingEntityId
= $this->
getEntityId
();
45
46
if
(
$ratingEntityId
<= 0)
47
{
48
return
;
49
}
50
51
$sourceFields
= [];
52
53
if
(isset($cache[
$ratingEntityId
]))
54
{
55
$sourceFields
= $cache[
$ratingEntityId
];
56
}
57
else
58
{
59
$userId = 0;
60
$bitrix24NewUserProvider =
new
Bitrix24NewUser
();
61
62
$res =
LogTable::getList
([
63
'filter'
=> [
64
'@EVENT_ID'
=> array_merge($this->
getEventId
(), $bitrix24NewUserProvider->getEventId() ),
65
'=RATING_ENTITY_ID'
=>
$ratingEntityId
66
],
67
'select'
=> [
'ID'
,
'ENTITY_ID'
]
68
]);
69
if
($logEntry = $res->fetch())
70
{
71
$userId = $logEntry[
'ENTITY_ID'
];
72
}
73
74
if
($userId > 0)
75
{
76
$res = UserTable::getList(array(
77
'filter'
=> [
78
'=ID'
=> $userId
79
],
80
'select'
=> [
81
'NAME'
,
'LAST_NAME'
,
'SECOND_NAME'
,
'LOGIN'
,
'UF_DEPARTMENT'
82
]
83
));
84
if
($user = $res->fetch())
85
{
86
$userName = \CUser::formatName(
87
\CSite::getNameFormat(),
88
$user,
89
true
,
90
false
91
);
92
$user[
'FULL_NAME'
] = $userName;
93
94
$user[
'DEPARTMENT_NAME'
] =
''
;
95
if
(
96
is_array($user[
'UF_DEPARTMENT'
])
97
&& !empty($user[
'UF_DEPARTMENT'
])
98
&& Loader::includeModule(
'iblock'
)
99
)
100
{
101
$res = SectionTable::getList([
102
'filter'
=> [
103
'ID'
=> $user[
'UF_DEPARTMENT'
]
104
],
105
'select'
=> [
'ID'
,
'NAME'
]
106
]);
107
if
($sectionFields = $res->fetch())
108
{
109
$user[
'DEPARTMENT_NAME'
] = $sectionFields[
'NAME'
];
110
}
111
}
112
113
$sourceFields
= array_merge($user, [
'LOG_ENTRY'
=> $logEntry ]);
114
$cache[
$ratingEntityId
] =
$sourceFields
;
115
}
116
}
117
}
118
119
if
(empty(
$sourceFields
))
120
{
121
return
;
122
}
123
124
$this->
setLogId
(
$sourceFields
[
'LOG_ENTRY'
][
'ID'
]);
125
$this->
setSourceFields
(
$sourceFields
);
126
$this->
setSourceTitle
(
Loc::getMessage
(
'SONET_LIVEFEED_INTRANET_NEW_USER_TITLE'
, [
127
'#USER_NAME#'
=>
$sourceFields
[
'FULL_NAME'
]
128
]));
129
}
130
131
public
function
getPinnedTitle
(): string
132
{
133
$result =
''
;
134
135
if
(ModuleManager::isModuleInstalled(
'bitrix24'
))
136
{
137
$result = Option::get(
'main'
,
'site_name'
);
138
}
139
else
140
{
141
if
(empty($this->sourceFields))
142
{
143
$this->
initSourceFields
();
144
}
145
146
$sourceFields
= $this->
getSourceFields
();
147
if
(empty(
$sourceFields
))
148
{
149
return
$result;
150
}
151
152
$result =
$sourceFields
[
'DEPARTMENT_NAME'
];
153
}
154
155
return
$result;
156
}
157
158
public
function
getPinnedDescription
()
159
{
160
$result =
''
;
161
162
if
(empty($this->sourceFields))
163
{
164
$this->
initSourceFields
();
165
}
166
167
$sourceFields
= $this->
getSourceFields
();
168
if
(empty(
$sourceFields
))
169
{
170
return
$result;
171
}
172
173
return
Loc::getMessage
(
'SONET_LIVEFEED_INTRANET_NEW_USER_PINNED_DESCRIPTION'
, [
174
'#USER_NAME#'
=>
$sourceFields
[
'FULL_NAME'
]
175
]);
176
}
177
178
public
static
function
canRead
($params): bool
179
{
180
return
true
;
181
}
182
183
protected
function
getPermissions
(array $post): string
184
{
185
return
self::PERMISSION_READ
;
186
}
187
188
public
function
getLiveFeedUrl
(): string
189
{
190
$pathToLogEntry =
''
;
191
192
$logId
= $this->
getLogId
();
193
if
(
$logId
)
194
{
195
$pathToLogEntry = Option::get(
'socialnetwork'
,
'log_entry_page'
,
''
, $this->
getSiteId
());
196
if
(!empty($pathToLogEntry))
197
{
198
$pathToLogEntry = \CComponentEngine::makePathFromTemplate($pathToLogEntry, array(
"log_id"
=>
$logId
));
199
}
200
}
201
202
return
$pathToLogEntry;
203
}
204
}
Bitrix\Iblock\SectionTable
Definition
sectiontable.php:61
Bitrix\Main\Config\Option
Definition
option.php:15
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ModuleManager
Definition
modulemanager.php:5
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Definition
datamanager.php:441
Bitrix\Main\UserTable
Definition
user.php:46
Bitrix\Socialnetwork\Livefeed\Bitrix24NewUser
Definition
bitrix24newuser.php:10
Bitrix\Socialnetwork\Livefeed\IntranetNewUser
Definition
intranetnewuser.php:16
Bitrix\Socialnetwork\Livefeed\IntranetNewUser\initSourceFields
initSourceFields()
Definition
intranetnewuser.php:40
Bitrix\Socialnetwork\Livefeed\IntranetNewUser\getCommentProvider
getCommentProvider()
Definition
intranetnewuser.php:35
Bitrix\Socialnetwork\Livefeed\IntranetNewUser\CONTENT_TYPE_ID
const CONTENT_TYPE_ID
Definition
intranetnewuser.php:18
Bitrix\Socialnetwork\Livefeed\IntranetNewUser\getPinnedTitle
getPinnedTitle()
Definition
intranetnewuser.php:131
Bitrix\Socialnetwork\Livefeed\IntranetNewUser\getPermissions
getPermissions(array $post)
Definition
intranetnewuser.php:183
Bitrix\Socialnetwork\Livefeed\IntranetNewUser\getType
getType()
Definition
intranetnewuser.php:30
Bitrix\Socialnetwork\Livefeed\IntranetNewUser\getLiveFeedUrl
getLiveFeedUrl()
Definition
intranetnewuser.php:188
Bitrix\Socialnetwork\Livefeed\IntranetNewUser\getEventId
getEventId()
Definition
intranetnewuser.php:25
Bitrix\Socialnetwork\Livefeed\IntranetNewUser\canRead
static canRead($params)
Definition
intranetnewuser.php:178
Bitrix\Socialnetwork\Livefeed\IntranetNewUser\getId
static getId()
Definition
intranetnewuser.php:20
Bitrix\Socialnetwork\Livefeed\IntranetNewUser\PROVIDER_ID
const PROVIDER_ID
Definition
intranetnewuser.php:17
Bitrix\Socialnetwork\Livefeed\IntranetNewUser\getPinnedDescription
getPinnedDescription()
Definition
intranetnewuser.php:158
Bitrix\Socialnetwork\Livefeed\LogComment
Definition
logcomment.php:9
Bitrix\Socialnetwork\Livefeed\Provider
Definition
provider.php:22
Bitrix\Socialnetwork\Livefeed\Provider\getEntityId
getEntityId()
Definition
provider.php:607
Bitrix\Socialnetwork\Livefeed\Provider\setLogId
setLogId($logId)
Definition
provider.php:612
Bitrix\Socialnetwork\Livefeed\Provider\$logId
$logId
Definition
provider.php:54
Bitrix\Socialnetwork\Livefeed\Provider\setSourceFields
setSourceFields(array $fields)
Definition
provider.php:627
Bitrix\Socialnetwork\Livefeed\Provider\setSourceTitle
setSourceTitle($title)
Definition
provider.php:665
Bitrix\Socialnetwork\Livefeed\Provider\getSiteId
getSiteId()
Definition
provider.php:94
Bitrix\Socialnetwork\Livefeed\Provider\$sourceFields
$sourceFields
Definition
provider.php:55
Bitrix\Socialnetwork\Livefeed\Provider\PERMISSION_READ
const PERMISSION_READ
Definition
provider.php:47
Bitrix\Socialnetwork\Livefeed\Provider\getSourceFields
getSourceFields()
Definition
provider.php:637
Bitrix\Socialnetwork\Livefeed\Provider\TYPE_POST
const TYPE_POST
Definition
provider.php:25
Bitrix\Socialnetwork\Livefeed\Provider\getLogId
getLogId($params=[])
Definition
provider.php:333
Bitrix\Socialnetwork\Livefeed\Provider\$ratingEntityId
int null $ratingEntityId
Definition
provider.php:59
Bitrix\Socialnetwork\LogTable
Definition
log.php:36
Bitrix\Socialnetwork\Livefeed
Definition
bitrix24newuser.php:3
modules
socialnetwork
lib
livefeed
intranetnewuser.php
Создано системой
1.10.0