. */ use Gibbon\Services\Format; use Gibbon\Tables\DataTable; use Gibbon\Forms\Form; use Gibbon\Forms\DatabaseFormFactory; use Gibbon\Domain\Students\StudentGateway; use Gibbon\Domain\System\HookGateway; use Gibbon\Module\Reports\Forms\ReportingSidebarForm; use Gibbon\Module\Reports\Domain\ReportingCycleGateway; use Gibbon\Module\Reports\Domain\ReportingAccessGateway; use Gibbon\Module\Reports\Domain\ReportingScopeGateway; use Gibbon\Module\Reports\Domain\ReportingProgressGateway; use Gibbon\Domain\User\UserGateway; if (isActionAccessible($guid, $connection2, '/modules/Reports/reporting_write_byStudent.php') == false) { // Access denied $page->addError(__('You do not have access to this action.')); } else { // Proceed! $highestAction = getHighestGroupedAction($guid, $_GET['q'], $connection2); if (empty($highestAction)) { $page->addError(__('You do not have access to this action.')); return; } $gibbonPersonIDStudent = $_REQUEST['gibbonPersonIDStudent'] ?? ''; $gibbonPersonID = isActionAccessible($guid, $connection2, '/modules/Reports/reporting_cycles_manage.php') ? $_REQUEST['gibbonPersonID'] ?? $session->get('gibbonPersonID') : $session->get('gibbonPersonID'); $urlParams = [ 'gibbonSchoolYearID' => $_REQUEST['gibbonSchoolYearID'] ?? $session->get('gibbonSchoolYearID'), 'gibbonReportingCycleID' => $_GET['gibbonReportingCycleID'] ?? '', 'gibbonReportingScopeID' => $_GET['gibbonReportingScopeID'] ?? '', 'scopeTypeID' => $_GET['scopeTypeID'] ?? '', 'gibbonPersonID' => $gibbonPersonID, 'allStudents' => $_GET['allStudents'] ?? '', ]; if (!empty($_GET['criteriaSelector'])) { list($urlParams['gibbonReportingScopeID'], $urlParams['scopeTypeID']) = explode('-', $_GET['criteriaSelector']); } // SIDEBAR: Dropdowns $sidebarForm = $container->get(ReportingSidebarForm::class)->createForm($urlParams); $session->set('sidebarExtra', $sidebarForm->getOutput()); $page->scripts->add('chart'); $page->breadcrumbs ->add(__('My Reporting'), 'reporting_my.php', ['gibbonPersonID' => $gibbonPersonID]) ->add(__('Write Reports'), 'reporting_write.php', $urlParams) ->add(__('By Student')); $reportingAccessGateway = $container->get(ReportingAccessGateway::class); $reportingScope = $container->get(ReportingScopeGateway::class)->getByID($urlParams['gibbonReportingScopeID']); if (empty($reportingScope)) { $page->addError(__('The specified record cannot be found.')); return; } $reportingCycle = $container->get(ReportingCycleGateway::class)->getByID($reportingScope['gibbonReportingCycleID']); if (empty($reportingCycle)) { $page->addError(__('The specified record cannot be found.')); return; } // ACCESS CHECK: overall check (for high-level access) or per-scope check for general access $accessCheck = $reportingAccessGateway->getAccessToScopeByPerson($urlParams['gibbonReportingScopeID'], $session->get('gibbonPersonID')); if ($highestAction == 'Write Reports_editAll') { $reportingOpen = ($accessCheck['reportingOpen'] ?? 'N') == 'Y'; $canAccessReport = true; $canWriteReport = true; } elseif ($highestAction == 'Write Reports_mine') { $writeCheck = $reportingAccessGateway->getAccessToScopeAndCriteriaGroupByPerson($urlParams['gibbonReportingScopeID'], $reportingScope['scopeType'], $urlParams['scopeTypeID'], $session->get('gibbonPersonID')); $reportingOpen = ($writeCheck['reportingOpen'] ?? 'N') == 'Y'; $canAccessReport = ($accessCheck['canAccess'] ?? 'N') == 'Y'; $canWriteReport = $reportingOpen && ($writeCheck['canWrite'] ?? 'N') == 'Y'; } if (empty($canAccessReport)) { $page->addError(__('You do not have access to this action.')); return; } if ($reportingScope['scopeType'] == 'Year Group') { $scopeIdentifier = 'gibbonYearGroupID'; } elseif ($reportingScope['scopeType'] == 'Form Group') { $scopeIdentifier = 'gibbonFormGroupID'; } elseif ($reportingScope['scopeType'] == 'Course') { $scopeIdentifier = 'gibbonCourseClassID'; } // Check for student enrolment info, fallback to user info $student = $container->get(StudentGateway::class)->selectActiveStudentByPerson($reportingCycle['gibbonSchoolYearID'], $gibbonPersonIDStudent)->fetch(); if (empty($student)) { $student = $container->get(UserGateway::class)->getByID($gibbonPersonIDStudent); } if (empty($student)) { $page->addError(__('The specified record cannot be found.')); return; } $scopeDetails = $reportingAccessGateway->selectReportingDetailsByScope($urlParams['gibbonReportingScopeID'], $reportingScope['scopeType'], $urlParams['scopeTypeID'])->fetch(); $relatedReports = $container->get(ReportingScopeGateway::class)->selectRelatedReportingScopesByID($urlParams['gibbonReportingScopeID'], $reportingScope['scopeType'], $urlParams['scopeTypeID'])->fetchAll(); $reportingProgress = $container->get(ReportingProgressGateway::class)->selectBy(['gibbonReportingScopeID' => $urlParams['gibbonReportingScopeID'], $scopeIdentifier => $urlParams['scopeTypeID'], 'gibbonPersonIDStudent' => $gibbonPersonIDStudent])->fetch(); $student['alerts'] = getAlertBar($guid, $connection2, $gibbonPersonIDStudent, $student['privacy'], '', false, false, "_blank"); $progress = $reportingAccessGateway->selectReportingProgressByScope($urlParams['gibbonReportingScopeID'], $reportingScope['scopeType'], $urlParams['scopeTypeID'], $urlParams['allStudents'] == 'Y')->fetchGroupedUnique(); $progressComplete = array_reduce($progress, function ($group, $item) { return $item['progress'] == 'Complete' ? $group + 1 : $group; }, 0); $keys = array_flip(array_keys($progress)); $values = array_values($progress); $prevStudent = $values[$keys[$gibbonPersonIDStudent] -1] ?? $values[count($values)-1]; $nextStudent = $values[$keys[$gibbonPersonIDStudent] +1] ?? $values[0]; echo $page->fetchFromTemplate('ui/reportingStudentHeader.twig.html', [ 'canWriteReport' => $canWriteReport, 'reportingOpen' => $reportingOpen, 'student' => $student, 'scopeDetails' => $scopeDetails, 'relatedReports' => $relatedReports, 'prevStudent' => $prevStudent, 'nextStudent' => $nextStudent, 'params' => $urlParams, ]); // PER STUDENT CRITERIA $reportingCriteria = $reportingAccessGateway->selectReportingCriteriaByStudentAndScope($reportingScope['gibbonReportingScopeID'], $reportingScope['scopeType'], $urlParams['scopeTypeID'], $gibbonPersonIDStudent)->fetchAll(); // FORM $form = Form::create('reportingWrite', $session->get('absoluteURL').'/modules/Reports/reporting_write_byStudentProcess.php'); $form->setFactory(DatabaseFormFactory::create($pdo)); $form->enableQuickSave(); $form->addHiddenValue('address', $session->get('address')); $form->addHiddenValue('gibbonSchoolYearID', $urlParams['gibbonSchoolYearID']); $form->addHiddenValue('gibbonReportingCycleID', $reportingScope['gibbonReportingCycleID']); $form->addHiddenValue('gibbonReportingScopeID', $reportingScope['gibbonReportingScopeID']); $form->addHiddenValue('gibbonPersonIDStudent', $gibbonPersonIDStudent); $form->addHiddenValue('gibbonPersonIDNext', $nextStudent['gibbonPersonID']); $form->addHiddenValue('scopeTypeID', $urlParams['scopeTypeID']); $form->addHiddenValue('allStudents', $urlParams['allStudents']); $form->addHiddenValue('gibbonPersonID', $gibbonPersonID); $form->addRow()->addClass('reportStatus')->addContent(Format::alert($scopeDetails['name'], 'empty'))->wrap('