Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
eventhandler.php
1<?php
2
3namespace Bitrix\ABTest;
4
7
8Localization\Loc::loadMessages(__FILE__);
9
11{
12
18 public static function onPageStart()
19 {
20 $applicationContext = Application::getInstance()->getContext();
21
22 if ($mode = $applicationContext->getRequest()->get('abtest_mode'))
23 $_SESSION['ABTEST_MODE'] = $mode;
24 }
25
32 public static function onGetCurrentSiteTemplate(\Bitrix\Main\Event $event)
33 {
34 $template = $event->getParameter('template');
35 $result = null;
36
37 if ($context = Helper::getContext())
38 {
39 if ($context['section'] == 'B')
40 $result = Helper::getAlternative('template', $template);
41 }
42
43 return $result;
44 }
45
52 public static function onFileRewrite(\Bitrix\Main\Event $event)
53 {
54 $path = $event->getParameter('path');
55 $result = null;
56
57 if ($context = Helper::getContext())
58 {
59 if ($context['section'] == 'B')
60 $result = Helper::getAlternative('page', $path);
61 }
62
63 return $result;
64 }
65
71 public static function onGetAttributeTypes()
72 {
73 $sections = array(
74 'A' => array('NAME' => Localization\Loc::getMessage('ABTEST_CONV_TEST_SECTION_A_NAME')),
75 'B' => array('NAME' => Localization\Loc::getMessage('ABTEST_CONV_TEST_SECTION_B_NAME'))
76 );
77
78 return array(
79 'abtest' => array(
80 'MODULE' => 'abtest',
81 'NAME' => Localization\Loc::getMessage('ABTEST_CONVATTR_TEST_NAME'),
82 'SORT' => 5000,
83 'GET_VALUES' => function(array $ids)
84 {
85 $result = ABTestTable::getList(array(
86 'select' => array('ID', 'NAME'),
87 'filter' => array('ID' => $ids),
88 'order' => array('SORT' => 'ASC'),
89 ));
90
91 $values = array();
92 while ($abtest = $result->fetch())
93 {
94 if (empty($abtest['NAME']))
95 $abtest['NAME'] = str_replace('#ID#', $abtest['ID'], Localization\Loc::getMessage('ABTEST_CONV_TEST_TITLE'));
96
97 $values[$abtest['ID']] = array(
98 'NAME' => $abtest['NAME']
99 );
100 }
101
102 return $values;
103 }
104 ),
105 'abtest_section' => array(
106 'MODULE' => 'abtest',
107 'NAME' => Localization\Loc::getMessage('ABTEST_CONVATTR_TEST_SECTION_NAME'),
108 'SORT' => 5100,
109 'GET_VALUES' => function(array $ids) use ($sections)
110 {
111 $values = array();
112 foreach ($ids as $id)
113 {
114 if (!empty($sections[$id]))
115 $values[$id] = $sections[$id];
116 }
117
118 return $values;
119 }
120 ),
121 );
122 }
123
130 public static function onConversionSetContextAttributes(\Bitrix\Conversion\DayContext $conversionContext)
131 {
132 if ($abtest = Helper::getActiveTest())
133 {
134 if ($context = Helper::getContext())
135 {
136 if ($context['abtest'] != $abtest['ID'])
137 return;
138
139 if (!in_array($context['section'], array('A', 'B')))
140 return;
141
142 $conversionContext->setAttribute('abtest', $context['abtest']);
143 $conversionContext->setAttribute('abtest_section', $context['section']);
144 }
145 }
146 }
147
153 public static function onPanelCreate()
154 {
155 global $USER, $APPLICATION;
156
157 if ($USER->canDoOperation('view_other_settings'))
158 {
159 if ($context = Helper::getContext())
160 {
161 $baseUri = \CHTTP::urlDeleteParams($APPLICATION->getCurPage(), array('abtest_mode'));
162
163 $groupAUri = \CHTTP::urlAddParams($baseUri, array('abtest_mode' => intval($context['abtest']).'|A'));
164 $groupBUri = \CHTTP::urlAddParams($baseUri, array('abtest_mode' => intval($context['abtest']).'|B'));
165 $resetUri = \CHTTP::urlAddParams($baseUri, array('abtest_mode' => 'reset'));
166
167 $APPLICATION->addPanelButton(array(
168 'ID' => 'abtest_options',
169 'SRC' => $context['section'] == 'B' ? '/bitrix/images/abtest/ab-icon-b.png' : '/bitrix/images/abtest/ab-icon-a.png',
170 'TEXT' => str_replace('#ID#', intval($context['abtest']), Localization\Loc::getMessage('ABTEST_PANEL_MENU_BTN')),
171 'TYPE' => 'BIG',
172 'MAIN_SORT' => 900,
173 'SORT' => 10,
174 'MENU' => array(
175 array(
176 'ACTION' => "jsUtils.Redirect([], '".\CUtil::jsEscape($groupAUri)."'); ",
177 'TEXT' => Localization\Loc::getMessage('ABTEST_PANEL_MENU_MODE_A'),
178 'CHECKED' => $context['section'] == 'A' ? true : false,
179 ),
180 array(
181 'ACTION' => "jsUtils.Redirect([], '".\CUtil::jsEscape($groupBUri)."'); ",
182 'TEXT' => Localization\Loc::getMessage('ABTEST_PANEL_MENU_MODE_B'),
183 'CHECKED' => $context['section'] == 'B' ? true : false,
184 ),
185 array(
186 'ACTION' => "jsUtils.Redirect([], '".\CUtil::jsEscape($resetUri)."'); ",
187 'TEXT' => Localization\Loc::getMessage('ABTEST_PANEL_MENU_RESET'),
188 )
189 )
190 ));
191 }
192 }
193 }
194
195}
static onFileRewrite(\Bitrix\Main\Event $event)
static onConversionSetContextAttributes(\Bitrix\Conversion\DayContext $conversionContext)
static onGetCurrentSiteTemplate(\Bitrix\Main\Event $event)
static getActiveTest()
Definition helper.php:16
static getContext()
Definition helper.php:116
static getAlternative($type, $value)
Definition helper.php:208
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29