fix tables to have school year, and remove school year from other tables.
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 5m48s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 1m33s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 5m48s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 1m33s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
This commit is contained in:
+9
-32
@@ -172,10 +172,6 @@ class User extends Authenticatable implements JWTSubject
|
||||
$pivotColumns[] = 'deleted_at';
|
||||
$relation->wherePivotNull('deleted_at');
|
||||
}
|
||||
if (Schema::hasColumn('user_roles', 'school_year')) {
|
||||
$pivotColumns[] = 'school_year';
|
||||
}
|
||||
|
||||
if (! empty($pivotColumns)) {
|
||||
$relation->withPivot($pivotColumns);
|
||||
}
|
||||
@@ -422,7 +418,6 @@ class User extends Authenticatable implements JWTSubject
|
||||
->join('user_roles', 'user_roles.user_id', '=', 'users.id')
|
||||
->join('roles', 'roles.id', '=', 'user_roles.role_id')
|
||||
->where('roles.name', $roleName)
|
||||
->where('users.school_year', $schoolYear)
|
||||
->whereNull('user_roles.deleted_at')
|
||||
->get()
|
||||
->map(fn ($r) => (array) $r)
|
||||
@@ -440,7 +435,6 @@ class User extends Authenticatable implements JWTSubject
|
||||
->selectRaw('u.id, MAX(CASE WHEN r.slug NOT IN ("guest","teacher","teacher_assistant","parent") THEN 1 ELSE 0 END) as is_admin')
|
||||
->join('user_roles as ur', 'ur.user_id', '=', 'u.id')
|
||||
->join('roles as r', 'r.id', '=', 'ur.role_id')
|
||||
->where('u.school_year', $schoolYear)
|
||||
->where('r.is_active', 1)
|
||||
->whereNull('ur.deleted_at')
|
||||
->groupBy('u.id')
|
||||
@@ -546,23 +540,11 @@ class User extends Authenticatable implements JWTSubject
|
||||
}
|
||||
|
||||
if (! empty($schoolYear)) {
|
||||
// Prefer ur.school_year if it exists (role is year-scoped)
|
||||
$hasUrSchoolYear = false;
|
||||
try {
|
||||
$cols = DB::getSchemaBuilder()->getColumnListing('user_roles');
|
||||
$hasUrSchoolYear = in_array('school_year', $cols, true);
|
||||
} catch (\Throwable $e) {
|
||||
$hasUrSchoolYear = false;
|
||||
}
|
||||
$escYear = DB::getPdo()->quote($schoolYear);
|
||||
|
||||
if ($hasUrSchoolYear) {
|
||||
$q->where('ur.school_year', $schoolYear);
|
||||
} else {
|
||||
$escYear = DB::getPdo()->quote($schoolYear);
|
||||
|
||||
$q->where(function ($w) use ($escYear) {
|
||||
// A) teacher assignment that year
|
||||
$w->whereRaw("
|
||||
$q->where(function ($w) use ($escYear) {
|
||||
// Staff participation in a year comes from yearly relationship tables.
|
||||
$w->whereRaw("
|
||||
EXISTS (
|
||||
SELECT 1
|
||||
FROM teacher_class tc
|
||||
@@ -571,20 +553,15 @@ class User extends Authenticatable implements JWTSubject
|
||||
)
|
||||
");
|
||||
|
||||
// B) OR has any non-teacher-ish, non-parent role
|
||||
$w->orWhereRaw("
|
||||
$w->orWhereRaw("
|
||||
EXISTS (
|
||||
SELECT 1
|
||||
FROM user_roles ur2
|
||||
JOIN roles r2 ON r2.id = ur2.role_id
|
||||
WHERE ur2.user_id = users.id
|
||||
AND ur2.deleted_at IS NULL
|
||||
AND LOWER(r2.name) NOT IN ('parent','ta')
|
||||
AND LOWER(r2.name) NOT LIKE '%teacher%'
|
||||
FROM staff_attendance sa
|
||||
WHERE sa.user_id = users.id
|
||||
AND sa.school_year = {$escYear}
|
||||
)
|
||||
");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$q->groupBy('users.id');
|
||||
|
||||
Reference in New Issue
Block a user