Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
avatar.php
1<?php
2
11
13use Bitrix\Socialnetwork\EO_Workgroup;
15
16class Avatar
17{
18 public static function getValue(?EO_Workgroup $group): string
19 {
20 $classList = [
21 'sonet-ui-grid-group-avatar',
22 'ui-icon-common-user-group',
23 ];
24
25 $avatar = '<i></i>';
26
27 $imageId = (
28 $group
29 ? $group->getImageId()
30 : 0
31 );
32
33 if ($imageId > 0)
34 {
35 $file = \CFile::getFileArray($imageId);
36 if (!empty($file))
37 {
38 $fileResized = \CFile::resizeImageGet(
39 $file,
40 [
41 'width' => 100,
42 'height' => 100,
43 ]
44 );
45
46 $classList[] = 'ui-icon';
47 $avatar = "<i style=\"background-image: url('" . Uri::urnEncode(htmlspecialcharsbx($fileResized['src'])) . "'); background-size: cover\"></i>";
48 }
49 }
50 else
51 {
52 $avatarType = (string)$group->get('AVATAR_TYPE');
53 if ($avatarType !== '')
54 {
55 $classList[] = 'sonet-common-workgroup-avatar';
56 $classList[] = '--' . htmlspecialcharsbx(Helper\Workgroup::getAvatarTypeWebCssClass($avatarType));
57 }
58 else
59 {
60 $classList[] = 'ui-icon';
61 }
62 }
63
64 return '<div class="' . implode(' ', $classList) . '">' . $avatar . '</div>';
65 }
66}