fix registration enrollment of students
This commit is contained in:
@@ -40,15 +40,15 @@ class StudentYearStatusService
|
||||
return (int) ($row['is_new'] ?? 1) === 1;
|
||||
}
|
||||
|
||||
public function upsert(int $studentId, string $schoolYear, bool $isNew): void
|
||||
public function upsert(int $studentId, string $schoolYear, bool $isNew): bool
|
||||
{
|
||||
if ($studentId <= 0) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$schoolYear = trim($schoolYear);
|
||||
if (! preg_match('/^\d{4}-\d{4}$/', $schoolYear) || ! $this->db->tableExists('student_year_status')) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$flag = $isNew ? 1 : 0;
|
||||
@@ -59,19 +59,35 @@ class StudentYearStatusService
|
||||
->first();
|
||||
|
||||
if (is_array($existing) && isset($existing['id'])) {
|
||||
$this->yearStatusModel->update((int) $existing['id'], [
|
||||
return (bool) $this->yearStatusModel->update((int) $existing['id'], [
|
||||
'is_new' => $flag,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->yearStatusModel->insert([
|
||||
return (bool) $this->yearStatusModel->insert([
|
||||
'student_id' => $studentId,
|
||||
'school_year' => $schoolYear,
|
||||
'is_new' => $flag,
|
||||
]);
|
||||
}
|
||||
|
||||
public function hasStatus(int $studentId, string $schoolYear): bool
|
||||
{
|
||||
if ($studentId <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$schoolYear = trim($schoolYear);
|
||||
if (! preg_match('/^\d{4}-\d{4}$/', $schoolYear) || ! $this->db->tableExists('student_year_status')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->yearStatusModel
|
||||
->where('student_id', $studentId)
|
||||
->where('school_year', $schoolYear)
|
||||
->countAllResults() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark students who existed in a source school year as returning in the target year.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user