function installDB() { global $DB, $APPLICATION; $this->errors = false; if (!$DB->query("SELECT 'x' FROM b_abtest", true)) { $createTestTemplates = true; $this->errors = $DB->runSQLBatch($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/abtest/install/db/' . strtolower($DB->type) . '/install.sql'); } if ($this->errors !== false) { $APPLICATION->throwException(implode('', $this->errors)); return false; } $eventManager = Bitrix\Main\EventManager::getInstance(); $eventManager->registerEventHandler('main', 'OnGetCurrentSiteTemplate', 'abtest', '\\Bitrix\\ABTest\\EventHandler', 'onGetCurrentSiteTemplate'); $eventManager->registerEventHandler('main', 'OnFileRewrite', 'abtest', '\\Bitrix\\ABTest\\EventHandler', 'onFileRewrite'); $eventManager->registerEventHandlerCompatible('main', 'OnPageStart', 'abtest', '\\Bitrix\\ABTest\\EventHandler', 'onPageStart'); $eventManager->registerEventHandlerCompatible('main', 'OnPanelCreate', 'abtest', '\\Bitrix\\ABTest\\EventHandler', 'onPanelCreate'); $eventManager->registerEventHandlerCompatible('conversion', 'OnGetAttributeTypes', 'abtest', '\\Bitrix\\ABTest\\EventHandler', 'onGetAttributeTypes'); $eventManager->registerEventHandlerCompatible('conversion', 'OnSetDayContextAttributes', 'abtest', '\\Bitrix\\ABTest\\EventHandler', 'onConversionSetContextAttributes'); registerModule($this->MODULE_ID); $defSite = Bitrix\Main\SiteTable::getList(array('order' => array('ACTIVE' => 'DESC', 'DEF' => 'DESC', 'SORT' => 'ASC'), 'select' => array('LID')))->fetch(); if (!empty($createTestTemplates) && CModule::includeModule('abtest') && !empty($defSite)) { $arTestTemplates = array(100 => array('ENABLED' => 'T', 'NAME' => getMessage('ABTEST_SAMPLE1_NAME'), 'DESCR' => getMessage('ABTEST_SAMPLE1_DESCR'), 'TEST_DATA' => array('id' => 'sample1', 'list' => array(array('type' => 'template', 'old_value' => '', 'new_value' => '')))), 200 => array('ENABLED' => 'T', 'NAME' => getMessage('ABTEST_SAMPLE2_NAME'), 'DESCR' => getMessage('ABTEST_SAMPLE2_DESCR'), 'TEST_DATA' => array('id' => 'sample2', 'list' => array(array('type' => 'page', 'old_value' => '', 'new_value' => '')))), 300 => array('ENABLED' => 'T', 'NAME' => getMessage('ABTEST_SAMPLE3_NAME'), 'DESCR' => getMessage('ABTEST_SAMPLE3_DESCR'), 'TEST_DATA' => array('id' => 'sample3', 'list' => array(array('type' => 'page', 'old_value' => '', 'new_value' => '')))), 400 => array('ENABLED' => 'T', 'NAME' => getMessage('ABTEST_SAMPLE4_NAME'), 'DESCR' => getMessage('ABTEST_SAMPLE4_DESCR'), 'TEST_DATA' => array('id' => 'sample4', 'list' => array(array('type' => 'page', 'old_value' => '', 'new_value' => '')))), 500 => array('ENABLED' => 'T', 'NAME' => getMessage('ABTEST_SAMPLE5_NAME'), 'DESCR' => getMessage('ABTEST_SAMPLE5_DESCR'), 'TEST_DATA' => array('id' => 'sample5', 'list' => array(array('type' => 'page', 'old_value' => '', 'new_value' => '')))), 600 => array('ENABLED' => 'T', 'NAME' => getMessage('ABTEST_SAMPLE6_NAME'), 'DESCR' => getMessage('ABTEST_SAMPLE6_DESCR'), 'TEST_DATA' => array('id' => 'sample6', 'list' => array(array('type' => 'page', 'old_value' => '', 'new_value' => '')))), 700 => array('ENABLED' => 'N', 'NAME' => getMessage('ABTEST_SAMPLE7_NAME'), 'DESCR' => getMessage('ABTEST_SAMPLE7_DESCR'), 'TEST_DATA' => array('id' => 'sample7', 'list' => array(array('type' => 'composite', 'old_value' => 'N', 'new_value' => 'Y')))), 800 => array('ENABLED' => 'N', 'NAME' => getMessage('ABTEST_SAMPLE8_NAME'), 'DESCR' => getMessage('ABTEST_SAMPLE8_DESCR'), 'TEST_DATA' => array('id' => 'sample8', 'list' => array(array('type' => 'cdn', 'old_value' => 'N', 'new_value' => 'Y')))), 900 => array('ENABLED' => 'N', 'NAME' => getMessage('ABTEST_SAMPLE9_NAME'), 'DESCR' => getMessage('ABTEST_SAMPLE9_DESCR'), 'TEST_DATA' => array('id' => 'sample9', 'list' => array(array('type' => 'bigdata', 'old_value' => 'N', 'new_value' => 'Y'))))); foreach ($arTestTemplates as $sort => $test) { $test['SITE_ID'] = $defSite['LID']; $test['ACTIVE'] = 'N'; $test['DURATION'] = 0; $test['PORTION'] = 30; $test['SORT'] = $sort; Bitrix\ABTest\ABTestTable::add($test); } } return true; }
} $isAdmin = $USER->canDoOperation('edit_php'); $ID = intval($ID); $abtest = Bitrix\ABTest\ABTestTable::getList(array('filter' => array('=ID' => $ID), 'select' => array('*', 'USER_NAME' => 'USER.NAME', 'USER_LAST_NAME' => 'USER.LAST_NAME', 'USER_SECOND_NAME' => 'USER.SECOND_NAME', 'USER_TITLE' => 'USER.TITLE', 'USER_LOGIN' => 'USER.LOGIN')))->fetch(); if (empty($abtest) || $abtest['ENABLED'] != 'Y') { $APPLICATION->setTitle(empty($abtest['NAME']) ? str_replace('#ID#', $ID, getMessage('ABTEST_REPORT_TITLE1')) : str_replace('#NAME#', $abtest['NAME'], getMessage('ABTEST_REPORT_TITLE2'))); $message = new CAdminMessage(array('MESSAGE' => getMessage('ABTEST_REPORT_NOTFOUND'), 'DETAILS' => getMessage('ABTEST_REPORT_DISABLED'))); require $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_admin_after.php'; echo $message->Show(); require $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/epilog_admin.php'; return; } if ($abtest['ACTIVE'] == 'Y') { $active_test = $abtest; } else { $active_test = Bitrix\ABTest\ABTestTable::getList(array('order' => array('SORT' => 'ASC'), 'filter' => array('SITE_ID' => $abtest['SITE_ID'], 'ACTIVE' => 'Y')))->fetch(); } $arGraphData = array(); if ($conversionAvailable) { $conversionRates = Bitrix\Conversion\RateManager::getTypes(array('ACTIVE' => true)); } if (!empty($conversionRates)) { reset($conversionRates); $baseRate = key($conversionRates); $allRates = array_keys($conversionRates); usort($allRates, function ($a, $b) use($conversionRates) { $a = $conversionRates[$a]; $b = $conversionRates[$b]; return $a['MODULE'] == $b['MODULE'] ? $b['SORT'] - $a['SORT'] : $a['SORT'] - $b['SORT']; }); $funnelRates = array('sale_cart', 'sale_order', 'sale_payment');
} else { $errors[] = getMessage('ABTEST_EMPTY_TEST_DATA'); } if (!empty($errors)) { $message = new CAdminMessage(array('MESSAGE' => getMessage('ABTEST_TEST_DATA_ERROR'), 'DETAILS' => join('<br>', $errors))); } if (empty($message)) { $arFields['ENABLED'] = 'Y'; if ($ID > 0) { $result = Bitrix\ABTest\ABTestTable::update($ID, $arFields); if ($result->isSuccess() && $abtest['ACTIVE'] == 'Y') { Bitrix\ABTest\Helper::clearCache($arFields['SITE_ID']); } } else { $arFields['ACTIVE'] = 'N'; $result = Bitrix\ABTest\ABTestTable::add($arFields); $ID = $result->isSuccess() ? $result->getId() : 0; } if (!$result->isSuccess()) { unset($arFields['ENABLED']); $message = new CAdminMessage(array('MESSAGE' => getMessage('ABTEST_SAVE_ERROR'), 'DETAILS' => join('<br>', $result->getErrorMessages()))); } else { if (strlen($save) > 0) { LocalRedirect('abtest_admin.php?lang=' . LANG); } else { LocalRedirect($APPLICATION->getCurPage() . '?lang=' . LANG . '&ID=' . $ID); } } } if ($ID > 0) { $abtest = array_merge($abtest, $arFields);
$arActiveTests[$abtest['SITE_ID']] = $abtest; } } } break; case 'stop': if (!Bitrix\ABTest\Helper::stopTest($ID)) { $lAdmin->addGroupError(getMessage('ABTEST_STOP_ERROR')); } break; } } } $arHeaders = array(array('id' => 'TITLE', 'content' => getMessage('ABTEST_TBL_HEADER_TITLE'), 'default' => true, 'sort' => 'name'), array('id' => 'ACTIVE', 'content' => getMessage('ABTEST_TBL_HEADER_STATE'), 'default' => true, 'sort' => 'active')); $lAdmin->addHeaders($arHeaders); $result = Bitrix\ABTest\ABTestTable::getList(array('order' => array(strtoupper($by) => $order), 'select' => array('*', 'USER_NAME' => 'USER.NAME', 'USER_LAST_NAME' => 'USER.LAST_NAME', 'USER_SECOND_NAME' => 'USER.SECOND_NAME', 'USER_TITLE' => 'USER.TITLE', 'USER_LOGIN' => 'USER.LOGIN'))); $result = new CAdminResult($result, $sTableID); $arRows = array(); $arActiveTests = array(); while ($abtest = $result->fetch()) { $arRows[] = $abtest; if ($abtest['ACTIVE'] == 'Y') { if (!isset($arActiveTests[$abtest['SITE_ID']])) { $arActiveTests[$abtest['SITE_ID']] = array(); } $arActiveTests[$abtest['SITE_ID']][] = $abtest['ID']; } } foreach ($arRows as &$abtest) { $row =& $lAdmin->addRow($abtest['ID'], $abtest); $row->addViewField('TITLE', sprintf('<div%s><b>%s</b><br>%s</div>', in_array($abtest['ENABLED'], array('T', 'Y')) ? '' : ' style="color: #808080; "', htmlspecialcharsbx($abtest['NAME']) ?: str_replace('#ID#', $abtest['ID'], getMessage('ABTEST_TEST_TITLE')), htmlspecialcharsbx($abtest['DESCR'])));