update controllers logic
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\ClassProgressReport;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\TeacherClass;
|
||||
use App\Models\User;
|
||||
|
||||
class ClassProgressReportPolicy
|
||||
@@ -34,7 +36,23 @@ class ClassProgressReportPolicy
|
||||
|
||||
private function owns(User $user, ClassProgressReport $report): bool
|
||||
{
|
||||
return (int) $report->teacher_id === (int) $user->id;
|
||||
if ((int) $report->teacher_id === (int) $user->id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$schoolYear = (string) (Configuration::getConfig('school_year') ?? '');
|
||||
if ($schoolYear === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$semester = (string) (Configuration::getConfig('semester') ?? '');
|
||||
foreach (TeacherClass::assignedForSectionTerm((int) $report->class_section_id, $semester, $schoolYear) as $row) {
|
||||
if ((int) ($row['teacher_id'] ?? 0) === (int) $user->id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function isAdmin(User $user): bool
|
||||
|
||||
Reference in New Issue
Block a user