1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
avatarservice.php
См. документацию.
1<?php
2
4
8
9final class AvatarService
10{
11 private const IMAGE_TYPE = 'image';
12 private const DEFAULT_WIDTH = 150;
13 private const DEFAULT_HEIGHT = 150;
14
15 public function getAvatar(int $imageId): ?Avatar
16 {
17 if (!$this->isAvailable())
18 {
19 return null;
20 }
21
22 return new Avatar(self::IMAGE_TYPE, $this->getImageAvatarUri($imageId));
23 }
24
25 private function getImageAvatarUri(int $imageId): string
26 {
27 $result = '';
28
29 $file = \CFile::getFileArray($imageId);
30 if (!empty($file))
31 {
32 $fileResized = \CFile::resizeImageGet(
33 $file,
34 [
35 'width' => self::DEFAULT_WIDTH,
36 'height' => self::DEFAULT_HEIGHT,
37 ]
38 );
39
40 $result = Uri::urnEncode(htmlspecialcharsbx($fileResized['src']));
41 }
42
43 return $result;
44 }
45
46 private function isAvailable(): bool
47 {
48 return Loader::includeModule('socialnetwork');
49 }
50}
Определения loader.php:13
Определения uri.php:17
$result
Определения get_property_values.php:14
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701