CAllCrmMailTemplate::Add

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmMailTemplate
  4. Add
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/mail_template.php
  • Класс: \CAllCrmMailTemplate
  • Вызов: CAllCrmMailTemplate::Add
static function Add(&$arFields, $options = null)
{
	global $DB;

	self::ClearErrors();

	if(!is_array($options))
	{
		$options = array();
	}

	if (!self::CheckFields('ADD', $arFields, 0))
	{
		return false;
	}

	if(isset($arFields['ID']))
	{
		unset($arFields['ID']);
	}

	if(!isset($arFields['SORT']))
	{
		$arFields['SORT'] = 100;
	}

	if(!isset($arFields['SCOPE']) || !CCrmMailTemplateScope::IsDefined($arFields['SCOPE']))
	{
		$arFields['SCOPE'] = CCrmMailTemplateScope::Personal;
	}

	if(!isset($arFields['IS_ACTIVE']))
	{
		$arFields['IS_ACTIVE'] = 'N';
	}

	if(!isset($arFields['TITLE']))
	{
		$arFields['TITLE'] = '';
	}

	if(!isset($arFields['EMAIL_FROM']))
	{
		$arFields['EMAIL_FROM'] = '';
	}

	if(!isset($arFields['SUBJECT']))
	{
		$arFields['SUBJECT'] = '';
	}

	if (!isset($arFields['ENTITY_TYPE_ID']))
		$arFields['ENTITY_TYPE_ID'] = 0;

	if (!isset($arFields['BODY_TYPE']))
		$arFields['BODY_TYPE'] = \CCrmContentType::BBCode;

	if(!isset($arFields['BODY']))
	{
		$arFields['BODY'] = '';
	}

	if(!isset($arFields['SING_REQUIRED']))
	{
		$arFields['SING_REQUIRED'] = 'N';
	}

	if (isset($arFields['CREATED']))
	{
		unset($arFields['CREATED']);
	}

	if (isset($arFields['LAST_UPDATED']))
	{
		unset($arFields['LAST_UPDATED']);
	}

	$arFields['~CREATED'] = $arFields['~LAST_UPDATED'] = $DB->CurrentTimeFunction();

	$currentUserID =  isset($options['CURRENT_USER_ID']) ? intval($options['CURRENT_USER_ID']) : CCrmPerms::GetCurrentUserID();

	if(!isset($arFields['AUTHOR_ID']))
	{
		$arFields['AUTHOR_ID'] = $currentUserID;
	}

	$arFields['EDITOR_ID'] = $arFields['AUTHOR_ID'];

	$ID = $DB->Add(CCrmMailTemplate::TABLE_NAME, $arFields, array('BODY'));
	if($ID === false)
	{
		self::RegisterError(array('text' => 'DB connection was lost.'));
		return false;
	}

	$arFields['ID'] = $ID = intval($ID);

	self::updateUserFields($ID, $arFields);

	$rsEvents = GetModuleEvents('crm', 'OnMailTemplateAdd');
	while ($arEvent = $rsEvents->Fetch())
	{
		ExecuteModuleEventEx($arEvent, array($ID, &$arFields));
	}

	return $ID;
}

Добавить комментарий