TaskFieldHandler::checkDatesInProject

  1. Bitrix24 API (v. 23.675.0)
  2. tasks
  3. TaskFieldHandler
  4. checkDatesInProject
  • Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/control/handler/taskfieldhandler.php
  • Класс: BitrixTasksControlHandlerTaskFieldHandler
  • Вызов: TaskFieldHandler::checkDatesInProject
private function checkDatesInProject()
{
	$groupId = 0;

	if (array_key_exists('GROUP_ID', $this->fields) && (int) $this->fields['GROUP_ID'] > 0)
	{
		$groupId = (int) $this->fields['GROUP_ID'];
	}
	elseif ($this->taskId)
	{
		$task = (TaskRegistry::getInstance())->getObject($this->taskId);
		if (
			$task
			&& !$task->isDeleted()
		)
		{
			$groupId = $task->getGroupId();
		}
	}

	if (!$groupId)
	{
		return;
	}

	if (
		Loader::includeModule('socialnetwork')
		&& ($group = CSocNetGroup::getById($groupId))
		&& ($group['PROJECT'] === 'Y')
		&& ($group['PROJECT_DATE_START'] || $group['PROJECT_DATE_FINISH'])
	)
	{
		$projectStartDate = DateTime::createFrom($group['PROJECT_DATE_START']);
		$projectFinishDate = DateTime::createFrom($group['PROJECT_DATE_FINISH']);

		if ($projectFinishDate)
		{
			$projectFinishDate->addSecond(86399);
		}

		$deadline = null;
		$endDatePlan = null;
		$startDatePlan = null;

		if (isset($this->fields['DEADLINE']) && $this->fields['DEADLINE'])
		{
			$deadline = DateTime::createFrom($this->fields['DEADLINE']);
		}
		if (isset($this->fields['END_DATE_PLAN']) && $this->fields['END_DATE_PLAN'])
		{
			$endDatePlan = DateTime::createFrom($this->fields['END_DATE_PLAN']);
		}
		if (isset($this->fields['START_DATE_PLAN']) && $this->fields['START_DATE_PLAN'])
		{
			$startDatePlan = DateTime::createFrom($this->fields['START_DATE_PLAN']);
		}

		if ($deadline && !$deadline->checkInRange($projectStartDate, $projectFinishDate))
		{
			throw new TaskFieldValidateException(Loc::getMessage('TASKS_DEADLINE_OUT_OF_PROJECT_RANGE'));
		}

		if ($endDatePlan && !$endDatePlan->checkInRange($projectStartDate, $projectFinishDate))
		{
			throw new TaskFieldValidateException(Loc::getMessage('TASKS_PLAN_DATE_END_OUT_OF_PROJECT_RANGE'));
		}

		if ($startDatePlan && !$startDatePlan->checkInRange($projectStartDate, $projectFinishDate))
		{
			throw new TaskFieldValidateException(Loc::getMessage('TASKS_PLAN_DATE_START_OUT_OF_PROJECT_RANGE'));
		}
	}
}

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