Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
discountentity.php
1<?php
2namespace Bitrix\Catalog;
3
8Loc::loadMessages(__FILE__);
9
42{
43 const ENTITY_ELEMENT = 'ELEMENT';
44 const ENTITY_ELEMENT_PROPERTY = 'ELEMENT_PROPERTY';
45 const ENTITY_PRODUCT = 'PRODUCT';
46
52 public static function getTableName()
53 {
54 return 'b_catalog_discount_entity';
55 }
56
62 public static function getMap()
63 {
64 return [
65 'ID' => new ORM\Fields\IntegerField('ID', [
66 'primary' => true,
67 'autocomplete' => true,
68 'title' => Loc::getMessage('DISCOUNT_ENTITY_ENTITY_ID_FIELD')
69 ]),
70 'DISCOUNT_ID' => new ORM\Fields\IntegerField('DISCOUNT_ID', [
71 'required' => true,
72 'title' => Loc::getMessage('DISCOUNT_ENTITY_ENTITY_DISCOUNT_ID_FIELD')
73 ]),
74 'MODULE_ID' => new ORM\Fields\StringField('MODULE_ID', [
75 'required' => true,
76 'validation' => [__CLASS__, 'validateModuleId'],
77 'title' => Loc::getMessage('DISCOUNT_ENTITY_ENTITY_MODULE_ID_FIELD')
78 ]),
79 'ENTITY' => new ORM\Fields\StringField('ENTITY', [
80 'required' => true,
81 'validation' => [__CLASS__, 'validateEntity'],
82 'title' => Loc::getMessage('DISCOUNT_ENTITY_ENTITY_ENTITY_FIELD')
83 ]),
84 'ENTITY_ID' => new ORM\Fields\IntegerField('ENTITY_ID', [
85 'title' => Loc::getMessage('DISCOUNT_ENTITY_ENTITY_ENTITY_ID_FIELD')
86 ]),
87 'ENTITY_VALUE' => new ORM\Fields\StringField('ENTITY_VALUE', [
88 'title' => Loc::getMessage('DISCOUNT_ENTITY_ENTITY_ENTITY_VALUE_FIELD')
89 ]),
90 'FIELD_ENTITY' => new ORM\Fields\StringField('FIELD_ENTITY', [
91 'required' => true,
92 'validation' => [__CLASS__, 'validateFieldEntity'],
93 'title' => Loc::getMessage('DISCOUNT_ENTITY_ENTITY_FIELD_ENTITY_FIELD')
94 ]),
95 'FIELD_TABLE' => new ORM\Fields\StringField('FIELD_TABLE', [
96 'required' => true,
97 'validation' => [__CLASS__, 'validateFieldTable'],
98 'title' => Loc::getMessage('DISCOUNT_ENTITY_ENTITY_FIELD_TABLE_FIELD')
99 ]),
100 'DISCOUNT' => new ORM\Fields\Relations\Reference(
101 'DISCOUNT',
102 '\Bitrix\Catalog\Discount',
103 ['=this.DISCOUNT_ID' => 'ref.ID']
104 )
105 ];
106 }
107
113 public static function validateModuleId()
114 {
115 return [
117 ];
118 }
119
125 public static function validateEntity()
126 {
127 return [
129 ];
130 }
131
137 public static function validateFieldEntity()
138 {
139 return [
141 ];
142 }
143
149 public static function validateFieldTable()
150 {
151 return [
153 ];
154 }
155
162 public static function deleteByDiscount($discount)
163 {
164 $discount = (int)$discount;
165 if ($discount <= 0)
166 return;
167 $conn = Main\Application::getConnection();
168 $helper = $conn->getSqlHelper();
169 $conn->queryExecute(
170 'delete from '.$helper->quote(self::getTableName()).' where '.$helper->quote('DISCOUNT_ID').' = '.$discount
171 );
172 unset($helper, $conn);
173 }
174
183 public static function getByDiscount(array $discountList, $filter = [], $groupModule = true)
184 {
185 $groupModule = ($groupModule === true);
186 $result = [];
187 if (!empty($discountList))
188 {
189 Type\Collection::normalizeArrayValuesByInt($discountList);
190 if (!empty($discountList))
191 {
192 if (!is_array($filter))
193 $filter = [];
194
195 $discountRows = array_chunk($discountList, 500);
196 foreach ($discountRows as &$row)
197 {
198 $filter['@DISCOUNT_ID'] = $row;
199 $entityIterator = self::getList([
200 'select' => [
201 'DISCOUNT_ID', 'MODULE_ID',
202 'ENTITY', 'ENTITY_ID', 'ENTITY_VALUE', 'FIELD_ENTITY', 'FIELD_TABLE'
203 ],
204 'filter' => $filter
205 ]);
206 if ($groupModule)
207 {
208 while ($entity = $entityIterator->fetch())
209 {
210 unset($entity['DISCOUNT_ID']);
211 $module = $entity['MODULE_ID'];
212 $entityCode = $entity['ENTITY'];
213 if (!isset($result[$module]))
214 $result[$module] = [];
215 if (!isset($result[$module][$entityCode]))
216 $result[$module][$entityCode] = [];
217 $result[$module][$entityCode][$entity['FIELD_ENTITY']] = $entity;
218 }
219 unset($entityCode, $module);
220 }
221 else
222 {
223 while ($entity = $entityIterator->fetch())
224 {
225 $entity['DISCOUNT_ID'] = (int)$entity['DISCOUNT_ID'];
226 if (!isset($result[$entity['DISCOUNT_ID']]))
227 $result[$entity['DISCOUNT_ID']] = [];
228 $result[$entity['DISCOUNT_ID']][] = $entity;
229 }
230 }
231 unset($entity, $entityIterator);
232 }
233 unset($row, $discountRows);
234 }
235 }
236 return $result;
237 }
238}
static getByDiscount(array $discountList, $filter=[], $groupModule=true)
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getList(array $parameters=array())