Update graduation workflow, promotions, and admin module improvements
This commit is contained in:
@@ -392,14 +392,42 @@ class StudentPromotionController extends Controller
|
||||
protected function pickRecommendedClass($classes, Student $student): ?SchoolClass
|
||||
{
|
||||
$sameDepartmentClasses = $classes->where('department_id', $student->department_id)->values();
|
||||
$currentClassName = (string) $student->classRoom?->name;
|
||||
$currentNormalized = $this->normalizeClassNameForComparison($currentClassName);
|
||||
$currentParallel = $this->extractClassParallel($currentClassName);
|
||||
|
||||
return $sameDepartmentClasses->first(function (SchoolClass $classRoom) use ($student) {
|
||||
return str_contains(strtolower($classRoom->name), strtolower((string) $student->classRoom?->name));
|
||||
return $sameDepartmentClasses->first(function (SchoolClass $classRoom) use ($currentParallel) {
|
||||
return $currentParallel !== null
|
||||
&& $this->extractClassParallel((string) $classRoom->name) === $currentParallel;
|
||||
})
|
||||
?? $sameDepartmentClasses->first(function (SchoolClass $classRoom) use ($currentNormalized) {
|
||||
return $currentNormalized !== ''
|
||||
&& $this->normalizeClassNameForComparison((string) $classRoom->name) === $currentNormalized;
|
||||
})
|
||||
?? $sameDepartmentClasses->first(function (SchoolClass $classRoom) use ($student) {
|
||||
return str_contains(strtolower($classRoom->name), strtolower((string) $student->classRoom?->name));
|
||||
})
|
||||
?? $sameDepartmentClasses->first()
|
||||
?? $classes->first();
|
||||
}
|
||||
|
||||
protected function normalizeClassNameForComparison(string $className): string
|
||||
{
|
||||
$normalized = strtoupper(trim($className));
|
||||
$normalized = preg_replace('/^XII?I?\s+/i', '', $normalized) ?? $normalized;
|
||||
|
||||
return preg_replace('/\s+/', ' ', trim($normalized)) ?? trim($normalized);
|
||||
}
|
||||
|
||||
protected function extractClassParallel(string $className): ?string
|
||||
{
|
||||
if (! preg_match('/(\d+)\s*$/', trim($className), $matches)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ltrim($matches[1], '0') ?: '0';
|
||||
}
|
||||
|
||||
protected function transformClassOptions(Collection $classes): Collection
|
||||
{
|
||||
return $classes->map(function (SchoolClass $classRoom) {
|
||||
|
||||
Reference in New Issue
Block a user