is::Delete

  1. Bitrix24 API (v. 23.675.0)
  2. tasks
  3. is
  4. Delete
  • Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/classes/general/taskelapsed.php
  • Класс: \is
  • Вызов: is::Delete
static function Delete($ID, $arParams = array())
{
	global $DB;

	$ID = intval($ID);
	if ($ID < 1)
		return false;

	$executiveUserId = null;
	if (isset($arParams['USER_ID']))
		$executiveUserId = (int) $arParams['USER_ID'];
	elseif ($userId = \Bitrix\Tasks\Util\User::getId())
		$executiveUserId = $userId;

	/** @noinspection PhpDeprecationInspection */
	$rsRemovingLogItem = self::getByID($ID);
	if ($rsRemovingLogItem && ($arRemovingLogItem = $rsRemovingLogItem->fetch()))
		$taskId = $arRemovingLogItem['TASK_ID'];
	else
		return (false);

	$curDuration = 0;
		$rsTask = CTasks::getList(
			array(),
			array('ID' => $taskId),
			array('ID', 'TIME_SPENT_IN_LOGS')
		);
	if ($rsTask && ($arTask = $rsTask->fetch()))
		$curDuration = (int) $arTask['TIME_SPENT_IN_LOGS'];

	foreach(GetModuleEvents('tasks', 'OnBeforeTaskElapsedTimeDelete', true) as $arEvent)
	{
		if (ExecuteModuleEventEx($arEvent, array($ID, $arRemovingLogItem))===false)
			return false;
	}

	$deleteResult = \Bitrix\Tasks\ElapsedTimeTable::delete($ID);

	$occurAsUserId = CTasksTools::getOccurAsUserId();
	if ( ! $occurAsUserId )
		$occurAsUserId = ($executiveUserId ? $executiveUserId : 1);

	$oLog = new CTaskLog();
	$oLog->Add(array(
		'TASK_ID'       =>  $taskId,
		'USER_ID'       =>  $occurAsUserId,
		'~CREATED_DATE' =>  $DB->currentTimeFunction(),
		'FIELD'         => 'TIME_SPENT_IN_LOGS',
		'FROM_VALUE'    =>  $curDuration,
		'TO_VALUE'      =>  $curDuration - (int) $arRemovingLogItem['SECONDS']
	));

	foreach(GetModuleEvents('tasks', 'OnTaskElapsedTimeDelete', true) as $arEvent)
		ExecuteModuleEventEx($arEvent, array($ID, &$arRemovingLogItem));

	return $deleteResult;
}

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