timesheetService = $timesheetService; $this->projectService = $projectService; $this->clientService = $clientService; } /** * Displays the add time form. * * This is the creation entry point, so it gates on CREATE (matching post()) rather than VIEW — * a view-only role should not be able to load the time-logging form. Grant-equivalent for every * built-in role (the set holding timesheets.create is exactly editor+, the prior authOrRedirect). * * @param array $params Request parameters */ #[RequiresPermission(TimesheetsPermissions::CREATE, global: true)] public function get(array $params): Response { $this->tpl->assign('values', $this->timesheetService->getDefaultTimeValues()); $this->tpl->assign('info', ''); $this->assignTemplateVars(); return $this->tpl->display('timesheets.addTime'); } /** * Handles time entry creation. * * @param array $params Request parameters */ #[RequiresPermission(TimesheetsPermissions::CREATE, global: true)] public function post(array $params): Response { $info = ''; $values = $this->timesheetService->getDefaultTimeValues(); if (isset($_POST['save']) || isset($_POST['saveNew'])) { $values = $this->timesheetService->parseAddTimePostValues($_POST, $values); $info = $this->timesheetService->validateAndSaveTime($values); if (isset($_POST['saveNew'])) { $values = $this->timesheetService->getDefaultTimeValues(); } } $this->tpl->assign('values', $values); $this->tpl->assign('info', $info); $this->assignTemplateVars(); return $this->tpl->display('timesheets.addTime'); } /** * Assigns common template variables. */ private function assignTemplateVars(): void { $this->tpl->assign('allClients', $this->clientService->getAll()); $this->tpl->assign('allProjects', $this->projectService->getAll(showClosedProjects: false)); // Scope the picker to the current user's own timesheets; an unscoped call would require // timesheets.manage and over-fetch every user's entries. $this->tpl->assign('allTickets', $this->timesheetService->getAll( dateFrom: dtHelper()->userNow()->subYears(10)->setToDbTimezone(), dateTo: dtHelper()->userNow()->addYears(10)->setToDbTimezone(), userId: (int) session('userdata.id'), )); $this->tpl->assign('kind', $this->timesheetService->getLoggableHourTypes()); } }