• Модуль: report
  • Путь к файлу: ~/bitrix/modules/report/lib/visualconstructor/controller/board.php
  • Класс: BitrixReportVisualConstructorControllerBoard
  • Вызов: Board::createWidgetFromExisting
private function createWidgetFromExisting($formParams)
{
	$dashboardForUser = DashboardHelper::getDashboardByKeyForCurrentUser($formParams['boardId']);
	if (!$dashboardForUser)
	{
		$this->addError(new Error('Can't create widget because current user has not board to edit'));
		return false;
	}

	$widget = BitrixReportVisualConstructorEntityWidget::getWidgetByGId($formParams['patternWidgetId']);

	$copy = $widget->getCopyForCurrentUser();
	$cellId = 'cell_' . randString(4);
	try
	{
		$row = Row::getRowDefaultEntity(array(
			'cellIds' => array($cellId)
		));
	}
	catch (ArgumentException $e)
	{
		$this->errorCollection[] = new Error($e->getMessage());
		return false;
	}

	$row->setBoardId($formParams['boardId']);
	$copy->setWeight($cellId);
	$copy->setGId(Util::generateUserUniqueId());
	$copy->setIsPattern(false);
	$copy->setBoardId($formParams['boardId']);
	$row->addWidgets($copy);
	$row->setWeight(0);
	$dashboardForUser->addRows($row);
	$dashboardForUser->save();
	return $copy->getGId();
}