• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/classes/general/taskitem.php
  • Класс: CTaskItem
  • Вызов: CTaskItem::addProjectDependence
public function addProjectDependence($parentId, $linkType = DependenceTable::LINK_TYPE_FINISH_START)
{
	$exceptionInfo = array(
		'AUX' => array(
			'MESSAGE' => array(
				'FROM_TASK_ID' => $parentId,
				'TASK_ID' => $this->getId(),
				'LINK_TYPE' => $linkType
			)
		)
	);

	if(!BitrixTasksUtilRestriction::checkCanCreateDependence())
	{
		$exceptionInfo['ERROR'] = array(
			array(
				'CODE' => 'TRIAL_EXPIRED',
				'MESSAGE' => Loc::getMessage('TASKS_TRIAL_PERIOD_EXPIRED')
			)
		);

		throw new ActionRestrictedException(Loc::getMessage('TASK_CANT_ADD_LINK'), $exceptionInfo);
	}

	if($this->checkAccess(ActionDictionary::ACTION_TASK_DEADLINE))
	{
		$parentTask = CTaskItem::getInstanceFromPool($parentId, $this->executiveUserId);
		if($parentTask->checkAccess(ActionDictionary::ACTION_TASK_DEADLINE))
		{
			// DependenceTable does not care about PARENT_ID relations and other restrictions except
			// those which may compromise dependence mechanism logic
			// so PARENT_ID check and DATE assignment are placed outside

			$errors = array();
			if($this->checkIsSubtaskOf($parentId) || $parentTask->checkIsSubtaskOf($this->getId()))
			{
				$errors['TASKS_HAS_PARENT_RELATION'] = Loc::getMessage('TASKS_HAS_PARENT_RELATION');
			}
			else
			{
				$scheduler = BitrixTasksProcessorTaskScheduler::getInstance($this->executiveUserId);

				try
				{
					$scheduler->defineTaskDates($this->getData())->save();
					$scheduler->defineTaskDates($parentTask->getData())->save();
				}
				catch (TasksException $e)
				{
					throw new ActionFailedException(Loc::getMessage('TASK_CANT_ADD_LINK'), $exceptionInfo);
				}

				$result = DependenceTable::createLink($this->getId(), $parentId, array(
					//'TASK_DATA' => 			$this->getData(false),
					//'PARENT_TASK_DATA' => 	$parentTask->getData(false),
					'LINK_TYPE' => $linkType,
					'CREATOR_ID' => $this->executiveUserId
				));
				if(!$result->isSuccess())
				{
					$errors = array_merge($errors, $result->getErrorMessages());
				}
			}

			if(!empty($errors))
			{
				$exceptionInfo['ERROR'] = $errors;
				throw new ActionFailedException(Loc::getMessage('TASK_CANT_ADD_LINK'), $exceptionInfo);
			}

			return;
		}
	}

	throw new ActionNotAllowedException(Loc::getMessage('TASK_CANT_ADD_LINK'), $exceptionInfo);
}