- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/timeline/markcontroller.php
- Класс: Bitrix\Crm\Timeline\MarkController
- Вызов: MarkController::onItemMoveToFinalStage
public function onItemMoveToFinalStage(ItemIdentifier $item, string $finalStageSemantics, ?int $authorId = null): void
{
if (!PhaseSemantics::isDefined($finalStageSemantics))
{
throw new ArgumentException('Such stage semantics does not exist', 'finalStageSemantics');
}
if (!PhaseSemantics::isFinal($finalStageSemantics))
{
throw new ArgumentException('Stage should be final', 'finalStageSemantics');
}
$markTypeId = TimelineMarkType::getMarkTypeByPhaseSemantics($finalStageSemantics);
// do not create a successful entry to lead
if ($markTypeId === TimelineMarkType::SUCCESS && $item->getEntityTypeId() === CCrmOwnerType::Lead)
{
return;
}
$bindings = $this->getBindingsForItem($item);
$timelineEntryId = $this->getTimelineEntryFacade()->create(
TimelineEntry\Facade::MARK,
[
'MARK_TYPE_ID' => $markTypeId,
'ENTITY_TYPE_ID' => $item->getEntityTypeId(),
'ENTITY_ID' => $item->getEntityId(),
'AUTHOR_ID' => ($authorId > 0) ? $authorId : static::getCurrentOrDefaultAuthorId(),
'BINDINGS' => $bindings,
]
);
if ($timelineEntryId <= 0)
{
return;
}
$historyDataModel = null;
$timelineEntry = $this->getTimelineEntryFacade()->getById($timelineEntryId);
if (is_array($timelineEntry))
{
$historyDataModel = Container::getInstance()->getTimelineHistoryDataModelMaker()->prepareHistoryDataModel(
$timelineEntry,
['ENABLE_USER_INFO' => true]
);
}
foreach ($bindings as $binding)
{
Container::getInstance()->getTimelinePusher()->sendPullEvent(
$binding['ENTITY_TYPE_ID'],
$binding['ENTITY_ID'],
Pusher::ADD_ACTIVITY_PULL_COMMAND,
$historyDataModel
);
}
}