Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Builder.php
1<?php
2
4
10
11final 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}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
buildSpacesFromQueryResult(array $queryResult)
Definition Builder.php:20