- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/control/handler/templatefieldhandler.php
- Класс: BitrixTasksControlHandlerTemplateFieldHandler
- Вызов: TemplateFieldHandler::prepareResponsible
public function prepareResponsible(): self
{
if (
$this->templateId
&& !array_key_exists('RESPONSIBLES', $this->fields)
&& !array_key_exists('RESPONSIBLE_ID', $this->fields)
)
{
return $this;
}
if (
!array_key_exists('RESPONSIBLES', $this->fields)
&& !array_key_exists('RESPONSIBLE_ID', $this->fields)
)
{
throw new TemplateFieldValidateException(Loc::getMessage("TASKS_BAD_RESPONSIBLE_ID"));
}
if (!array_key_exists('RESPONSIBLE_ID', $this->fields))
{
$this->fields['RESPONSIBLE_ID'] = (int) array_values($this->fields['RESPONSIBLES'])[0];
}
if (
array_key_exists('RESPONSIBLES', $this->fields)
&& is_string($this->fields['RESPONSIBLES'])
)
{
$this->fields['RESPONSIBLES'] = unserialize($this->fields['RESPONSIBLES'], ['allowed_classes' => false]);
}
if (
(
!$this->templateId
&& (int)($this->fields['TPARAM_TYPE'] ?? null) !== CTaskTemplates::TYPE_FOR_NEW_USER
)
||
(
$this->templateId
&& (int) $this->templateData['TPARAM_TYPE'] !== CTaskTemplates::TYPE_FOR_NEW_USER
)
)
{
if(isset($this->fields["RESPONSIBLE_ID"]))
{
$r = CUser::GetByID($this->fields["RESPONSIBLE_ID"]);
if (!$r->Fetch())
{
throw new TemplateFieldValidateException(Loc::getMessage("TASKS_BAD_RESPONSIBLE_ID_EX"));
}
}
else
{
if(!$this->templateId)
{
throw new TemplateFieldValidateException(Loc::getMessage("TASKS_BAD_RESPONSIBLE_ID"));
}
}
}
if (
!$this->templateId
&& empty($this->fields['RESPONSIBLES'])
)
{
$this->fields['RESPONSIBLES'] = [$this->fields['RESPONSIBLE_ID']];
}
elseif (
empty($this->fields['RESPONSIBLES'])
&& empty($this->templateData['RESPONSIBLES'])
)
{
$this->fields['RESPONSIBLES'] = [$this->fields['RESPONSIBLE_ID']];
}
return $this;
}