Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ormfactory.php
1<?php
2
4
7use Bitrix\Location\Model\EO_Hierarchy_Collection;
8use Bitrix\Location\Model\EO_Location;
9use Bitrix\Location\Model\EO_Location_Collection;
10
11final class OrmFactory
12{
13 public static function createLocation(EO_Location $ormLocation, string $languageId): Location
14 {
15 $result = (new Location())
16 ->setId($ormLocation->getId())
17 ->setCode($ormLocation->getCode())
18 ->setExternalId($ormLocation->getExternalId())
19 ->setSourceCode($ormLocation->getSourceCode())
20 ->setType(($ormLocation->getType()))
21 ->setLatitude($ormLocation->getLatitude())
22 ->setLongitude($ormLocation->getLongitude());
23
24 if($fields = $ormLocation->getFields())
25 {
27 foreach($fields as $field)
28 {
29 $result->setFieldValue($field->getType(), $field->getValue());
30 }
31 }
32
33 foreach($ormLocation->getName() as $ormName)
34 {
35 if($ormName->getLanguageId() === $languageId || $ormName->getLanguageId() == '')
36 {
37 $result->setName($ormName->getName());
38 $result->setLanguageId($ormName->getLanguageId());
39
40 if($ormName->getLanguageId() === $languageId)
41 {
42 break;
43 }
44 }
45 }
46
47 return $result;
48 }
49
50 public static function createCollection(EO_Location_Collection $collection, string $language)
51 {
52 $result = new Location\Collection();
53
54 foreach ($collection as $item)
55 {
56 $result->addItem(
57 self::createLocation($item, $language)
58 );
59 }
60 return $result;
61 }
62
63 public static function createParentCollection(EO_Hierarchy_Collection $ormHierarchy, string $languageId)
64 {
65 $result = new Location\Parents();
66
67 foreach ($ormHierarchy as $item)
68 {
69 $result->addItem(
70 self::createLocation(
71 $item->getAncestor(),
72 $languageId
73 )
74 );
75 }
76
77 return $result;
78 }
79}
static createParentCollection(EO_Hierarchy_Collection $ormHierarchy, string $languageId)
static createCollection(EO_Location_Collection $collection, string $language)
setFieldValue(int $type, string $value)
Definition location.php:563