Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
orderprops_relation.php
1<?php
9
10use Bitrix\Main;
11
28class OrderPropsRelationTable extends Main\Entity\DataManager
29{
30 public const ENTITY_TYPE_PAY_SYSTEM = 'P';
31 public const ENTITY_TYPE_DELIVERY = 'D';
32 public const ENTITY_TYPE_LANDING = 'L';
33 public const ENTITY_TYPE_TRADING_PLATFORM = 'T';
34
35 public static function getFilePath()
36 {
37 return __FILE__;
38 }
39
40 public static function getTableName()
41 {
42 return 'b_sale_order_props_relation';
43 }
44
45 public static function getMap()
46 {
47 return [
48 'PROPERTY_ID' => [
49 'primary' => true,
50 'data_type' => 'integer',
51 'format' => '/^[0-9]{1,11}$/',
52 ],
53 'ENTITY_ID' => [
54 'primary' => true,
55 'data_type' => 'string',
56 'validation' => [__CLASS__, 'getEntityValidators'],
57 ],
58 'ENTITY_TYPE' => [
59 'primary' => true,
60 'data_type' => 'string',
61 'values' => [
66 ],
67 ],
68
69 'lPROPERTY' => [
70 'data_type' => 'Bitrix\Sale\Internals\OrderPropsTable',
71 'reference' => ['=this.PROPERTY_ID' => 'ref.ID'],
72 'join_type' => 'LEFT',
73 ],
74 ];
75 }
76
77 public static function getEntityValidators()
78 {
79 return array(
80 new Main\Entity\Validator\Length(1, 35),
81 );
82 }
83
84 public static function getRelationsByPropertyIdList(array $propertyIds) : array
85 {
86 static $relations = [];
87
88 $diff = array_diff($propertyIds, array_keys($relations));
89 if ($diff)
90 {
91 $dbRes = static::getList([
92 'select' => ['PROPERTY_ID', 'ENTITY_ID', 'ENTITY_TYPE'],
93 'filter' => ['@PROPERTY_ID' => $diff]
94 ]);
95
96 while ($data = $dbRes->fetch())
97 {
98 $relations[$data['PROPERTY_ID']][] = [
99 'ENTITY_ID' => $data['ENTITY_ID'],
100 'ENTITY_TYPE' => $data['ENTITY_TYPE']
101 ];
102 }
103
104 foreach ($diff as $id)
105 {
106 $relations[$id] = $relations[$id] ?? [];
107 }
108 }
109
110 return array_intersect_key($relations, array_fill_keys($propertyIds, true));
111 }
112
113 public static function getRelationsByPropertyId($propertyId) : array
114 {
115 $relations = static::getRelationsByPropertyIdList([$propertyId]);
116
117 return $relations[$propertyId];
118 }
119}