- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/manager/task/template.php
- Класс: Bitrix\Tasks\Manager\Task\Template
- Вызов: Template::get
static function get($userId, $itemId, array $parameters = array())
{
$errors = static::ensureHaveErrorCollection($parameters);
$result = array(
'DATA' => array(),
'CAN' => array(),
'ERRORS' => $errors
);
$userId = Assert::expectIntegerPositive($userId, '$userId');
$itemId = Assert::expectIntegerPositive($itemId, '$itemId');
$data = \CTaskTemplates::getList(array(), array('ID' => $itemId), array(), array('USER_ID' => $userId), array('*', 'UF_*'))->fetch();
$can = array();
if(empty($data))
{
$errors->add('ACCESS_DENIED.NO_TEMPLATE', 'Template not found');
return $result;
}
$data['ACCOMPLICES'] = Type::unserializeArray($data['ACCOMPLICES']);
$data['AUDITORS'] = Type::unserializeArray($data['AUDITORS']);
$data['REPLICATE_PARAMS'] = Type::unserializeArray($data['REPLICATE_PARAMS']);
// adapt responsibles
$responsibles = array();
if($data['MULTITASK'] == 'Y')
{
$responsibles = Type::unserializeArray($data['RESPONSIBLES']);
}
unset($data['RESPONSIBLES']);
if(empty($responsibles))
{
$responsibles = array(
$data['RESPONSIBLE_ID']
);
}
$data[Responsible::getCode(true)] = static::formatSetResponsible($responsibles);
// todo: temporal formatters, implement model object with array access and lazy data fetch/format
Originator::formatSet($data);
Auditor::formatSet($data);
Accomplice::formatSet($data);
ParentTask::formatSet($data);
Project::formatSet($data);
$deadline = static::getDeadLine($data['DEADLINE_AFTER']);
if($deadline != '')
{
$data['DEADLINE'] = $deadline;
}
// select sub-entity related data
if (!is_array($parameters['ENTITY_SELECT'] ?? null))
{
$parameters['ENTITY_SELECT'] = []; // none by default
}
$entitySelect = array_flip($parameters['ENTITY_SELECT']);
// select CHECKLIST sub entity
if(isset($entitySelect['CHECKLIST']))
{
$mgrResult = Template\CheckList::getListByParentEntity($userId, $itemId, $parameters);
$data[static::SE_PREFIX.'CHECKLIST'] = $mgrResult['DATA'];
if(!empty($mgrResult['CAN']))
{
$can[static::SE_PREFIX.'CHECKLIST'] = $mgrResult['CAN'];
}
}
// select RELATEDTASK sub entity
// todo: should be a separate class here, but for now this is okay
$related = Type::unserializeArray($data['DEPENDS_ON']);
unset($data['DEPENDS_ON']);
if(isset($entitySelect['RELATEDTASK']))
{
// in task entity tags come from a separate table, in template - from the same table
$seRelated = array();
foreach($related as $task)
{
$seRelated[] = array('ID' => $task);
}
$data[static::SE_PREFIX.'RELATEDTASK'] = $seRelated;
}
// select TAG sub entity
// todo: should be a separate class here, but for now this is okay
$tags = Type::unserializeArray($data['TAGS']);
unset($data['TAGS']);
if(isset($entitySelect['TAG']))
{
// in task entity tags come from a separate table, in template - from the same table
$seTag = array();
foreach($tags as $tag)
{
$seTag[] = array('NAME' => $tag);
}
$data[static::SE_PREFIX.'TAG'] = $seTag;
}
if ($parameters['DROP_PRIMARY'] ?? null)
{
unset($data['ID']);
$can = [];
}
$data[static::ACT_KEY] = $can;
$result['DATA'] = $data;
$result['CAN'] = $can;
return $result;
}