/** * Returns A/B-test traffic amounts * * @param int $id A/B-test ID. * @return array */ public static function getTestCapacity($id) { $cache = new \CPHPCache(); if ($cache->initCache(time() - strtotime('today'), 'abtest_capacity_' . intval($id), '/abtest')) { $capacity = $cache->getVars(); } else { if (Loader::includeModule('conversion')) { if ($conversionRates = Conversion\RateManager::getTypes(array('ACTIVE' => true))) { if ($abtest = ABTestTable::getById($id)->fetch()) { $lid = $abtest['SITE_ID']; $baseRate = array_slice($conversionRates, 0, 1, true); $reportContext = new Conversion\ReportContext(); $reportContext->setAttribute('conversion_site', $lid); $reportContext->setAttribute('abtest', $id); $reportContext->setAttribute('abtest_section', 'A'); $groupAData = reset($reportContext->getRatesDeprecated($baseRate, array(), null)); $reportContext->unsetAttribute('abtest_section', 'A'); $reportContext->setAttribute('abtest_section', 'B'); $groupBData = reset($reportContext->getRatesDeprecated($baseRate, array(), null)); $capacity = array('A' => $groupAData['DENOMINATOR'], 'B' => $groupBData['DENOMINATOR']); $cache->startDataCache(strtotime('tomorrow') - time()); $cache->endDataCache($capacity); } } } } return !empty($capacity) ? $capacity : array('A' => 0, 'B' => 0); }
/** * Deletes an A/B-test * * @param int $id A/B-test ID. * @return bool */ public static function deleteTest($id) { if ($abtest = ABTestTable::getById($id)->fetch()) { $result = ABTestTable::delete(intval($id)); if ($result->isSuccess()) { if ($abtest['ACTIVE'] == 'Y') { Helper::clearCache($abtest['SITE_ID']); } return true; } } return false; }