Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
discountentities.php
1
<?php
2
namespace
Bitrix\Sale\Internals
;
3
4
use
Bitrix\Main
;
5
use
Bitrix\Main\Application
;
6
use
Bitrix\Main\Localization\Loc
;
7
Loc::loadMessages
(__FILE__);
8
38
class
DiscountEntitiesTable
extends
Main\Entity\DataManager
39
{
45
public
static
function
getTableName
()
46
{
47
return
'b_sale_discount_entities'
;
48
}
49
55
public
static
function
getMap
()
56
{
57
return
array(
58
'ID'
=>
new
Main\
Entity
\
IntegerField
(
'ID'
, array(
59
'primary'
=>
true
,
60
'autocomplete'
=>
true
,
61
'title'
=>
Loc::getMessage
(
'DISCOUNT_ENTITIES_ENTITY_ID_FIELD'
)
62
)),
63
'DISCOUNT_ID'
=>
new
Main\
Entity
\
IntegerField
(
'DISCOUNT_ID'
, array(
64
'required'
=>
true
,
65
'title'
=>
Loc::getMessage
(
'DISCOUNT_ENTITIES_ENTITY_DISCOUNT_ID_FIELD'
)
66
)),
67
'MODULE_ID'
=>
new
Main\
Entity
\
StringField
(
'MODULE_ID'
, array(
68
'required'
=>
true
,
69
'validation'
=> array(__CLASS__,
'validateModuleId'
),
70
'title'
=>
Loc::getMessage
(
'DISCOUNT_ENTITIES_ENTITY_MODULE_ID_FIELD'
)
71
)),
72
'ENTITY'
=>
new
Main\
Entity
\
StringField
(
'ENTITY'
, array(
73
'required'
=>
true
,
74
'validation'
=> array(__CLASS__,
'validateEntity'
),
75
'title'
=>
Loc::getMessage
(
'DISCOUNT_ENTITIES_ENTITY_ENTITY_FIELD'
)
76
)),
77
'FIELD_ENTITY'
=>
new
Main\
Entity
\
StringField
(
'FIELD_ENTITY'
, array(
78
'required'
=>
true
,
79
'validation'
=> array(__CLASS__,
'validateFieldEntity'
),
80
'title'
=>
Loc::getMessage
(
'DISCOUNT_ENTITIES_ENTITY_FIELD_ENTITY_FIELD'
)
81
)),
82
'FIELD_TABLE'
=>
new
Main\
Entity
\
StringField
(
'FIELD_TABLE'
, array(
83
'required'
=>
true
,
84
'validation'
=> array(__CLASS__,
'validateFieldTable'
),
85
'title'
=>
Loc::getMessage
(
'DISCOUNT_ENTITIES_ENTITY_FIELD_TABLE_FIELD'
),
86
)),
87
'DISCOUNT'
=>
new
Main\
Entity
\ReferenceField(
88
'DISCOUNT'
,
89
'Bitrix\Sale\Internals\Discount'
,
90
array(
'=this.DISCOUNT_ID'
=>
'ref.ID'
),
91
array(
'join_type'
=>
'LEFT'
)
92
)
93
);
94
}
100
public
static
function
validateModuleId
()
101
{
102
return
array(
103
new
Main\
Entity
\Validator\Length(
null
, 50),
104
);
105
}
111
public
static
function
validateEntity
()
112
{
113
return
array(
114
new
Main\
Entity
\Validator\Length(
null
, 255),
115
);
116
}
122
public
static
function
validateFieldEntity
()
123
{
124
return
array(
125
new
Main\
Entity
\Validator\Length(
null
, 255),
126
);
127
}
133
public
static
function
validateFieldTable
()
134
{
135
return
array(
136
new
Main\
Entity
\Validator\Length(
null
, 255),
137
);
138
}
139
146
public
static
function
deleteByDiscount
($discount)
147
{
148
$discount = (int)$discount;
149
if
($discount <= 0)
150
return
;
151
$conn =
Application::getConnection
();
152
$helper = $conn->getSqlHelper();
153
$conn->queryExecute(
154
'delete from '
.$helper->quote(self::getTableName()).
' where '
.$helper->quote(
'DISCOUNT_ID'
).
' = '
.$discount
155
);
156
}
157
166
public
static
function
updateByDiscount
($discount, $entityList, $clear)
167
{
168
$discount = (int)$discount;
169
if
($discount <= 0)
170
return
false
;
171
$clear = ($clear ===
true
);
172
if
($clear)
173
{
174
self::deleteByDiscount
($discount);
175
}
176
if
(!empty($entityList) && is_array($entityList))
177
{
178
foreach
($entityList as &$entity)
179
{
180
$fields = array(
181
'DISCOUNT_ID'
=> $discount,
182
'MODULE_ID'
=> $entity[
'MODULE'
],
183
'ENTITY'
=> $entity[
'ENTITY'
],
184
'FIELD_ENTITY'
=> $entity[
'FIELD_ENTITY'
],
185
);
186
if
(is_array($fields[
'FIELD_ENTITY'
]))
187
$fields[
'FIELD_ENTITY'
] = implode(
'-'
, $fields[
'FIELD_ENTITY'
]);
188
if
(isset($entity[
'FIELD_TABLE'
]) && is_array($entity[
'FIELD_TABLE'
]))
189
{
190
foreach
($entity[
'FIELD_TABLE'
] as $oneField)
191
{
192
if
(empty($oneField))
193
continue
;
194
$fields[
'FIELD_TABLE'
] = $oneField;
195
$result = self::add($fields);
196
}
197
unset($oneField);
198
}
199
else
200
{
201
$fields[
'FIELD_TABLE'
] = (isset($entity[
'FIELD_TABLE'
]) ? $entity[
'FIELD_TABLE'
] : $entity[
'FIELD_ENTITY'
]);
202
$result = self::add($fields);
203
}
204
}
205
unset($entity);
206
}
207
return
true
;
208
}
209
218
public
static
function
getByDiscount
($discountList, $filter = array(), $groupModule =
true
)
219
{
220
$groupModule = ($groupModule ===
true
);
221
$result = array();
222
if
(!empty($discountList) && is_array($discountList))
223
{
224
Main\Type\Collection::normalizeArrayValuesByInt($discountList);
225
if
(!empty($discountList))
226
{
227
if
(!is_array($filter))
228
$filter = array();
229
230
$discountRows = array_chunk($discountList, 500);
231
foreach
($discountRows as &$row)
232
{
233
$filter[
'@DISCOUNT_ID'
] = $row;
234
235
$entityIterator = self::getList(array(
236
'select'
=> array(
'DISCOUNT_ID'
,
'MODULE_ID'
,
'ENTITY'
,
'FIELD_ENTITY'
,
'FIELD_TABLE'
),
237
'filter'
=> $filter
238
));
239
if
($groupModule)
240
{
241
while
($entity = $entityIterator->fetch())
242
{
243
unset($entity[
'DISCOUNT_ID'
]);
244
if
(!isset($result[$entity[
'MODULE_ID'
]]))
245
$result[$entity[
'MODULE_ID'
]] = array();
246
if
(!isset($result[$entity[
'MODULE_ID'
]][$entity[
'ENTITY'
]]))
247
$result[$entity[
'MODULE_ID'
]][$entity[
'ENTITY'
]] = array();
248
$result[$entity[
'MODULE_ID'
]][$entity[
'ENTITY'
]][$entity[
'FIELD_ENTITY'
]] = $entity;
249
}
250
}
251
else
252
{
253
while
($entity = $entityIterator->fetch())
254
{
255
$entity[
'DISCOUNT_ID'
] = (int)$entity[
'DISCOUNT_ID'
];
256
if
(!isset($result[$entity[
'DISCOUNT_ID'
]]))
257
$result[$entity[
'DISCOUNT_ID'
]] = array();
258
$result[$entity[
'DISCOUNT_ID'
]][] = $entity;
259
}
260
}
261
unset($entity, $entityIterator);
262
}
263
unset($row, $discountRows);
264
}
265
}
266
return
$result;
267
}
268
}
Bitrix\Catalog\Model\Entity
Definition
entity.php:12
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getConnection
static getConnection($name="")
Definition
application.php:611
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Fields\IntegerField
Definition
integerfield.php:20
Bitrix\Main\ORM\Fields\StringField
Definition
stringfield.php:20
Bitrix\Sale\Internals\DiscountEntitiesTable
Definition
discountentities.php:39
Bitrix\Sale\Internals\DiscountEntitiesTable\validateEntity
static validateEntity()
Definition
discountentities.php:111
Bitrix\Sale\Internals\DiscountEntitiesTable\getMap
static getMap()
Definition
discountentities.php:55
Bitrix\Sale\Internals\DiscountEntitiesTable\deleteByDiscount
static deleteByDiscount($discount)
Definition
discountentities.php:146
Bitrix\Sale\Internals\DiscountEntitiesTable\getByDiscount
static getByDiscount($discountList, $filter=array(), $groupModule=true)
Definition
discountentities.php:218
Bitrix\Sale\Internals\DiscountEntitiesTable\validateFieldTable
static validateFieldTable()
Definition
discountentities.php:133
Bitrix\Sale\Internals\DiscountEntitiesTable\validateFieldEntity
static validateFieldEntity()
Definition
discountentities.php:122
Bitrix\Sale\Internals\DiscountEntitiesTable\updateByDiscount
static updateByDiscount($discount, $entityList, $clear)
Definition
discountentities.php:166
Bitrix\Sale\Internals\DiscountEntitiesTable\validateModuleId
static validateModuleId()
Definition
discountentities.php:100
Bitrix\Sale\Internals\DiscountEntitiesTable\getTableName
static getTableName()
Definition
discountentities.php:45
Bitrix\Main
Bitrix\Sale\Internals
Definition
accountnumber.php:3
modules
sale
lib
internals
discountentities.php
Создано системой
1.10.0