$arResult['SHOW_SECTION_MANAGE'] = 'N'; if ($isAccessToCounters) { if (CModule::Includemodule('intranet')) { $arDepartments = CIntranetUtils::GetSubordinateDepartments($arParams['USER_ID'], $bRecursive = false); } if (!empty($arDepartments)) { $arResult['SHOW_SECTION_MANAGE'] = 'Y'; } } } if ($arResult['SHOW_SECTION_MANAGE'] === 'Y' && $arParams['GROUP_ID'] > 0) { $arResult['SHOW_SECTION_MANAGE'] = 'N'; } if ($arResult['SHOW_SECTION_MANAGE'] === 'Y') { $arResult['SECTION_MANAGE_COUNTER'] = 0; if ($arEmployees = CTaskIntranetTools::getImmediateEmployees($arParams['USER_ID'])) { foreach ($arEmployees as $employeeId) { $employeeId = (int) $employeeId; $arResult['SECTION_MANAGE_COUNTER'] += CTaskListCtrl::getUserRoleCounterForUser($employeeId, CTaskListState::VIEW_ROLE_RESPONSIBLE) + CTaskListCtrl::getUserRoleCounterForUser($employeeId, CTaskListState::VIEW_ROLE_ACCOMPLICE) + CTaskListCtrl::getUserRoleCounterForUser($employeeId, CTaskListState::VIEW_ROLE_ORIGINATOR) + CTaskListCtrl::getUserRoleCounterForUser($employeeId, CTaskListState::VIEW_ROLE_AUDITOR); } } } // get states description $oListState = CTaskListState::getInstance($loggedInUserId); $arResult['VIEW_STATE'] = $oListState->getState(); $arResult['VIEW_STATE_RAW'] = $oListState->getRawState(); $oListCtrl = CTaskListCtrl::getInstance($arParams['USER_ID']); $oListCtrl->useState($oListState); if ($arParams["GROUP_ID"] > 0) { $oListCtrl->setFilterByGroupId((int) $arParams["GROUP_ID"]); } else {
public function executeComponent() { global $APPLICATION; $APPLICATION->SetTitle(GetMessage('TASKS_TITLE_TASKS')); if (!CModule::IncludeModule('tasks')) { ShowError(GetMessage('TASKS_MODULE_NOT_FOUND')); return 0; } if (!CModule::IncludeModule('intranet')) { return 0; } $this->arResult['DEPARTMENTS'] = array(); $this->processParams(); // preparw arResult if (!($this->arResult['LOGGED_IN_USER'] >= 1)) { return 0; } $nameTemplate = $this->arResult['NAME_TEMPLATE']; $startFromDepartments = $this->getInitDepartmentsIds(); $arDepartmentsData = CIntranetUtils::GetDepartmentsData($startFromDepartments); if (!is_array($arDepartmentsData) || empty($arDepartmentsData)) { $this->IncludeComponentTemplate(); return 0; } $allUsersIds = array(); $arSubDepartmentsUsers = array(); foreach ($arDepartmentsData as $departmentId => $departmentName) { $departmentHead = CIntranetUtils::GetDepartmentManagerID($departmentId); $arSubDepartmentsIds = CIntranetUtils::getSubDepartments($departmentId); $this->arResult['DEPARTMENTS'][$departmentId] = array('~TITLE' => $departmentName, 'TITLE' => htmlspecialcharsbx($departmentName), 'HEAD_USER_ID' => $departmentHead, 'RESPONSIBLES_TOTAL_TASKS' => 0, 'RESPONSIBLES_NOTICED_TASKS' => 0, 'ACCOMPLICES_TOTAL_TASKS' => 0, 'ACCOMPLICES_NOTICED_TASKS' => 0, 'ORIGINATORS_TOTAL_TASKS' => 0, 'ORIGINATORS_NOTICED_TASKS' => 0, 'AUDITORS_TOTAL_TASKS' => 0, 'AUDITORS_NOTICED_TASKS' => 0, 'USERS' => array(), 'SUBDEPARTMENTS' => array()); $rsUsers = CTaskIntranetTools::getDepartmentsUsers(array($departmentId), array('ID', 'PERSONAL_PHOTO', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN', 'WORK_POSITION')); $arUsers = array(); $arDepartmentUsersIds = array(); while ($arUser = $rsUsers->getNext()) { $arUser['USER_IN_SUBDEPS'] = false; $arUsers[] = $arUser; $arDepartmentUsersIds[] = (int) $arUser['ID']; } if ($departmentHead > 0) { $arImmediateEmployees = CTaskIntranetTools::getImmediateEmployees($departmentHead, array($departmentId)); if (is_array($arImmediateEmployees) && !empty($arImmediateEmployees)) { // Remove immediate manager's employees in subdeps, if they are already in current department $arImmediateEmployees = array_diff($arImmediateEmployees, $arDepartmentUsersIds); if (!empty($arImmediateEmployees)) { $rsUsers = CUser::GetList($by = 'ID', $order = 'ASC', array('ACTIVE' => 'Y', 'ID' => implode('|', array_unique($arImmediateEmployees))), array('SELECT' => array('UF_DEPARTMENT'), 'FIELDS' => array('ID', 'PERSONAL_PHOTO', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN', 'WORK_POSITION'))); while ($arUser = $rsUsers->getNext()) { $arUser['USER_IN_SUBDEPS'] = true; $arUsers[] = $arUser; } } } } foreach ($arUsers as $arUser) { $userId = (int) $arUser['ID']; $allUsersIds[] = $userId; $userPhoto = false; if ($arUser['PERSONAL_PHOTO'] > 0) { $userPhoto = CIntranetUtils::InitImage($arUser['PERSONAL_PHOTO'], 30, 0, BX_RESIZE_IMAGE_EXACT); } $tasksHref = CComponentEngine::MakePathFromTemplate($this->arResult['PATH_TO_USER_TASKS'], array('user_id' => $userId)); $this->arResult['DEPARTMENTS'][$departmentId]['USERS'][] = array('ID' => $userId, 'PHOTO' => $userPhoto, 'DEPARTMENT_HEAD' => $departmentHead == $userId ? 'Y' : 'N', 'USER_IN_SUBDEPS' => $arUser['USER_IN_SUBDEPS'] ? 'Y' : 'N', 'FORMATTED_NAME' => CUser::FormatName($nameTemplate, array('NAME' => $arUser['~NAME'], 'LAST_NAME' => $arUser['~LAST_NAME'], 'SECOND_NAME' => $arUser['~SECOND_NAME'], 'LOGIN' => $arUser['~LOGIN']), true, true), 'WORK_POSITION' => $arUser['WORK_POSITION'], '~WORK_POSITION' => $arUser['~WORK_POSITION'], 'NAME' => $arUser['NAME'], 'LAST_NAME' => $arUser['LAST_NAME'], 'SECOND_NAME' => $arUser['SECOND_NAME'], '~NAME' => $arUser['~NAME'], '~LAST_NAME' => $arUser['~LAST_NAME'], '~SECOND_NAME' => $arUser['~SECOND_NAME'], 'HREF' => CComponentEngine::MakePathFromTemplate($this->arResult['PATH_TO_USER'], array('user_id' => $userId)), 'RESPONSIBLES_TOTAL_TASKS' => 0, 'RESPONSIBLES_NOTICED_TASKS' => 0, 'ACCOMPLICES_TOTAL_TASKS' => 0, 'ACCOMPLICES_NOTICED_TASKS' => 0, 'ORIGINATORS_TOTAL_TASKS' => 0, 'ORIGINATORS_NOTICED_TASKS' => 0, 'AUDITORS_TOTAL_TASKS' => 0, 'AUDITORS_NOTICED_TASKS' => 0, 'RESPONSIBLES_TOTAL_HREF' => $tasksHref . '?F_CANCEL=Y&F_STATE=sR400', 'RESPONSIBLES_NOTICED_HREF' => null, 'ACCOMPLICES_TOTAL_HREF' => $tasksHref . '?F_CANCEL=Y&F_STATE=sR800', 'ACCOMPLICES_NOTICED_HREF' => null, 'ORIGINATORS_TOTAL_HREF' => $tasksHref . '?F_CANCEL=Y&F_STATE=sRg00', 'ORIGINATORS_NOTICED_HREF' => null, 'AUDITORS_TOTAL_HREF' => $tasksHref . '?F_CANCEL=Y&F_STATE=sRc00', 'AUDITORS_NOTICED_HREF' => null); } if (is_array($arSubDepartmentsIds)) { $arSubDepartmentsData = CIntranetUtils::GetDepartmentsData($arSubDepartmentsIds); foreach ($arSubDepartmentsIds as $subDepartmentId) { $title = ''; if (array_key_exists($subDepartmentId, $arSubDepartmentsData)) { $title = $arSubDepartmentsData[$subDepartmentId]; } $this->arResult['DEPARTMENTS'][$departmentId]['SUBDEPARTMENTS'][$subDepartmentId] = array('ID' => $subDepartmentId, '~TITLE' => $title, 'TITLE' => htmlspecialcharsbx($title), 'COUNTERS' => array('RESPONSIBLES_TOTAL_TASKS' => 0, 'RESPONSIBLES_NOTICED_TASKS' => 0, 'ACCOMPLICES_TOTAL_TASKS' => 0, 'ACCOMPLICES_NOTICED_TASKS' => 0, 'ORIGINATORS_TOTAL_TASKS' => 0, 'ORIGINATORS_NOTICED_TASKS' => 0, 'AUDITORS_TOTAL_TASKS' => 0, 'AUDITORS_NOTICED_TASKS' => 0), 'HREF' => '?DEP_ID=' . (int) $subDepartmentId); $arSubDepartmentsUsers[$subDepartmentId] = array(); } $rsUsers = CIntranetUtils::GetDepartmentEmployees($arSubDepartmentsIds, $bRecursive = false, $bSkipSelf = false); while ($arUser = $rsUsers->fetch()) { if (is_array($arUser['UF_DEPARTMENT'])) { $userId = (int) $arUser['ID']; $allUsersIds[] = $userId; foreach ($arUser['UF_DEPARTMENT'] as $subDepartmentId) { if ($subDepartmentId > 0) { $arSubDepartmentsUsers[$subDepartmentId][] = $userId; } } } } } usort($this->arResult['DEPARTMENTS'][$departmentId]['USERS'], function ($a, $b) { if ($a['USER_IN_SUBDEPS'] !== $b['USER_IN_SUBDEPS']) { if ($a['USER_IN_SUBDEPS'] === 'N') { return -1; } else { return 1; } } if ($a['DEPARTMENT_HEAD'] !== $b['DEPARTMENT_HEAD']) { if ($a['DEPARTMENT_HEAD'] === 'Y') { return -1; } else { return 1; } } return strcmp($a['FORMATTED_NAME'], $b['FORMATTED_NAME']); }); } $arCounters = self::getCounts($allUsersIds); foreach ($startFromDepartments as $departmentId) { foreach ($this->arResult['DEPARTMENTS'][$departmentId]['USERS'] as &$userData) { $arCounter = $arCounters[$userData['ID']]; $userData['RESPONSIBLES_TOTAL_TASKS'] = $arCounter['RESPONSIBLES_TOTAL_TASKS']; $userData['RESPONSIBLES_NOTICED_TASKS'] = $arCounter['RESPONSIBLES_NOTICED_TASKS']; $userData['ACCOMPLICES_TOTAL_TASKS'] = $arCounter['ACCOMPLICES_TOTAL_TASKS']; $userData['ACCOMPLICES_NOTICED_TASKS'] = $arCounter['ACCOMPLICES_NOTICED_TASKS']; $userData['ORIGINATORS_TOTAL_TASKS'] = $arCounter['ORIGINATORS_TOTAL_TASKS']; $userData['ORIGINATORS_NOTICED_TASKS'] = $arCounter['ORIGINATORS_NOTICED_TASKS']; $userData['AUDITORS_TOTAL_TASKS'] = $arCounter['AUDITORS_TOTAL_TASKS']; $userData['AUDITORS_NOTICED_TASKS'] = $arCounter['AUDITORS_NOTICED_TASKS']; if ($userData['USER_IN_SUBDEPS'] === 'N') { $this->arResult['DEPARTMENTS'][$departmentId]['RESPONSIBLES_TOTAL_TASKS'] += $arCounter['RESPONSIBLES_TOTAL_TASKS']; $this->arResult['DEPARTMENTS'][$departmentId]['RESPONSIBLES_NOTICED_TASKS'] += $arCounter['RESPONSIBLES_NOTICED_TASKS']; $this->arResult['DEPARTMENTS'][$departmentId]['ACCOMPLICES_TOTAL_TASKS'] += $arCounter['ACCOMPLICES_TOTAL_TASKS']; $this->arResult['DEPARTMENTS'][$departmentId]['ACCOMPLICES_NOTICED_TASKS'] += $arCounter['ACCOMPLICES_NOTICED_TASKS']; $this->arResult['DEPARTMENTS'][$departmentId]['ORIGINATORS_TOTAL_TASKS'] += $arCounter['ORIGINATORS_TOTAL_TASKS']; $this->arResult['DEPARTMENTS'][$departmentId]['ORIGINATORS_NOTICED_TASKS'] += $arCounter['ORIGINATORS_NOTICED_TASKS']; $this->arResult['DEPARTMENTS'][$departmentId]['AUDITORS_TOTAL_TASKS'] += $arCounter['AUDITORS_TOTAL_TASKS']; $this->arResult['DEPARTMENTS'][$departmentId]['AUDITORS_NOTICED_TASKS'] += $arCounter['AUDITORS_NOTICED_TASKS']; } } unset($userData); foreach ($this->arResult['DEPARTMENTS'][$departmentId]['SUBDEPARTMENTS'] as $subDepartmentId => &$subDepData) { foreach ($arSubDepartmentsUsers[$subDepartmentId] as $userId) { $arCounter = $arCounters[$userId]; $subDepData['COUNTERS']['RESPONSIBLES_TOTAL_TASKS'] += $arCounter['RESPONSIBLES_TOTAL_TASKS']; $subDepData['COUNTERS']['RESPONSIBLES_NOTICED_TASKS'] += $arCounter['RESPONSIBLES_NOTICED_TASKS']; $subDepData['COUNTERS']['ACCOMPLICES_TOTAL_TASKS'] += $arCounter['ACCOMPLICES_TOTAL_TASKS']; $subDepData['COUNTERS']['ACCOMPLICES_NOTICED_TASKS'] += $arCounter['ACCOMPLICES_NOTICED_TASKS']; $subDepData['COUNTERS']['ORIGINATORS_TOTAL_TASKS'] += $arCounter['ORIGINATORS_TOTAL_TASKS']; $subDepData['COUNTERS']['ORIGINATORS_NOTICED_TASKS'] += $arCounter['ORIGINATORS_NOTICED_TASKS']; $subDepData['COUNTERS']['AUDITORS_TOTAL_TASKS'] += $arCounter['AUDITORS_TOTAL_TASKS']; $subDepData['COUNTERS']['AUDITORS_NOTICED_TASKS'] += $arCounter['AUDITORS_NOTICED_TASKS']; } } unset($subDepData); } $this->IncludeComponentTemplate(); }