-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckUrlCond.php
More file actions
140 lines (120 loc) · 4.06 KB
/
checkUrlCond.php
File metadata and controls
140 lines (120 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?
use Bitrix\Main\Loader;
use Bitrix\Main\Application;
if ( ! Loader::includeModule('catalog')) {
return;
}
if ( ! Loader::includeModule('sale')) {
return;
}
class checkUrlCond extends CSaleCondCtrlComplex
{
/**основной метод для проверки выполнения условий
* @param $arOneCondition
*
* @return bool
* @throws \Bitrix\Main\SystemException
*/
public static function isUrlCheck ($arOneCondition)
{
$result = false;
$arOneCondition = unserialize($arOneCondition);
$requestUri = Application::getInstance()->getContext()->getRequest()->getRequestUri();
switch ($arOneCondition['logic']) {
case 'Equal':
if ($requestUri === $arOneCondition['value']) {
$result = true;
}
break;
case 'Not':
if ($requestUri !== $arOneCondition['value']) {
$result = true;
}
break;
case 'Contain':
if (strpos($requestUri, $arOneCondition['value']) !== false) {
$result = true;
}
break;
case 'NotCont':
if (strpos($requestUri, $arOneCondition['value']) === false) {
$result = true;
}
break;
}
return $result;
}
public static function GetControlDescr ()
{
$description = parent::GetControlDescr();
$description['SORT'] = 100;
return $description;
}
public static function GetControlShow ($arParams)
{
$arControls = static::GetControls();
$arResult = array(
'controlgroup' => true,
'group' => false,
'label' => "Страницы сайта",
'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
'children' => array(),
);
foreach ($arControls as &$arOneControl) {
$arResult['children'][] = array(
'controlId' => $arOneControl['ID'],
'group' => false,
'label' => $arOneControl['LABEL'],
'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
'control' => array(
$arOneControl['PREFIX'],
static::GetLogicAtom($arOneControl['LOGIC']),
static::GetValueAtom($arOneControl['JS_VALUE']),
),
);
}
if (isset($arOneControl)) {
unset($arOneControl);
}
return $arResult;
}
public static function Generate ($arOneCondition, $arParams, $arControl, $arSubs = false)
{
return static::GetClassName() . "::isUrlCheck('" . serialize($arOneCondition) . "')";
}
public static function GetControls ($strControlID = false)
{
$arControlList = array(
'CondPageUrlName' => array(
'ID' => 'CondPageUrlName',
'FIELD' => 'NAME',
'FIELD_TYPE' => 'string',
'FIELD_LENGTH' => 255,
'LABEL' => "Страница сайта",
'PREFIX' => "URL",
'LOGIC' => static::GetLogic(array(
BT_COND_LOGIC_EQ,
BT_COND_LOGIC_NOT_EQ,
BT_COND_LOGIC_CONT,
BT_COND_LOGIC_NOT_CONT,
)),
'JS_VALUE' => array(
'type' => 'input',
),
'PHP_VALUE' => '',
),
);
if (false === $strControlID) {
return $arControlList;
} else if (isset($arControlList[$strControlID])) {
return $arControlList[$strControlID];
} else {
return false;
}
}
public static function GetShowIn ($arControls)
{
$arControls = array(CSaleCondCtrlGroup::GetControlID());
return $arControls;
}
}