• Модуль: sender
  • Путь к файлу: ~/bitrix/modules/sender/lib/stat/statistics.php
  • Класс: BitrixSenderStatStatistics
  • Вызов: Statistics::getRecommendedSendTime
public function getRecommendedSendTime($chainId = null)
{
	$timeList = $this->getReadingByDayTime(1);
	$len = count($timeList);
	$weightList = array();
	for ($i = 0; $i <= $len; $i++)
	{
		$j = $i + 1;
		if ($j > $len)
		{
			$j = 0;
		}
		else if ($j < 0)
		{
			$j = 23;
		}
		$weight = $timeList[$i]['CNT'] + $timeList[$j]['CNT'];
		$weightList[$i] = $weight;
	}

	$deliveryTime = 0;
	if ($chainId)
	{
		$listDb = PostingTable::getList(array(
			'select' => array('COUNT_SEND_ALL'),
			'filter' => array(
				'=MAILING_CHAIN_ID' => $chainId
			),
			'order' => array('DATE_CREATE' => 'DESC'),
		));
		if ($item = $listDb->fetch())
		{
			$deliveryTime = intval($item['COUNT_SEND_ALL']  * 1/10 * 1/3600);
		}
	}
	if ($deliveryTime <= 0)
	{
		$deliveryTime = 1;
	}

	arsort($weightList);
	foreach ($weightList as $i => $weight)
	{
		$i -= $deliveryTime;
		if ($i >= $len)
		{
			$i = $i - $len;
		}
		else if ($i < 0)
		{
			$i = $len + $i;
		}
		$timeList[$i]['DELIVERY_TIME'] = $deliveryTime;
		return $timeList[$i];
	}

	return null;
}