Task::get

  1. Bitrix24 API (v. 23.675.0)
  2. tasks
  3. Task
  4. get
  • Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/manager/task.php
  • Класс: Bitrix\Tasks\Manager\Task
  • Вызов: Task::get
static function get($userId, $taskId, array $parameters = array())
{
	$errors = static::ensureHaveErrorCollection($parameters);

	// todo: filterArguments() and filterResult() here on public mode?

	$data = static::getBasicData($userId, $taskId, $parameters);
	$can = array();

	if ($errors->checkNoFatals())
	{
		$can = array(static::ACT_KEY => &$data[ static::ACT_KEY ]); // for compatibility

		// select sub-entity related data
		$parameters['ENTITY_SELECT'] = $parameters['ENTITY_SELECT'] ?? null;
		if (!is_array($parameters['ENTITY_SELECT']))
		{
			// by default none is selected
			$parameters[ 'ENTITY_SELECT' ] = array();
			// could be of static::getLegalSubEntities()
		}
		$entitySelect = array_flip($parameters[ 'ENTITY_SELECT' ]);

		Originator::formatSet($data);
		Auditor::formatSet($data);
		Accomplice::formatSet($data);
		ParentTask::formatSet($data);
		Project::formatSet($data);

		// special case: responsibles
		$data[ Responsible::getCode(true) ] = array(array('ID' => $data[ 'RESPONSIBLE_ID' ]));

		$code = Tag::getCode(true);
		if (isset($entitySelect[ Tag::getCode() ]))
		{
			if (array_key_exists('TAGS', $data) && is_array($data['TAGS']))
			{
				$can[$code] = [];
				foreach ($data['TAGS'] as $tag)
				{
					$data[$code][] = ['NAME' => $tag];
				}
			}
			else
			{
				$mgrResult = Tag::getList($userId, $taskId);
				$data[ $code ] = $mgrResult[ 'DATA' ];
				if (!empty($mgrResult[ 'CAN' ]))
				{
					$can[ $code ] = $mgrResult[ 'CAN' ];
				}

				Tag::adaptSet($data); // for compatibility
			}
		}

		$code = Checklist::getCode(true);
		if (isset($entitySelect[ 'CHECKLIST' ]))
		{
			if (array_key_exists('CHECKLIST', $data) && is_array($data['CHECKLIST']))
			{
				$data['CHECKLIST'] = TaskCheckListFacade::fillActionsForItems($taskId, $userId, $data['CHECKLIST']);
				$data[$code] = $data['CHECKLIST'];
			}
			else
			{
				$mgrResult = TaskCheckListFacade::getItemsForEntity($taskId, $userId);
				$data[$code] = $mgrResult;
			}

			foreach ($data[$code] as $id => $item)
			{
				$can[$code][$id]['ACTION'] = $item['ACTION'];
			}
		}

		if (isset($entitySelect[ 'REMINDER' ]))
		{
			$mgrResult = Reminder::getListByParentEntity($userId, $taskId, $parameters);
			$data[ static::SE_PREFIX . 'REMINDER' ] = $mgrResult[ 'DATA' ];
			if (!empty($mgrResult[ 'CAN' ]))
			{
				$can[ static::SE_PREFIX . 'REMINDER' ] = $mgrResult[ 'CAN' ];
			}
		}

		if (isset($entitySelect[ 'LOG' ]))
		{
			$mgrResult = Log::getListByParentEntity($userId, $taskId, $parameters);
			$data[ static::SE_PREFIX . 'LOG' ] = $mgrResult[ 'DATA' ];
			if (!empty($mgrResult[ 'CAN' ]))
			{
				$can[ static::SE_PREFIX . 'LOG' ] = $mgrResult[ 'CAN' ];
			}
		}

		if (isset($entitySelect[ 'ELAPSEDTIME' ]))
		{
			$mgrResult = ElapsedTime::getListByParentEntity($userId, $taskId, $parameters);
			$data[ static::SE_PREFIX . 'ELAPSEDTIME' ] = $mgrResult[ 'DATA' ];
			if (!empty($mgrResult[ 'CAN' ]))
			{
				$can[ static::SE_PREFIX . 'ELAPSEDTIME' ] = $mgrResult[ 'CAN' ];
			}
		}

		if (isset($entitySelect[ 'PROJECTDEPENDENCE' ]))
		{
			$mgrResult = ProjectDependence::getListByParentEntity($userId, $taskId, array_merge($parameters, array(
				'TYPE' => ProjectDependence::INGOING,
				'DIRECT' => true,
				'DEPENDS_ON_DATA' => true
			)));
			$data[ static::SE_PREFIX . 'PROJECTDEPENDENCE' ] = $mgrResult[ 'DATA' ];
			if (!empty($mgrResult[ 'CAN' ]))
			{
				$can[ static::SE_PREFIX . 'PROJECTDEPENDENCE' ] = $mgrResult[ 'CAN' ];
			}
		}

		if (isset($entitySelect[ 'TEMPLATE' ]))
		{
			if ($data[ 'REPLICATE' ] == 'Y')
			{
				$template = Template::getByParentTask($userId, $taskId);
				$data[ static::SE_PREFIX . 'TEMPLATE' ] = $template[ 'DATA' ];
			}
		}

		if (isset($entitySelect[ 'TEMPLATE.SOURCE' ]))
		{
			if (intval($data[ 'FORKED_BY_TEMPLATE_ID' ]))
			{
				$template = Template::get($userId, intval($data[ 'FORKED_BY_TEMPLATE_ID' ]));

				// todo: remove this
				$tData = $template[ 'DATA' ];
				if (!empty($tData))
				{
					$tData = array(
						'ID' => $tData[ 'ID' ],
						'TITLE' => $tData[ 'TITLE' ],
						'TASK_ID' => $tData[ 'TASK_ID' ],
						'TPARAM_TYPE' => $tData[ 'TPARAM_TYPE' ],
						'REPLICATE_PARAMS' => $tData[ 'REPLICATE_PARAMS' ]
					);
				}
				$data[ static::SE_PREFIX . 'TEMPLATE.SOURCE' ] = $tData;
			}
		}

		if (isset($entitySelect[ 'RELATEDTASK' ]))
		{
			$mgrResult = RelatedTask::getListByParentEntity($userId, $taskId, $parameters);
			$data[ static::SE_PREFIX . 'RELATEDTASK' ] = $mgrResult[ 'DATA' ];
			if (!empty($mgrResult[ 'CAN' ]))
			{
				$can[ static::SE_PREFIX . 'RELATEDTASK' ] = $mgrResult[ 'CAN' ];
			}
		}

		if (isset($entitySelect[ 'TIMEMANAGER' ]) || isset($entitySelect[ 'DAYPLAN' ])) // 'TIMEMANAGER' condition left for compatibility
		{
			$subData = array($data[ 'ID' ] => &$data);
			$subCan = array($data[ 'ID' ] => &$can);
			static::injectDayPlanFields($userId, $parameters, $subData, $subCan);
		}
	}

	return array(
		'DATA' => $data,
		'CAN' => $can, // for compatibility
		'ERRORS' => $errors
	);
}

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