Example #1
0
 public static function getModules()
 {
     if (!($modules =& self::$modules)) {
         $default = array('ACTIVE' => !ModuleManager::isModuleInstalled('sale'));
         foreach (array(AttributeManager::getTypesInternal(), CounterManager::getTypesInternal(), RateManager::getTypesInternal()) as $types) {
             foreach ($types as $type) {
                 $modules[$type['MODULE']] = $default;
             }
         }
         if ($modules['sale']) {
             $modules['sale']['ACTIVE'] = true;
         }
         $modules = unserialize(Option::get('conversion', 'MODULES', 'a:0:{}')) + $modules;
         // TODO all modules with attributes must be active
         $modules['conversion'] = $modules['abtest'] = $modules['sender'] = $modules['seo'] = array('ACTIVE' => true);
         ksort($modules);
     }
     return $modules;
 }
Example #2
0
use Bitrix\Conversion\ReportContext;
use Bitrix\Main\Loader;
use Bitrix\Main\SiteTable;
use Bitrix\Main\Type\Date;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
Loader::IncludeModule('conversion');
if ($APPLICATION->GetGroupRight('conversion') < 'W') {
    $APPLICATION->AuthForm(Loc::getMessage('ACCESS_DENIED'));
}
$userOptions = CUserOptions::GetOption('conversion', 'filter', array());
// PERIOD
$from = ($d = $_GET['from'] ?: $userOptions['from']) && Date::isCorrect($d) ? new Date($d) : Date::createFromPhp(new DateTime('first day of last month'));
$to = ($d = $_GET['to'] ?: $userOptions['to']) && Date::isCorrect($d) ? new Date($d) : Date::createFromPhp(new DateTime('last day of this month'));
// RATES
if (!($rateTypes = RateManager::getTypes())) {
    die('No rates available!');
}
$rateName = $_GET['rate'] ?: $userOptions['rate'];
if (!($rateType = $rateTypes[$rateName])) {
    list($rateName, $rateType) = each($rateTypes);
}
// SITES
$sites = array();
$result = SiteTable::getList(array('select' => array('LID', 'NAME'), 'order' => array('DEF' => 'DESC', 'SORT' => 'ASC')));
while ($row = $result->fetch()) {
    $sites[$row['LID']] = $row['NAME'];
}
if (!$sites) {
    die('No sites available!');
}
Example #3
0
 /**
  * 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);
 }
Example #4
0
$groupedAttributeTypes = \Bitrix\Conversion\AttributeManager::getGroupedTypes();
// $splitGroups
unset($groupedAttributeTypes[null]);
$attributeGroupName = $_GET['split'] ?: $userOptions['split'];
// $splitGroupKey
if (!($attributeTypes = $groupedAttributeTypes[$attributeGroupName])) {
    list($attributeGroupName, $attributeTypes) = each($groupedAttributeTypes);
}
$attributeGroupTypes = \Bitrix\Conversion\AttributeGroupManager::getTypes();
$splits = array();
foreach ($attributeTypes as $name => $type) {
    $splits[$name] = array('NAME' => $name, 'TITLE' => $type['NAME'] ?: $name, 'SPLIT_BY' => $type['SPLIT_BY'], 'BG_COLOR' => $type['BG_COLOR'] ?: '#4b9ec1');
}
$splits += array('other' => array('TITLE' => Loc::getMessage('CONVERSION_SPLIT_OTHER'), 'BG_COLOR' => '#96c023'), 'total' => array('TITLE' => Loc::getMessage('CONVERSION_SPLIT_TOTAL'), 'BG_COLOR' => '#33ade1'));
// RATES
if ($rateTypes = RateManager::getTypes(array('ACTIVE' => true))) {
    $topRateName = $_GET['rate'] ?: $userOptions['rate'];
    if ($topRateType = $rateTypes[$topRateName]) {
        $rateTypes = array($topRateName => $topRateType) + $rateTypes;
    } else {
        list($topRateName, $topRateType) = each($rateTypes);
    }
    $scale = $topRateType['SCALE'];
} else {
    $topRateName = null;
    $topRateType = null;
    $scale = array(0.5, 1, 1.5, 2, 5);
}
// FILTER
$filter = array('from' => $from->toString(), 'to' => $to->toString(), 'site' => $site, 'split' => $attributeGroupName, 'rate' => $topRateName);
CUserOptions::SetOption('conversion', 'filter', array_merge($userOptions, $filter));
Example #5
0
 private static function getRatesRecursive(array $rateTypes, array $counters, $level)
 {
     if ($level > 0) {
         $level--;
         $rates = array();
         foreach ($counters as $k => $v) {
             $rates[$k] = self::getRatesRecursive($rateTypes, $v, $level);
         }
         return $rates;
     } else {
         return RateManager::getRatesCalculated($rateTypes, $counters);
     }
 }
Example #6
0
use Bitrix\Main\SiteTable;
use Bitrix\Main\Web\Json;
use Bitrix\Main\Type\Date;
use Bitrix\Main\Page\Asset;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
Loader::IncludeModule('conversion');
if ($APPLICATION->GetGroupRight('conversion') < 'W') {
    $APPLICATION->AuthForm(Loc::getMessage('ACCESS_DENIED'));
}
$userOptions = CUserOptions::GetOption('conversion', 'filter', array());
// PERIOD
$from = ($d = $_GET['from'] ?: $userOptions['from']) && Date::isCorrect($d) ? new Date($d) : Date::createFromPhp(new DateTime('first day of last month'));
$to = ($d = $_GET['to'] ?: $userOptions['to']) && Date::isCorrect($d) ? new Date($d) : Date::createFromPhp(new DateTime('last day of this month'));
// RATES
if (!($rateTypes = RateManager::getTypes(array('MODULE' => 'sale')))) {
    die('No rates available!');
}
$rateName = $_GET['rate'];
if (!($rateType = $rateTypes[$rateName])) {
    list($rateName, $rateType) = each($rateTypes);
}
// SITES
$sites = array();
$result = SiteTable::getList(array('select' => array('LID', 'NAME'), 'order' => array('DEF' => 'DESC', 'SORT' => 'ASC')));
while ($row = $result->fetch()) {
    $sites[$row['LID']] = $row['NAME'];
}
if (!$sites) {
    die('No sites available!');
}