fix navbar and age mismatch
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Models\StudentModel;
|
|||||||
use App\Models\TeacherModel;
|
use App\Models\TeacherModel;
|
||||||
use App\Models\ClassSectionModel;
|
use App\Models\ClassSectionModel;
|
||||||
use App\Models\ConfigurationModel;
|
use App\Models\ConfigurationModel;
|
||||||
|
use App\Support\Enrollment\EnrollmentEligibility;
|
||||||
use Config\Database;
|
use Config\Database;
|
||||||
|
|
||||||
class AssignmentController extends BaseController
|
class AssignmentController extends BaseController
|
||||||
@@ -177,11 +178,13 @@ class AssignmentController extends BaseController
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$calculatedAge = EnrollmentEligibility::ageOnSeptemberFirst($student['dob'] ?? null, $year);
|
||||||
|
|
||||||
$students[] = [
|
$students[] = [
|
||||||
'id' => (int)$student['id'],
|
'id' => (int)$student['id'],
|
||||||
'firstname' => esc($student['firstname']),
|
'firstname' => esc($student['firstname']),
|
||||||
'lastname' => esc($student['lastname']),
|
'lastname' => esc($student['lastname']),
|
||||||
'age' => esc($student['age']),
|
'age' => esc((string)($calculatedAge ?? ($student['age'] ?? ''))),
|
||||||
'gender' => esc($student['gender']),
|
'gender' => esc($student['gender']),
|
||||||
'registration_grade' => esc($student['registration_grade']),
|
'registration_grade' => esc($student['registration_grade']),
|
||||||
'photo_consent' => esc($student['photo_consent'] ? 'Yes' : 'No'),
|
'photo_consent' => esc($student['photo_consent'] ? 'Yes' : 'No'),
|
||||||
|
|||||||
@@ -391,7 +391,7 @@ public function save()
|
|||||||
}
|
}
|
||||||
unset($node);
|
unset($node);
|
||||||
|
|
||||||
$this->sortTreeByOrder($tree);
|
$this->sortTreeAlpha($tree);
|
||||||
|
|
||||||
$flatAlpha = $all;
|
$flatAlpha = $all;
|
||||||
usort($flatAlpha, fn($a, $b) => strnatcasecmp(
|
usort($flatAlpha, fn($a, $b) => strnatcasecmp(
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ class NavbarService
|
|||||||
$allowedIds = $this->mapModel->getNavItemIdsForRoles($roles);
|
$allowedIds = $this->mapModel->getNavItemIdsForRoles($roles);
|
||||||
if (empty($allowedIds)) return [];
|
if (empty($allowedIds)) return [];
|
||||||
|
|
||||||
// Load all enabled items, then filter. The builder controls this order.
|
// Load all enabled items, then filter.
|
||||||
|
// The displayed sidebar is alphabetized after the tree is built so
|
||||||
|
// new menu items fall into place without relying on manual sort_order.
|
||||||
$rows = $this->navModel->where('is_enabled', 1)
|
$rows = $this->navModel->where('is_enabled', 1)
|
||||||
->orderBy('sort_order', 'ASC')
|
->orderBy('sort_order', 'ASC')
|
||||||
->orderBy('label', 'ASC')
|
->orderBy('label', 'ASC')
|
||||||
@@ -57,34 +59,22 @@ class NavbarService
|
|||||||
}
|
}
|
||||||
unset($node);
|
unset($node);
|
||||||
|
|
||||||
$this->sortTreeByOrder($tree);
|
$this->sortTreeAlphabetically($tree);
|
||||||
|
|
||||||
$this->cache->save($cacheKey, $tree, 300); // 5 minutes
|
$this->cache->save($cacheKey, $tree, 300); // 5 minutes
|
||||||
return $tree;
|
return $tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sortTreeByOrder(array &$nodes): void
|
private function sortTreeAlphabetically(array &$nodes): void
|
||||||
{
|
{
|
||||||
usort($nodes, function ($a, $b) {
|
usort($nodes, fn ($a, $b) => strnatcasecmp(
|
||||||
$order = ((int) ($a['sort_order'] ?? 0)) <=> ((int) ($b['sort_order'] ?? 0));
|
$this->labelSortKey((string) ($a['label'] ?? '')),
|
||||||
if ($order !== 0) {
|
$this->labelSortKey((string) ($b['label'] ?? ''))
|
||||||
return $order;
|
));
|
||||||
}
|
|
||||||
|
|
||||||
$label = strnatcasecmp(
|
|
||||||
$this->labelSortKey((string) ($a['label'] ?? '')),
|
|
||||||
$this->labelSortKey((string) ($b['label'] ?? ''))
|
|
||||||
);
|
|
||||||
if ($label !== 0) {
|
|
||||||
return $label;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ((int) ($a['id'] ?? 0)) <=> ((int) ($b['id'] ?? 0));
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach ($nodes as &$node) {
|
foreach ($nodes as &$node) {
|
||||||
if (!empty($node['children']) && is_array($node['children'])) {
|
if (!empty($node['children']) && is_array($node['children'])) {
|
||||||
$this->sortTreeByOrder($node['children']);
|
$this->sortTreeAlphabetically($node['children']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($node);
|
unset($node);
|
||||||
|
|||||||
Reference in New Issue
Block a user