Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ormconverter.php
1<?php
2
4
6use Bitrix\Location\Model\EO_Hierarchy;
7use Bitrix\Location\Model\EO_Hierarchy_Collection;
8use Bitrix\Location\Model\EO_Location;
9use Bitrix\Location\Model\EO_Location_Collection;
10use Bitrix\Location\Model\EO_LocationField_Collection;
11use Bitrix\Location\Model\EO_LocationName;
13
19final class OrmConverter
20{
29 public static function convertFieldsToOrm(Location $location): EO_LocationField_Collection
30 {
32
34 foreach ($location->getFieldCollection() as $field)
35 {
36 $result->add(
38 ->setType($field->getType())
39 ->setValue($field->getValue())
40 ->setLocationId($location->getId())
41 );
42 }
43
44 return $result;
45 }
46
56 public static function createLocation(EO_Location $ormLocation, string $languageId): Location
57 {
58 $result = (new Location())
59 ->setId($ormLocation->getId())
60 ->setCode($ormLocation->getCode())
61 ->setExternalId($ormLocation->getExternalId())
62 ->setSourceCode($ormLocation->getSourceCode())
63 ->setType(($ormLocation->getType()))
64 ->setLatitude($ormLocation->getLatitude())
65 ->setLongitude($ormLocation->getLongitude());
66
67 if($fields = $ormLocation->getFields())
68 {
70 foreach($fields as $field)
71 {
72 $result->setFieldValue($field->getType(), $field->getValue());
73 }
74 }
75
77 foreach($ormLocation->getName() as $ormName)
78 {
79 if($ormName->getLanguageId() === $languageId || $ormName->getLanguageId() === '')
80 {
81 $result->setName($ormName->getName());
82 $result->setLanguageId($ormName->getLanguageId());
83
84 if($ormName->getLanguageId() === $languageId)
85 {
86 break;
87 }
88 }
89 }
90
91 return $result;
92 }
93
104 public static function createCollection(EO_Location_Collection $collection, string $language): Location\Collection
105 {
106 $result = new Location\Collection();
107
109 foreach ($collection as $item)
110 {
111 $result->addItem(
112 self::createLocation($item, $language)
113 );
114 }
115 return $result;
116 }
117
128 public static function createParentCollection(EO_Hierarchy_Collection $ormHierarchy, string $languageId): Location\Parents
129 {
130 $result = new Location\Parents();
131
133 foreach ($ormHierarchy as $item)
134 {
135 $result->addItem(
136 self::createLocation(
137 $item->getAncestor(),
138 $languageId
139 )
140 );
141 }
142
143 return $result;
144 }
145}
setFieldValue(int $type, string $value)
Definition location.php:563
static createObject($setDefaultValues=true)