26 static::getControlDescr(),
33 $description = parent::getControlDescr();
34 $description[
'SORT'] = 700;
40 return get_called_class();
46 'controlgroup' =>
true,
49 'showIn' => static::getShowIn($params[
'SHOW_IN_GROUPS']),
53 foreach (static::getControls() as $control)
55 $result[
'children'][] = array(
56 'controlId' => $control[
'ID'],
58 'label' => $control[
'LABEL'],
59 'showIn' => static::getShowIn($params[
'SHOW_IN_GROUPS']),
62 static::getLogicAtom($control[
'LOGIC']),
63 static::getValueAtom($control[
'JS_VALUE'])
71 public static function checkBasket(array $order, array $userIds, $type)
73 if(empty($order[
'USER_ID']))
78 $orderUserId = (int)$order[
'USER_ID'];
79 if ($type ===
'Equal')
81 return in_array($orderUserId, $userIds);
83 elseif($type ===
'Not')
85 return !in_array($orderUserId, $userIds);
91 public static function generate($oneCondition, $params, $control, $subs =
false)
94 if (is_string($control))
96 $control = static::getControls($control);
98 $error = !is_array($control);
103 $values = static::check($oneCondition, $oneCondition, $control,
false);
104 $error = ($values ===
false);
109 switch ($control[
'ID'])
112 $stringArray =
'array('.implode(
',', $values[
'value']).
')';
113 $type = $oneCondition[
'logic'];
114 $result = static::getClassName() .
"::checkBasket({$params['ORDER']}, $stringArray, '{$type}')";
117 $result = self::generateOrderConditions($oneCondition, $params, $control, $values);
132 $controlList = array(
133 self::ENTITY_USER_ID => array(
134 'ID' => self::ENTITY_USER_ID,
135 'EXECUTE_MODULE' =>
'sale',
136 'MODULE_ID' =>
'main',
137 'MODULE_ENTITY' =>
'main',
139 'FIELD' =>
'USER_ID',
140 'FIELD_TYPE' =>
'int',
143 'LABEL' =>
Loc::getMessage(
'SALE_USER_CONDITION_CONTROL_FIELD_USER_ID'),
144 'PREFIX' =>
Loc::getMessage(
'SALE_USER_CONDITION_CONTROL_FIELD_USER_PREFIX'),
145 'LOGIC' => static::getLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ)),
147 'type' =>
'userPopup',
148 'popup_url' => self::getAdminSection().
'user_search.php',
149 'popup_params' => array(
150 'lang' => LANGUAGE_ID,
154 'user_load_url' =>
'/bitrix/admin/sale_discount_edit.php?lang=' . LANGUAGE_ID,
155 'coreUserInfo' =>
'Y',
157 'PHP_VALUE' => array(
166 BT_COND_LOGIC_EQ =>
Loc::getMessage(
'SALE_USER_CONDITION_CONTROL_FIELD_USER_GROUP_EQ'),
167 BT_COND_LOGIC_NOT_EQ =>
Loc::getMessage(
'SALE_USER_CONDITION_CONTROL_FIELD_USER_GROUP_NOT_EQ'),
170 $userGroups = array();
171 $iterator = Main\GroupTable::getList(array(
172 'select' => array(
'ID',
'NAME',
'C_SORT'),
173 'order' => array(
'C_SORT' =>
'ASC',
'NAME' =>
'ASC')
175 while ($row = $iterator->fetch())
176 $userGroups[$row[
'ID']] = $row[
'NAME'];
177 unset($row, $iterator);
179 'ID' => self::ENTITY_USER_GROUP_ID,
180 'EXECUTE_MODULE' =>
'all',
181 'MODULE_ID' =>
'main',
182 'MODULE_ENTITY' =>
'main',
183 'ENTITY' =>
'USER_GROUPS',
184 'FIELD' =>
'USER_GROUPS',
185 'FIELD_TYPE' =>
'int',
188 'LABEL' =>
Loc::getMessage(
'SALE_USER_CONDITION_CONTROL_FIELD_USER_GROUP_ID'),
189 'PREFIX' =>
Loc::getMessage(
'SALE_USER_CONDITION_CONTROL_FIELD_USER_GROUP_PREFIX'),
190 'LOGIC' => static::getLogicEx(array_keys($labels), $labels),
194 'values' => $userGroups,
197 'PHP_VALUE' => array(
201 unset($userGroups, $labels);
204 return static::searchControl($controlList, $controlId);
209 return array(\CSaleCondCtrlGroup::getControlID());
212 private static function generateOrderConditions(array $oneCondition, array $params, array $control, $values)
216 $logic = static::SearchLogic($values[
'logic'], $control[
'LOGIC']);
217 if (!empty($logic[
'OP'][$control[
'MULTIPLE']]))
221 if (isset($control[
'JS_VALUE'][
'multiple']) && $control[
'JS_VALUE'][
'multiple'] ==
'Y')
224 $joinOperator = ($logic[
'MULTI_SEP'] ??
' && ');
226 $field = $params[
'ORDER'].
'[\''.$control[
'FIELD'].
'\']
';
227 switch ($control['FIELD_TYPE
'])
233 $result = str_replace(
234 array('#FIELD#
', '#VALUE#
'),
235 array($field, $values['value
']),
236 $logic['OP
'][$control['MULTIPLE
']]
242 foreach ($values['value
'] as $item)
244 $list[] = str_replace(
245 array('#FIELD#
', '#VALUE#
'),
246 array($field, $item),
247 $logic['OP
'][$control['MULTIPLE
']]
250 $result = '((
'.implode(')
'.$joinOperator.'(
', $list).'))
';
259 $result = str_replace(
260 array('#FIELD#
', '#VALUE#
'),
261 array($field, '"'.EscapePHPString($values['value']).'"'),
262 $logic['OP
'][$control['MULTIPLE
']]
268 foreach ($values['value
'] as $item)
270 $list[] = str_replace(
271 array('#FIELD#
', '#VALUE#
'),
272 array($field, '"'.EscapePHPString($item).'"'),
273 $logic['OP
'][$control['MULTIPLE
']]
276 $result = '((
'.implode(')
'.$joinOperator.'(
', $list).'))
';
284 $result = str_replace(
285 array('#FIELD#
', '#VALUE#
'),
286 array($field, $values['value
']),
287 $logic['OP
'][$control['MULTIPLE
']]
293 foreach ($values['value
'] as $item)
295 $list[] = str_replace(
296 array('#FIELD#
', '#VALUE#
'),
297 array($field, $item),
298 $logic['OP
'][$control['MULTIPLE
']]
301 $result = '((
'.implode(')
'.$joinOperator.'(
', $list).'))
';
307 $result = 'isset(
'.$field.') &&
'.$result;
316 private static function getAdminSection()
318 //TODO: need use \CAdminPage::getSelfFolderUrl, but in general it is impossible now
319 return (defined('SELF_FOLDER_URL
') ? SELF_FOLDER_URL : '/
bitrix/admin/
');
static getControlShow($params)
static getShowIn($arControls)
static onBuildDiscountConditionInterfaceControls()
static getControls($controlId=false)
static checkBasket(array $order, array $userIds, $type)
static generate($oneCondition, $params, $control, $subs=false)
static includeModule($moduleName)
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static isModuleInstalled($moduleName)