• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/history/leadstatushistorywithsupposedentry.php
  • Класс: Bitrix\Crm\History\LeadStatusHistoryWithSupposedEntry
  • Вызов: LeadStatusHistoryWithSupposedEntry::prepareHistoriesFromExistHistory
static function prepareHistoriesFromExistHistory($existHistory)
{
	$sortedAllStatuses = self::getExistStatusIdList();
	$unSuccessStatusList = self::getLeadUnSuccessStatusList();

	$sortedAllStatusDESC = array_reverse($sortedAllStatuses);

	$history = [];
	foreach ($existHistory as $historyRow)
	{
		$history[$historyRow['STATUS_ID_FROM_HISTORY']] = $historyRow;
	}
	$statusIdsFromHistory = array_keys($history);

	$lastStatusFromHistory = end($statusIdsFromHistory);

	$histories = [];
	$lastHistoryRow = [];
	if (in_array($lastStatusFromHistory, $unSuccessStatusList))
	{
		$firstStatusId = $sortedAllStatuses[0];
		$histories[$lastStatusFromHistory] = self::prepareHistoryRow($history[$lastStatusFromHistory]);

		if (!empty($histories[$lastStatusFromHistory]))
		{
			$histories[$firstStatusId] = $histories[$lastStatusFromHistory];
			$histories[$firstStatusId]['IS_SUPPOSED'] = 'Y';
			$histories[$firstStatusId]['STATUS_ID'] = $firstStatusId;
			$histories[$firstStatusId]['STATUS_SEMANTIC_ID'] = 'P';
			$histories[$firstStatusId]['IS_LOST'] = 'N';
		}
	}
	else
	{
		foreach ($sortedAllStatusDESC as $statusId)
		{
			if (isset($history[$statusId]))
			{
				$histories[$statusId] = self::prepareHistoryRow($history[$statusId]);
				$lastHistoryRow = $histories[$statusId];
			}
			else
			{
				if (!empty($lastHistoryRow))
				{
					$lastHistoryRow['IS_SUPPOSED'] = 'Y';
					$lastHistoryRow['STATUS_ID'] = $statusId;
					$lastHistoryRow['STATUS_SEMANTIC_ID'] = 'P';
					$lastHistoryRow['IS_LOST'] = 'N';
				}
				$histories[$statusId] = $lastHistoryRow;
			}
		}
	}

	return $histories;
}