Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
manager.php
1<?php
2
4
5class Manager
6{
7 public function createMembersFromEntityObject($memberEOsCollection): array
8 {
9 $result = [];
10 foreach ($memberEOsCollection as $memberEO)
11 {
12 if (!empty($memberEO->getUser()))
13 {
14 $result[] = $this->createMemberFromUserEntityObject($memberEO->getUser(), $memberEO->getImage());
15 }
16 }
17
18 return $result;
19 }
20
21 public function createMemberFromUserEntityObject($userEO, $fileEO): Member
22 {
23 return (new Member())
24 ->setName($userEO->getName())
25 ->setLastName($userEO->getLastName())
26 ->setId($userEO->getId())
27 ->setAvatar($this->getFileSrc($fileEO))
28 ;
29 }
30
31 private function getFileSrc($fileEO): string
32 {
33 if (is_null($fileEO))
34 {
35 return '';
36 }
37
38 if ($fileEO->getWidth() <= 100 || $fileEO->getHeight() <= 100)
39 {
40 return \CFile::GetFileSRC($fileEO->collectValues());
41 }
42
43 $file = \CFile::resizeImageGet(
44 $fileEO->collectValues(),
45 ['width' => 100, 'height' => 100],
46 BX_RESIZE_IMAGE_EXACT,
47 false
48 );
49
50 return !empty($file['src']) ? $file['src'] : '';
51 }
52
53 public function convertToArray(Member $member): array
54 {
55 return [
56 'id' => $member->getId(),
57 'name' => $member->getName(),
58 'lastName' => $member->getLastName(),
59 'avatar' => $member->getAvatar(),
60 ];
61 }
62}