Ejemplo n.º 1
0
 /** Save context & attributes to database */
 protected function save()
 {
     if (($id =& $this->id) !== null) {
         throw new SystemException('Cannot save existent context!');
     }
     $id = self::EMPTY_CONTEXT_ID;
     if ($attributes = $this->attributes) {
         // leave only one attribute in group
         static $groupedTypes;
         if (!$groupedTypes) {
             $groupedTypes = AttributeManager::getGroupedTypes();
             unset($groupedTypes[null]);
         }
         foreach ($groupedTypes as $types) {
             $intersection = array_intersect_key($types, $attributes);
             if (count($intersection) > 1) {
                 array_shift($intersection);
                 foreach ($intersection as $name => $type) {
                     unset($attributes[$name]);
                 }
             }
         }
         // save to database
         $snapshot = self::getSnapshot($attributes);
         $query = array('limit' => 1, 'select' => array('ID'), 'filter' => array('=SNAPSHOT' => $snapshot));
         if ($row = ContextTable::getList($query)->fetch()) {
             $id = (int) $row['ID'];
         } elseif (Option::get('conversion', 'CONTEXT_TABLE') != 'locked') {
             try {
                 $result = ContextTable::add(array('SNAPSHOT' => $snapshot));
                 if ($result->isSuccess()) {
                     $id = $result->getId();
                     foreach ($attributes as $name => $value) {
                         // TODO resetContext if not success and return null!!!
                         $result = ContextAttributeTable::add(array('CONTEXT_ID' => $id, 'NAME' => $name, 'VALUE' => (string) $value));
                     }
                 } else {
                     throw new DB\SqlQueryException();
                 }
             } catch (DB\SqlQueryException $e) {
                 if ($row = ContextTable::getList($query)->fetch()) {
                     $id = (int) $row['ID'];
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
$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'));
// 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'];
}
$site = $_GET['site'] ?: $userOptions['site'];
if (!($siteName = $sites[$site])) {
    list($site, $siteName) = each($sites);
}
// SPLITS
$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))) {