• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/control/handler/taskfieldhandler.php
  • Класс: BitrixTasksControlHandlerTaskFieldHandler
  • Вызов: TaskFieldHandler::prepareStatus
public function prepareStatus(): self
{
	if (!array_key_exists('STATUS', $this->fields))
	{
		return $this;
	}
	$this->fields['STATUS'] = (int) $this->fields['STATUS'];

	if ($this->fields['STATUS'] === Status::NEW)
	{
		$this->fields['STATUS'] = Status::PENDING;
	}

	$validValues = [
		Status::PENDING,
		Status::IN_PROGRESS,
		Status::SUPPOSEDLY_COMPLETED,
		Status::COMPLETED,
		Status::DEFERRED,
	];

	if (!in_array($this->fields['STATUS'], $validValues, true))
	{
		throw new TaskFieldValidateException(Loc::getMessage('TASKS_INCORRECT_STATUS'));
	}

	$nowDateTimeString = BitrixTasksUI::formatDateTime(UtilUser::getTime());

	if (!isset($this->fields['STATUS_CHANGED_DATE']))
	{
		$this->fields['STATUS_CHANGED_DATE'] = $nowDateTimeString;
	}

	if (
		!$this->taskId
		|| (int) $this->taskData['STATUS'] === $this->fields['STATUS']
	)
	{
		return $this;
	}

	if (!array_key_exists('STATUS_CHANGED_BY', $this->fields))
	{
		$this->fields['STATUS_CHANGED_BY'] = $this->userId;
	}
	if (!array_key_exists('STATUS_CHANGED_DATE', $this->fields))
	{
		$this->fields['STATUS_CHANGED_DATE'] = $nowDateTimeString;
	}

	if (
		$this->fields['STATUS'] === Status::COMPLETED
		|| $this->fields['STATUS'] === Status::SUPPOSEDLY_COMPLETED
	)
	{
		$this->fields['CLOSED_BY'] = $this->userId;
		$this->fields['CLOSED_DATE'] = $nowDateTimeString;
	}
	else
	{
		$this->fields['CLOSED_BY'] = false;
		$this->fields['CLOSED_DATE'] = false;

		if (
			$this->fields['STATUS'] === Status::IN_PROGRESS
			&& !array_key_exists('DATE_START', $this->fields)
		)
		{
			$this->fields['DATE_START'] = $nowDateTimeString;
		}
	}

	return $this;
}