Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
discountmodule.php
1<?php
3
7
8Loc::loadMessages(__FILE__);
9
36class 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;
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}
static getConnection($name="")
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getByDiscount($discountList, $filter=array())
static updateByDiscount($discount, $moduleList, $clear)