Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
discountgroup.php
1<?php
3
7
8Loc::loadMessages(__FILE__);
9
38class DiscountGroupTable extends Main\Entity\DataManager
39{
45 public static function getTableName()
46 {
47 return 'b_sale_discount_group';
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_GROUP_ENTITY_ID_FIELD')
62 )),
63 'DISCOUNT_ID' => new Main\Entity\IntegerField('DISCOUNT_ID', array(
64 'required' => true,
65 'title' => Loc::getMessage('DISCOUNT_GROUP_ENTITY_DISCOUNT_ID_FIELD')
66 )),
67 'ACTIVE' => new Main\Entity\BooleanField('ACTIVE', array(
68 'values' => array('N', 'Y'),
69 'default_value' => 'Y',
70 'title' => Loc::getMessage('DISCOUNT_GROUP_ENTITY_ACTIVE_FIELD')
71 )),
72 'GROUP_ID' => new Main\Entity\IntegerField('GROUP_ID', array(
73 'required' => true,
74 'title' => Loc::getMessage('DISCOUNT_GROUP_ENTITY_GROUP_ID_FIELD')
75 )),
76 'DISCOUNT' => new Main\Entity\ReferenceField(
77 'DISCOUNT',
78 'Bitrix\Sale\Internals\Discount',
79 array('=this.DISCOUNT_ID' => 'ref.ID'),
80 array('join_type' => 'LEFT')
81 )
82 );
83 }
84
91 public static function deleteByDiscount($discount)
92 {
93 $discount = (int)$discount;
94 if ($discount <= 0)
95 return;
97 $helper = $conn->getSqlHelper();
98 $conn->queryExecute(
99 'delete from '.$helper->quote(self::getTableName()).' where '.$helper->quote('DISCOUNT_ID').' = '.$discount
100 );
101 }
102
112 public static function updateByDiscount($discount, $groupList, $active, $clear)
113 {
114 $discount = (int)$discount;
115 if ($discount <= 0)
116 return false;
117 $clear = ($clear === true);
118 if ($clear)
119 {
120 self::deleteByDiscount($discount);
121 }
122 if (is_array($groupList))
123 {
124 $active = (string)$active;
125 if ($active != 'Y' && $active != 'N')
126 {
127 $discountIterator = self::getList(array(
128 'select' => array('ACTIVE'),
129 'filter' => array('=ID' => $discount)
130 ));
131 if ($discountActive = $discountIterator->fetch())
132 {
133 $active = $discountActive['ACTIVE'];
134 }
135 unset($discountActive, $discountIterator);
136 }
137 if ($active == 'Y' || $active == 'N')
138 {
139 if (empty($groupList))
140 $groupList[] = -1;
141
142 foreach ($groupList as &$group)
143 {
144 $fields = array(
145 'DISCOUNT_ID' => $discount,
146 'ACTIVE' => $active,
147 'GROUP_ID' => $group
148 );
149 $result = self::add($fields);
150 }
151 unset($group);
152 }
153 }
154 return true;
155 }
156
164 public static function changeActiveByDiscount($discount, $active)
165 {
166 $discount = (int)$discount;
167 $active = (string)$active;
168 if ($discount <= 0 || ($active != 'Y' && $active != 'N'))
169 return;
171 $helper = $conn->getSqlHelper();
172 $conn->queryExecute(
173 'update '.$helper->quote(self::getTableName()).
174 ' set '.$helper->quote('ACTIVE').' = \''.$active.'\' where '.
175 $helper->quote('DISCOUNT_ID').' = '.$discount
176 );
177 }
178
186 public static function getDiscountByGroups($groupList, $filter = array())
187 {
188 $result = array();
189 if (!empty($groupList) && is_array($groupList))
190 {
191 Main\Type\Collection::normalizeArrayValuesByInt($groupList);
192 if (!empty($groupList))
193 {
194 if (!is_array($filter))
195 $filter = array();
196
197 $groupRows = array_chunk($groupList, 500);
198 foreach ($groupRows as &$row)
199 {
200 $filter['@GROUP_ID'] = $row;
201
202 $groupIterator = self::getList(array(
203 'select' => array('DISCOUNT_ID'),
204 'filter' => $filter
205 ));
206 while ($group = $groupIterator->fetch())
207 {
208 $group['DISCOUNT_ID'] = (int)$group['DISCOUNT_ID'];
209 $result[$group['DISCOUNT_ID']] = true;
210 }
211 unset($group, $groupIterator);
212 }
213 unset($row, $groupRows);
214 if (!empty($result))
215 $result = array_keys($result);
216 }
217 }
218 return $result;
219 }
220
227 public static function getActiveDiscountByGroups($groupList)
228 {
229 return self::getDiscountByGroups($groupList, array('ACTIVE' => 'Y'));
230 }
231}
static getConnection($name="")
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static updateByDiscount($discount, $groupList, $active, $clear)
static changeActiveByDiscount($discount, $active)