Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
Builder.php
1
<?php
2
3
namespace
Bitrix\Socialnetwork\Space\List\Item
;
4
5
use
Bitrix\Main\Localization\Loc
;
6
use
Bitrix\Socialnetwork\Helper\AvatarManager
;
7
use
Bitrix\Socialnetwork\Internals\Space\Counter
;
8
use
Bitrix\Socialnetwork\Space\List\Dictionary
;
9
use
Bitrix\Socialnetwork\Space\List\UserRoleManager
;
10
11
final
class
Builder
12
{
13
private
AvatarManager
$avatarManager;
14
public
function
__construct
(
private
int
$userId)
15
{
16
$this->avatarManager =
new
AvatarManager
();
17
}
18
20
public
function
buildSpacesFromQueryResult
(array $queryResult): array
21
{
22
$spaces = [];
23
$counter =
Counter::getInstance
($this->userId);
24
25
foreach
($queryResult as $value)
26
{
27
$imageId = (int) ($value[
'IMAGE_ID'
] ?? 0);
28
if
($imageId)
29
{
30
$avatar = $this->avatarManager->getImageAvatar($imageId);
31
}
32
else
33
{
34
$avatar = $this->avatarManager->getIconAvatar($value[
'AVATAR_TYPE'
] ??
''
);
35
}
36
37
$visibilityType =
Dictionary::SPACE_VISIBILITY_TYPES
[
'open'
];
38
if
($value[
'OPENED'
] ===
'N'
)
39
{
40
$visibilityType =
Dictionary::SPACE_VISIBILITY_TYPES
[
'closed'
];
41
}
42
if
($value[
'VISIBLE'
] ===
'N'
)
43
{
44
$visibilityType =
Dictionary::SPACE_VISIBILITY_TYPES
[
'secret'
];
45
}
46
47
$userRole = (
new
UserRoleManager
())->getUserRole($value[
'ROLE'
], $value[
'ROLE_INIT_BY_TYPE'
]);
48
49
$spaces[] =
50
(
new
Space
())
51
->setId($value[
'ID'
])
52
->setName($value[
'NAME'
])
53
->setIsPinned((
int
)($value[
'PIN_ID'
]) > 0 && $userRole ===
Dictionary::USER_ROLES
[
'member'
])
54
->setDateActivity($value[
'DATE_ACTIVITY'
])
55
->setAvatar($avatar)
56
->setVisibilityType($visibilityType)
57
->setCounter($counter->getTotal($value[
'ID'
]))
58
->setLastActivityDescription(
''
)
59
->setUserRole($userRole)
60
->setFollow(\CSocNetSubscription::isUserSubscribed($this->userId,
'SG'
. $value[
'ID'
]))
61
;
62
}
63
64
return
$spaces;
65
}
66
67
public
function
buildCommonSpace
():
Space
68
{
69
$counter =
Counter::getInstance
($this->userId);
70
71
return
72
(
new
Space
())
73
->setId(0)
74
->setName(
Loc::getMessage
(
'SOCIALNETWORK_SPACES_LIST_COMMON_SPACE_NAME'
))
75
->setIsPinned(
false
)
76
->setDateActivity(
new
\
Bitrix
\Main\
Type
\
DateTime
())
77
->setAvatar($this->avatarManager->getIconAvatar(
'common-space'
))
78
->setVisibilityType(
Dictionary::SPACE_VISIBILITY_TYPES
[
'open'
])
79
->setCounter($counter->getTotal(0))
80
->setLastActivityDescription(
''
)
81
->setUserRole(
Dictionary::USER_ROLES
[
'member'
])
82
->setFollow(
true
)
83
;
84
}
85
}
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Socialnetwork\Helper\AvatarManager
Definition
avatarmanager.php:7
Bitrix\Socialnetwork\Internals\Space\Counter\getInstance
static getInstance(int $userId)
Definition
counter.php:19
Bitrix\Socialnetwork\Space\List\Dictionary
Definition
Dictionary.php:6
Bitrix\Socialnetwork\Space\List\Dictionary\SPACE_VISIBILITY_TYPES
const SPACE_VISIBILITY_TYPES
Definition
Dictionary.php:13
Bitrix\Socialnetwork\Space\List\Dictionary\USER_ROLES
const USER_ROLES
Definition
Dictionary.php:19
Bitrix\Socialnetwork\Space\List\Item\Builder
Definition
Builder.php:12
Bitrix\Socialnetwork\Space\List\Item\Builder\buildSpacesFromQueryResult
buildSpacesFromQueryResult(array $queryResult)
Definition
Builder.php:20
Bitrix\Socialnetwork\Space\List\Item\Builder\__construct
__construct(private int $userId)
Definition
Builder.php:14
Bitrix\Socialnetwork\Space\List\Item\Builder\buildCommonSpace
buildCommonSpace()
Definition
Builder.php:67
Bitrix\Socialnetwork\Space\List\Item\Space
Definition
Space.php:10
Bitrix\Socialnetwork\Space\List\UserRoleManager
Definition
UserRoleManager.php:8
Bitrix\Main\Type
Definition
collection.php:2
Bitrix\Socialnetwork\Internals\Space\Counter
Definition
dictionary.php:3
Bitrix\Socialnetwork\Space\List\Item
Definition
Builder.php:3
Bitrix
modules
socialnetwork
lib
Space
List
Item
Builder.php
Создано системой
1.10.0