• Модуль: sender
  • Путь к файлу: ~/bitrix/modules/sender/lib/entity/segment.php
  • Класс: BitrixSenderEntitySegment
  • Вызов: Segment::updateAddressCounters
static function updateAddressCounters($segmentId, array $counters)
{
	if (!$segmentId)
	{
		return false;
	}

	$count = 0;
	$countByType = array();
	foreach ($counters as $dataCounter)
	{
		$count += $dataCounter->getSummary();
		$list = $dataCounter->getList();
		foreach ($list as $typeId => $typeCount)
		{
			if (!isset($countByType[$typeId]))
			{
				$countByType[$typeId] = 0;
			}

			$countByType[$typeId] += $typeCount;
		}
	}


	$result = GroupTable::update($segmentId, array('ADDRESS_COUNT' => $count));
	if (!$result->isSuccess())
	{
		return false;
	}

	GroupCounterTable::deleteByGroupId($segmentId);
	foreach ($countByType as $typeId => $typeCount)
	{
		if (!$typeCount)
		{
			continue;
		}

		GroupCounterTable::add(array(
			'GROUP_ID' => $segmentId,
			'TYPE_ID' => $typeId,
			'CNT' => $typeCount,
		));
	}

	return true;
}