- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/control/handler/taskfieldhandler.php
- Класс: BitrixTasksControlHandlerTaskFieldHandler
- Вызов: TaskFieldHandler::prepareMembers
public function prepareMembers(): self
{
if (!$this->taskId)
{
if (
!array_key_exists('CREATED_BY', $this->fields)
|| $this->fields['CREATED_BY'] < 1
)
{
throw new TaskFieldValidateException(Loc::getMessage('TASKS_BAD_CREATED_BY'));
}
if (!array_key_exists('RESPONSIBLE_ID', $this->fields))
{
throw new TaskFieldValidateException(Loc::getMessage('TASKS_BAD_RESPONSIBLE_ID'));
}
}
elseif (
array_key_exists('CREATED_BY', $this->fields)
&& $this->fields['CREATED_BY'] < 1
)
{
throw new TaskFieldValidateException(Loc::getMessage('TASKS_BAD_CREATED_BY'));
}
if (array_key_exists('RESPONSIBLE_ID', $this->fields))
{
$newResponsibleId = (int) $this->fields['RESPONSIBLE_ID'];
$userResult = CUser::GetList(
'id',
'asc',
['ID_EQUAL_EXACT' => $newResponsibleId],
[
'FIELDS' => ['ID'],
'SELECT' => ['UF_DEPARTMENT'],
]
);
$user = $userResult->Fetch();
if (!$user)
{
throw new TaskFieldValidateException(Loc::getMessage('TASKS_BAD_RESPONSIBLE_ID_EX'));
}
$currentResponsible = 0;
if ($this->taskId)
{
$task = (TaskRegistry::getInstance())->getObject($this->taskId);
if (
$task
&& !$task->isDeleted()
)
{
$currentResponsible = $task->getResponsibleId();
}
}
// new task or responsible changed
if (
!$this->taskId
|| ($currentResponsible && $currentResponsible !== $newResponsibleId)
)
{
$subordinateDepartments = Department::getSubordinateIds(
($this->fields['CREATED_BY'] ?? null),
true
);
$userDepartment = $user['UF_DEPARTMENT'];
$userDepartment = (is_array($userDepartment) ? $userDepartment : [$userDepartment]);
$isSubordinate = (count(array_intersect($subordinateDepartments, $userDepartment)) > 0);
if (
!array_key_exists('STATUS', $this->fields)
|| !$this->fields['STATUS']
)
{
$this->fields['STATUS'] = Status::PENDING;
}
if (!$isSubordinate)
{
$this->fields['ADD_IN_REPORT'] = 'N';
}
$this->fields['DECLINE_REASON'] = false;
}
}
$this->castMembers('ACCOMPLICES');
$this->castMembers('AUDITORS');
return $this;
}