Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form groups: fix the bug to show the total number of students in each study year #1842

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ function getYearGroupsFromIDList($guid, $connection2, $ids, $vertical = false, $
$sqlYears = 'SELECT DISTINCT nameShort, sequenceNumber FROM gibbonYearGroup ORDER BY sequenceNumber';
$resultYears = $connection2->query($sqlYears);

$years = explode(',', $ids);
$years = explode(',', $ids ?? '');
if (count($years) > 0 and $years[0] != '') {
if (count($years) == $resultYears->rowCount()) {
$output = '<i>' . __('All') . '</i>';
Expand Down Expand Up @@ -741,7 +741,7 @@ function getMaxUpload($multiple = false)
//Encode strring using htmlentities with the ENT_QUOTES option
function htmlPrep($str)
{
return htmlentities($str, ENT_QUOTES, 'UTF-8');
return htmlentities($str ?? '', ENT_QUOTES, 'UTF-8');
}

/**
Expand Down
14 changes: 7 additions & 7 deletions modules/Form Groups/formGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
//Proceed!
$page->breadcrumbs->add(__('View Form Groups'));

$gateway = $container->get(FormGroupGateway::class);
$formGroupGateway = $container->get(FormGroupGateway::class);
if ($highestAction == "View Form Groups_all") {
$formGroups = $gateway->selectFormGroupsBySchoolYear($session->get('gibbonSchoolYearID'));
$formGroups = $formGroupGateway->selectFormGroupsBySchoolYear($session->get('gibbonSchoolYearID'));
}
else {
$formGroups = $gateway->selectFormGroupsBySchoolYearMyChildren($session->get('gibbonSchoolYearID'), $session->get('gibbonPersonID'));
$formGroups = $formGroupGateway->selectFormGroupsBySchoolYearMyChildren($session->get('gibbonSchoolYearID'), $session->get('gibbonPersonID'));
}

$formatTutorsList = function($row) use ($gateway) {
$tutors = $gateway->selectTutorsByFormGroup($row['gibbonFormGroupID'])->fetchAll();
$formatTutorsList = function($row) use ($formGroupGateway) {
$tutors = $formGroupGateway->selectTutorsByFormGroup($row['gibbonFormGroupID'])->fetchAll();
if (count($tutors) > 1) $tutors[0]['surname'] .= ' ('.__('Main Tutor').')';

return Format::nameList($tutors, 'Staff', false, true);
Expand Down Expand Up @@ -89,8 +89,8 @@
}
});
$table->addColumn('students', __('Students'))
->format(function ($values) use ($yearGroupGateway) {
return $yearGroupGateway->studentCountByYearGroup($values['gibbonYearGroupID']);
->format(function ($values) use ($yearGroupGateway, $session) {
return $yearGroupGateway->studentCountByYearGroup($values['gibbonYearGroupID'], $session->get('gibbonSchoolYearID'));
});

echo $table->render($yearGroups);
Expand Down
10 changes: 5 additions & 5 deletions src/Domain/School/YearGroupGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ public function queryYearGroups(QueryCriteria $criteria)
*
* @return array|false
*/
public function studentCountByYearGroup($gibbonYearGroupID)
public function studentCountByYearGroup($gibbonYearGroupID, $gibbonSchoolYearID)
{
$data = array('gibbonYearGroupID' => $gibbonYearGroupID, 'today' => date('Y-m-d'));
$data = ['gibbonYearGroupID' => $gibbonYearGroupID, 'gibbonSchoolYearID' => $gibbonSchoolYearID, 'today' => date('Y-m-d')];
$sql = "SELECT count(*)
FROM gibbonStudentEnrolment
FROM gibbonStudentEnrolment
JOIN gibbonPerson ON (gibbonStudentEnrolment.gibbonPersonID=gibbonPerson.gibbonPersonID)
JOIN gibbonSchoolYear ON (gibbonStudentEnrolment.gibbonSchoolYearID=gibbonSchoolYear.gibbonSchoolYearID)
WHERE gibbonPerson.status='Full'
AND gibbonSchoolYear.status='Current'
WHERE gibbonPerson.status='Full'
AND (dateStart IS NULL OR dateStart<=:today)
AND (dateEnd IS NULL OR dateEnd>=:today)
AND gibbonYearGroupID=:gibbonYearGroupID
AND gibbonStudentEnrolment.gibbonSchoolYearID=:gibbonSchoolYearID
";

return $this->db()->selectOne($sql, $data);
Expand Down