projectService = $projectService; $this->menuRepo = $menuRepo; $this->bomService = $bomService; $this->masterRefService = $masterRefService; } /** * Displays the list of all projects. * * @param array $params Request parameters */ public function get(array $params): Response { Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager], true); if (! Auth::userIsAtLeast(Roles::$manager)) { return $this->tpl->display('errors.error403', responseCode: 403); } if (! session()->exists('showClosedProjects')) { session(['showClosedProjects' => false]); } $this->tpl->assign('role', session('userdata.role')); if (Auth::userIsAtLeast(Roles::$admin)) { $allProjects = $this->projectService->getAll(session('showClosedProjects')); } else { $allProjects = $this->projectService->getClientManagerProjects(session('userdata.id'), session('userdata.clientId')); } // 为每个项目附加其关联的全局主数据(BOM/工艺文件/工具清单),供概览页展开显示 $typeNames = ['bom' => 'BOM', 'process' => '工艺文件', 'tooling' => '工具清单']; foreach ($allProjects as &$project) { $projectId = (int) $project['id']; $linkedMasters = []; foreach ($this->masterRefService->getRefs($projectId) as $ref) { $master = $this->bomService->getBom((int) $ref['masterId']); if ($master === false) { continue; } $master['refId'] = (int) $ref['id']; $master['typeName'] = $typeNames[$master['type'] ?? 'bom'] ?? 'BOM'; $linkedMasters[] = $master; } $project['linkedMasters'] = $linkedMasters; } unset($project); $this->tpl->assign('allProjects', $allProjects); // 项目概览甘特图数据(frappe-gantt 兼容 tasks) $gantt = $this->projectService->getProjectGanttData($allProjects); $this->tpl->assign('ganttTasks', $gantt['tasks'] ?? []); $this->tpl->assign('menuTypes', $this->menuRepo->getMenuTypes()); $this->tpl->assign('showClosedProjects', session('showClosedProjects')); return $this->tpl->display('projects.showAll'); } /** * Handles filter changes (show/hide closed projects). * * @param array $params Request parameters */ public function post(array $params): Response { Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager], true); if (isset($_POST['hideClosedProjects'])) { session(['showClosedProjects' => false]); } if (isset($_POST['showClosedProjects'])) { session(['showClosedProjects' => true]); } return $this->get($params); } }