This commit is contained in:
@@ -91,6 +91,9 @@ class ExamDraftController extends BaseController
|
||||
|
||||
public function teacherIndex()
|
||||
{
|
||||
$this->syncAcademicContext();
|
||||
$context = $this->resolveSchoolYearContext();
|
||||
|
||||
$teacherId = (int) (session()->get('user_id') ?? 0);
|
||||
if ($teacherId <= 0) {
|
||||
return redirect()->to('/login');
|
||||
@@ -175,11 +178,15 @@ class ExamDraftController extends BaseController
|
||||
'maxUploadBytes' => self::MAX_UPLOAD_BYTES,
|
||||
'validation' => $validation,
|
||||
'printableDraftIds' => $printableIds,
|
||||
'isSchoolYearReadonly' => $context->isReadonly(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function teacherStore()
|
||||
{
|
||||
$this->syncAcademicContext();
|
||||
$this->assertSchoolYearWritable($this->resolveSchoolYearContext());
|
||||
|
||||
$teacherId = (int) (session()->get('user_id') ?? 0);
|
||||
if ($teacherId <= 0) {
|
||||
return redirect()->to('/login');
|
||||
@@ -193,10 +200,13 @@ class ExamDraftController extends BaseController
|
||||
return redirect()->back()->withInput()->with('error', 'Select a class section before submitting.');
|
||||
}
|
||||
|
||||
$assignment = $this->teacherClassModel
|
||||
$assignmentQuery = $this->teacherClassModel
|
||||
->where('teacher_id', $teacherId)
|
||||
->where('class_section_id', $classSectionId)
|
||||
->first();
|
||||
->where('class_section_id', $classSectionId);
|
||||
if ($this->schoolYear !== '') {
|
||||
$assignmentQuery->where('school_year', $this->schoolYear);
|
||||
}
|
||||
$assignment = $assignmentQuery->first();
|
||||
|
||||
if (empty($assignment)) {
|
||||
return redirect()->back()->withInput()->with('error', 'You are not assigned to the selected class section.');
|
||||
@@ -785,6 +795,8 @@ class ExamDraftController extends BaseController
|
||||
|
||||
public function teacherStatusFeed()
|
||||
{
|
||||
$this->syncAcademicContext();
|
||||
|
||||
$teacherId = (int) (session()->get('user_id') ?? 0);
|
||||
if ($teacherId <= 0) {
|
||||
return $this->response->setStatusCode(401);
|
||||
@@ -848,6 +860,8 @@ class ExamDraftController extends BaseController
|
||||
->join('classSection cs', 'cs.class_section_id = exam_drafts.class_section_id', 'left')
|
||||
->join('users u', 'u.id = exam_drafts.' . $this->authorIdColumn, 'left');
|
||||
|
||||
$this->applyExamDraftYearScope($query);
|
||||
|
||||
if (empty($classSectionIds)) {
|
||||
return $query->where('exam_drafts.' . $this->authorIdColumn, $teacherId);
|
||||
}
|
||||
@@ -859,19 +873,25 @@ class ExamDraftController extends BaseController
|
||||
->where('exam_drafts.' . $this->authorIdColumn . ' !=', $teacherId)
|
||||
->where('exam_drafts.status !=', 'draft');
|
||||
|
||||
if ($this->schoolYear !== '') {
|
||||
$query->where('exam_drafts.school_year', $this->schoolYear);
|
||||
}
|
||||
if ($this->semester !== '') {
|
||||
$query->where('exam_drafts.semester', $this->semester);
|
||||
}
|
||||
|
||||
$query->groupEnd()
|
||||
->groupEnd();
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function syncAcademicContext(): void
|
||||
{
|
||||
$this->schoolYear = $this->currentSchoolYearName((string) ($this->configModel->getConfig('school_year') ?? ''));
|
||||
$this->semester = (string) ($this->configModel->getConfig('semester') ?? '');
|
||||
}
|
||||
|
||||
private function applyExamDraftYearScope($query): void
|
||||
{
|
||||
if ($this->schoolYear !== '') {
|
||||
$query->where('exam_drafts.school_year', $this->schoolYear);
|
||||
}
|
||||
}
|
||||
|
||||
private function attachTeacherDraftContext(array $row, int $viewerId): array
|
||||
{
|
||||
$isOwn = $this->draftTeacherId($row) === $viewerId;
|
||||
|
||||
Reference in New Issue
Block a user