• Модуль: bizproc
  • Путь к файлу: ~/bitrix/modules/bizproc/classes/general/document.php
  • Класс: CBPDocument
  • Вызов: CBPDocument::addDefaultWorkflowTemplates
static function addDefaultWorkflowTemplates($documentType, $additionalModuleId = null)
{
	if (!empty($additionalModuleId))
	{
		$additionalModuleId = preg_replace("/[^a-z0-9_.]/i", "", $additionalModuleId);
		$arModule = array($additionalModuleId, $documentType[0], 'bizproc');
	}
	else
	{
		$arModule = array($documentType[0], 'bizproc');
	}

	$bIn = false;
	foreach ($arModule as $sModule)
	{
		if (file_exists($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates'))
		{
			if($handle = opendir($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates'))
			{
				$bIn = true;
				while(false !== ($file = readdir($handle)))
				{
					if(!is_file($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates/'.$file))
						continue;
					$arFields = false;
					include($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates/'.$file);
					if(is_array($arFields))
					{
						/*
						 * If DOCUMENT_TYPE not defined, use current documentType
						 * Overwise check if DOCUMENT_TYPE equals to current documentType
						 */
						if (!array_key_exists("DOCUMENT_TYPE", $arFields))
							$arFields["DOCUMENT_TYPE"] = $documentType;
						elseif($arFields["DOCUMENT_TYPE"] != $documentType)
							continue;

						$arFields["SYSTEM_CODE"] = $file;
						if(is_object($GLOBALS['USER']))
							$arFields["USER_ID"] = $GLOBALS['USER']->GetID();
						$arFields["MODIFIER_USER"] = new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser);
						try
						{
							CBPWorkflowTemplateLoader::Add($arFields);
						}
						catch (Exception $e)
						{
						}
					}
				}
				closedir($handle);
			}
		}
		if ($bIn)
			break;
	}
}