Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
discountmodule.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
8
Loc::loadMessages
(__FILE__);
9
36
class
DiscountModuleTable
extends
Main\Entity\DataManager
37
{
43
public
static
function
getTableName
()
44
{
45
return
'b_sale_discount_module'
;
46
}
47
53
public
static
function
getMap
()
54
{
55
return
array(
56
'ID'
=>
new
Main\
Entity
\
IntegerField
(
'ID'
, array(
57
'primary'
=>
true
,
58
'autocomplete'
=>
true
,
59
'title'
=>
Loc::getMessage
(
'DISCOUNT_MODULE_ENTITY_ID_FIELD'
)
60
)),
61
'DISCOUNT_ID'
=>
new
Main\
Entity
\
IntegerField
(
'DISCOUNT_ID'
, array(
62
'required'
=>
true
,
63
'title'
=>
Loc::getMessage
(
'DISCOUNT_MODULE_ENTITY_DISCOUNT_ID_FIELD'
)
64
)),
65
'MODULE_ID'
=>
new
Main\
Entity
\
StringField
(
'MODULE_ID'
, array(
66
'required'
=>
true
,
67
'validation'
=> array(__CLASS__,
'validateModuleId'
),
68
'title'
=>
Loc::getMessage
(
'DISCOUNT_MODULE_ENTITY_MODULE_ID_FIELD'
)
69
)),
70
);
71
}
77
public
static
function
validateModuleId
()
78
{
79
return
array(
80
new
Main\
Entity
\Validator\Length(
null
, 50),
81
);
82
}
83
90
public
static
function
deleteByDiscount
($discount)
91
{
92
$discount = (int)$discount;
93
if
($discount <= 0)
94
return
;
95
$conn =
Application::getConnection
();
96
$helper = $conn->getSqlHelper();
97
$conn->queryExecute(
98
'delete from '
.$helper->quote(self::getTableName()).
' where '
.$helper->quote(
'DISCOUNT_ID'
).
' = '
.$discount
99
);
100
}
101
110
public
static
function
updateByDiscount
($discount, $moduleList, $clear)
111
{
112
$discount = (int)$discount;
113
if
($discount <= 0)
114
return
false
;
115
$clear = ($clear ===
true
);
116
if
($clear)
117
{
118
self::deleteByDiscount
($discount);
119
}
120
if
(!empty($moduleList) && is_array($moduleList))
121
{
122
foreach
($moduleList as &$module)
123
{
124
$fields = array(
125
'DISCOUNT_ID'
=> $discount,
126
'MODULE_ID'
=> $module
127
);
128
$result = self::add($fields);
129
}
130
unset($module);
131
}
132
return
true
;
133
}
134
142
public
static
function
getByDiscount
($discountList, $filter = array())
143
{
144
$result = array();
145
if
(!empty($discountList) && is_array($discountList))
146
{
147
Main\Type\Collection::normalizeArrayValuesByInt($discountList);
148
if
(!empty($discountList))
149
{
150
if
(!is_array($filter))
151
$filter = array();
152
153
$discountRows = array_chunk($discountList, 500);
154
foreach
($discountRows as &$row)
155
{
156
$filter[
'@DISCOUNT_ID'
] = $row;
157
158
$moduleIterator = self::getList(array(
159
'select'
=> array(
'DISCOUNT_ID'
,
'MODULE_ID'
),
160
'filter'
=> $filter
161
));
162
while
($module = $moduleIterator->fetch())
163
{
164
$module[
'DISCOUNT_ID'
] = (int)$module[
'DISCOUNT_ID'
];
165
if
(!isset($result[$module[
'DISCOUNT_ID'
]]))
166
$result[$module[
'DISCOUNT_ID'
]] = array();
167
$result[$module[
'DISCOUNT_ID'
]][] = $module[
'MODULE_ID'
];
168
}
169
unset($module, $moduleIterator);
170
}
171
unset($row, $discountRows);
172
}
173
}
174
return
$result;
175
}
176
}
Bitrix\Catalog\DiscountModuleTable
Definition
discountmodule.php:35
Bitrix\Catalog\DiscountModuleTable\deleteByDiscount
static deleteByDiscount($discount)
Definition
discountmodule.php:88
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\DiscountModuleTable\getMap
static getMap()
Definition
discountmodule.php:53
Bitrix\Sale\Internals\DiscountModuleTable\deleteByDiscount
static deleteByDiscount($discount)
Definition
discountmodule.php:90
Bitrix\Sale\Internals\DiscountModuleTable\getByDiscount
static getByDiscount($discountList, $filter=array())
Definition
discountmodule.php:142
Bitrix\Sale\Internals\DiscountModuleTable\updateByDiscount
static updateByDiscount($discount, $moduleList, $clear)
Definition
discountmodule.php:110
Bitrix\Sale\Internals\DiscountModuleTable\validateModuleId
static validateModuleId()
Definition
discountmodule.php:77
Bitrix\Sale\Internals\DiscountModuleTable\getTableName
static getTableName()
Definition
discountmodule.php:43
Bitrix\Main
Bitrix\Sale\Internals
Definition
accountnumber.php:3
modules
sale
lib
internals
discountmodule.php
Создано системой
1.10.0