This commit is contained in:
@@ -5,7 +5,7 @@ namespace App\Controllers\View;
|
||||
use App\Models\ProjectModel;
|
||||
use App\Models\StudentModel;
|
||||
use App\Models\StudentClassModel;
|
||||
use CodeIgniter\Controller;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\TeacherClassModel;
|
||||
use App\Models\ConfigurationModel;
|
||||
use RuntimeException;
|
||||
@@ -15,7 +15,7 @@ use App\Models\GradingLockModel;
|
||||
use App\Models\MissingScoreOverrideModel;
|
||||
|
||||
|
||||
class ProjectController extends Controller
|
||||
class ProjectController extends BaseController
|
||||
{
|
||||
protected $db;
|
||||
protected ConfigurationModel $configModel;
|
||||
@@ -42,16 +42,26 @@ class ProjectController extends Controller
|
||||
$studentModel = new StudentModel();
|
||||
$projectModel = new ProjectModel();
|
||||
|
||||
$teacherClass = $teacherClassModel->where('teacher_id', $updatedBy)->first();
|
||||
if (!$teacherClass) {
|
||||
return redirect()->back()->with('status', 'No class section found for the current teacher.');
|
||||
}
|
||||
|
||||
$classSectionId = $teacherClass['class_section_id'];
|
||||
session()->set('class_section_id', $classSectionId);
|
||||
|
||||
$semester = $this->getTeacherSelectedSemester();
|
||||
$schoolYear = $this->getTeacherSchoolYear();
|
||||
$classSectionId = (int) (
|
||||
$this->request->getGet('class_section_id')
|
||||
?? $this->request->getPost('class_section_id')
|
||||
?? 0
|
||||
);
|
||||
if ($classSectionId <= 0) {
|
||||
$teacherClass = $teacherClassModel
|
||||
->where('teacher_id', $updatedBy)
|
||||
->where('school_year', $schoolYear)
|
||||
->where('semester', $semester)
|
||||
->first();
|
||||
if (!$teacherClass) {
|
||||
return redirect()->back()->with('status', 'No class section found for the current teacher.');
|
||||
}
|
||||
$classSectionId = (int) $teacherClass['class_section_id'];
|
||||
}
|
||||
|
||||
session()->set('class_section_id', $classSectionId);
|
||||
|
||||
$projectRows = $projectModel
|
||||
->select('id, project_index')
|
||||
@@ -71,6 +81,7 @@ class ProjectController extends Controller
|
||||
$studentsClasses = $studentClassModel
|
||||
->active()
|
||||
->where('student_class.class_section_id', $classSectionId)
|
||||
->where('student_class.school_year', $schoolYear)
|
||||
->findAll();
|
||||
$students = [];
|
||||
|
||||
@@ -115,7 +126,7 @@ class ProjectController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateProjectScores(array $scores = null, int $updatedBy = null, int $classSectionId = null)
|
||||
public function updateProjectScores(?array $scores = null, ?int $updatedBy = null, ?int $classSectionId = null)
|
||||
{
|
||||
$scores = $this->request->getPost('scores');
|
||||
$projectModel = new ProjectModel();
|
||||
@@ -127,6 +138,7 @@ class ProjectController extends Controller
|
||||
$classSectionId = session()->get('class_section_id');
|
||||
$semester = $this->getTeacherSelectedSemester();
|
||||
$schoolYear = $this->getTeacherSchoolYear();
|
||||
$this->assertSchoolYearWritable($this->resolveSchoolYearContext());
|
||||
$classSectionId = (int) ($classSectionId ?? 0);
|
||||
if ($classSectionId > 0 && $this->isScoresLocked($classSectionId, $semester, $schoolYear)) {
|
||||
return redirect()->back()->with('error', 'Scores are locked for this class. Unlock to edit.');
|
||||
@@ -190,7 +202,8 @@ class ProjectController extends Controller
|
||||
'student_id' => $studentId,
|
||||
'project_index' => $index,
|
||||
'class_section_id' => $classSectionId,
|
||||
'semester' => $semester
|
||||
'semester' => $semester,
|
||||
'school_year' => $schoolYear,
|
||||
])->first();
|
||||
|
||||
$data = [
|
||||
@@ -231,6 +244,7 @@ class ProjectController extends Controller
|
||||
$classSectionId = session()->get('class_section_id');
|
||||
$semester = $this->getTeacherSelectedSemester();
|
||||
$schoolYear = $this->getTeacherSchoolYear();
|
||||
$this->assertSchoolYearWritable($this->resolveSchoolYearContext());
|
||||
|
||||
$projectModel = new ProjectModel();
|
||||
$studentClassModel = new StudentClassModel();
|
||||
@@ -257,6 +271,7 @@ class ProjectController extends Controller
|
||||
$students = $studentClassModel
|
||||
->active()
|
||||
->where('student_class.class_section_id', $classSectionId)
|
||||
->where('student_class.school_year', $schoolYear)
|
||||
->findAll();
|
||||
|
||||
foreach ($students as $student) {
|
||||
@@ -533,6 +548,6 @@ class ProjectController extends Controller
|
||||
|
||||
private function getTeacherSchoolYear(): string
|
||||
{
|
||||
return (string) $this->schoolYear;
|
||||
return $this->currentSchoolYearName((string) ($this->schoolYear ?? ''));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user