fix gitlab tests
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Services\Teachers;
|
||||
|
||||
use App\Services\ApplicationUrlService;
|
||||
use App\Services\Staff\StaffTimeOffLinkService;
|
||||
use App\Models\StaffAttendance;
|
||||
use App\Models\TeacherClass;
|
||||
use App\Models\User;
|
||||
use App\Services\ApplicationUrlService;
|
||||
use App\Services\SemesterRangeService;
|
||||
use App\Services\Staff\StaffTimeOffLinkService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
@@ -18,7 +18,8 @@ class TeacherAbsenceService
|
||||
private SemesterRangeService $semesterRangeService,
|
||||
private StaffTimeOffLinkService $staffTimeOffLinkService,
|
||||
private ApplicationUrlService $urls,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public function formData(int $userId): array
|
||||
{
|
||||
@@ -28,7 +29,7 @@ class TeacherAbsenceService
|
||||
|
||||
$teacher = User::query()->find($userId);
|
||||
$displayName = $teacher
|
||||
? trim(($teacher->firstname ?? '').' '.($teacher->lastname ?? ''))
|
||||
? trim(($teacher->firstname ?? '') . ' ' . ($teacher->lastname ?? ''))
|
||||
: 'Teacher';
|
||||
|
||||
$existing = StaffAttendance::query()
|
||||
@@ -75,7 +76,7 @@ class TeacherAbsenceService
|
||||
}
|
||||
|
||||
$reasonBase = $reasonType !== '' ? strtolower($reasonType) : '';
|
||||
$reason = $reasonBase !== '' ? ($reasonBase.': '.$reasonText) : $reasonText;
|
||||
$reason = $reasonBase !== '' ? ($reasonBase . ': ' . $reasonText) : $reasonText;
|
||||
|
||||
$allowedSet = array_fill_keys($this->allowedAbsenceDates($schoolYear), true);
|
||||
$roleName = User::getUserRoleName($userId) ?: null;
|
||||
@@ -96,12 +97,10 @@ class TeacherAbsenceService
|
||||
$parsed = Carbon::createFromFormat('Y-m-d', $date);
|
||||
if ($parsed->format('Y-m-d') !== $date || empty($allowedSet[$date])) {
|
||||
$invalid[] = $date;
|
||||
|
||||
continue;
|
||||
}
|
||||
} catch (\Throwable) {
|
||||
$invalid[] = $date;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -127,10 +126,10 @@ class TeacherAbsenceService
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($invalid)) {
|
||||
if (!empty($invalid)) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'message' => 'Invalid dates: '.implode(', ', $invalid),
|
||||
'message' => 'Invalid dates: ' . implode(', ', $invalid),
|
||||
'status' => 422,
|
||||
];
|
||||
}
|
||||
@@ -148,7 +147,7 @@ class TeacherAbsenceService
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'message' => $saved.' day(s) saved as absent.',
|
||||
'message' => $saved . ' day(s) saved as absent.',
|
||||
'saved' => $saved,
|
||||
'dates' => $savedDates,
|
||||
'status' => 200,
|
||||
@@ -212,10 +211,10 @@ class TeacherAbsenceService
|
||||
): void {
|
||||
try {
|
||||
$user = User::query()->find($userId);
|
||||
$fullName = trim(($user->firstname ?? '').' '.($user->lastname ?? '')) ?: 'Teacher';
|
||||
$fullName = trim(($user->firstname ?? '') . ' ' . ($user->lastname ?? '')) ?: 'Teacher';
|
||||
$userEmail = $user->email ?? '';
|
||||
$role = $roleName ?: 'teacher';
|
||||
$dateList = ! empty($savedDates) ? implode(', ', $savedDates) : implode(', ', $dates);
|
||||
$dateList = !empty($savedDates) ? implode(', ', $savedDates) : implode(', ', $dates);
|
||||
|
||||
$subject = sprintf(
|
||||
'TimeOff Request: %s (%s) — %s',
|
||||
@@ -228,21 +227,21 @@ class TeacherAbsenceService
|
||||
$assignedText = $this->formatAssignedClasses($userId, $schoolYear, $semester);
|
||||
|
||||
$body = '<div style="font-family:Arial,Helvetica,sans-serif;font-size:14px;line-height:1.5;">'
|
||||
.'<h3 style="margin:0 0 8px;">New TimeOff Request</h3>'
|
||||
.'<p style="margin:0 0 12px;">A staff time-off request was submitted from the teacher portal.</p>'
|
||||
.'<table cellpadding="6" cellspacing="0" style="border-collapse:collapse;">'
|
||||
.'<tr><td><strong>Name</strong></td><td>'.e($fullName).'</td></tr>'
|
||||
.'<tr><td><strong>Email</strong></td><td>'.e($userEmail).'</td></tr>'
|
||||
.'<tr><td><strong>Role</strong></td><td>'.e((string) $role).'</td></tr>'
|
||||
.'<tr><td><strong>Semester</strong></td><td>'.e($semester).'</td></tr>'
|
||||
.'<tr><td><strong>School Year</strong></td><td>'.e($schoolYear).'</td></tr>'
|
||||
.'<tr><td><strong>Reason Type</strong></td><td>'.e($reasonType ?: '-').'</td></tr>'
|
||||
.'<tr><td><strong>Reason</strong></td><td>'.e($reasonText).'</td></tr>'
|
||||
.'<tr><td><strong>Dates</strong></td><td>'.e($dateList ?: '-').'</td></tr>'
|
||||
.'<tr><td><strong>Assigned Class(es)</strong></td><td>'.e($assignedText).'</td></tr>'
|
||||
.'<tr><td><strong>Submitted At</strong></td><td>'.e($submittedAt).'</td></tr>'
|
||||
.'</table>'
|
||||
.'</div>';
|
||||
. '<h3 style="margin:0 0 8px;">New TimeOff Request</h3>'
|
||||
. '<p style="margin:0 0 12px;">A staff time-off request was submitted from the teacher portal.</p>'
|
||||
. '<table cellpadding="6" cellspacing="0" style="border-collapse:collapse;">'
|
||||
. '<tr><td><strong>Name</strong></td><td>' . e($fullName) . '</td></tr>'
|
||||
. '<tr><td><strong>Email</strong></td><td>' . e($userEmail) . '</td></tr>'
|
||||
. '<tr><td><strong>Role</strong></td><td>' . e((string) $role) . '</td></tr>'
|
||||
. '<tr><td><strong>Semester</strong></td><td>' . e($semester) . '</td></tr>'
|
||||
. '<tr><td><strong>School Year</strong></td><td>' . e($schoolYear) . '</td></tr>'
|
||||
. '<tr><td><strong>Reason Type</strong></td><td>' . e($reasonType ?: '-') . '</td></tr>'
|
||||
. '<tr><td><strong>Reason</strong></td><td>' . e($reasonText) . '</td></tr>'
|
||||
. '<tr><td><strong>Dates</strong></td><td>' . e($dateList ?: '-') . '</td></tr>'
|
||||
. '<tr><td><strong>Assigned Class(es)</strong></td><td>' . e($assignedText) . '</td></tr>'
|
||||
. '<tr><td><strong>Submitted At</strong></td><td>' . e($submittedAt) . '</td></tr>'
|
||||
. '</table>'
|
||||
. '</div>';
|
||||
|
||||
$token = $this->staffTimeOffLinkService->createToken([
|
||||
'uid' => $userId,
|
||||
@@ -257,9 +256,9 @@ class TeacherAbsenceService
|
||||
]);
|
||||
|
||||
$notifyUrl = $this->urls->timeoffNotifyUrl($token);
|
||||
$body .= '<p style="margin-top:16px;">Click <a href="'.e($notifyUrl).'">Send confirmation email to '
|
||||
.e($fullName)
|
||||
.'</a> so the staff member is notified automatically. This link expires in 14 days.</p>';
|
||||
$body .= '<p style="margin-top:16px;">Click <a href="' . e($notifyUrl) . '">Send confirmation email to '
|
||||
. e($fullName)
|
||||
. '</a> so the staff member is notified automatically. This link expires in 14 days.</p>';
|
||||
|
||||
$principalEmail = env('PRINCIPAL_EMAIL', 'principal@alrahmaisgl.org');
|
||||
|
||||
@@ -284,10 +283,10 @@ class TeacherAbsenceService
|
||||
$name = (string) ($assignment['class_section_name'] ?? '');
|
||||
$role = (string) ($assignment['teacher_role'] ?? '');
|
||||
if ($name !== '') {
|
||||
$parts[] = $role !== '' ? ($name.' ('.$role.')') : $name;
|
||||
$parts[] = $role !== '' ? ($name . ' (' . $role . ')') : $name;
|
||||
}
|
||||
}
|
||||
|
||||
return ! empty($parts) ? implode(', ', $parts) : 'No assigned class';
|
||||
return !empty($parts) ? implode(', ', $parts) : 'No assigned class';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ use App\Models\User;
|
||||
|
||||
class TeacherAssignmentService
|
||||
{
|
||||
public function __construct(private TeacherConfigService $configService) {}
|
||||
public function __construct(private TeacherConfigService $configService)
|
||||
{
|
||||
}
|
||||
|
||||
public function listAssignments(?string $schoolYear = null): array
|
||||
{
|
||||
@@ -51,7 +53,7 @@ class TeacherAssignmentService
|
||||
}
|
||||
|
||||
$role = strtolower((string) ($assign['position'] ?? ''));
|
||||
if (! in_array($role, ['main', 'ta'], true)) {
|
||||
if (!in_array($role, ['main', 'ta'], true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -71,9 +73,9 @@ class TeacherAssignmentService
|
||||
continue;
|
||||
}
|
||||
$assigned = $assignmentMap[$tid] ?? ['main' => [], 'ta' => []];
|
||||
$name = trim(($teacher['firstname'] ?? '').' '.($teacher['lastname'] ?? ''));
|
||||
$name = trim(($teacher['firstname'] ?? '') . ' ' . ($teacher['lastname'] ?? ''));
|
||||
if ($name === '') {
|
||||
$name = 'User#'.$tid;
|
||||
$name = 'User#' . $tid;
|
||||
}
|
||||
|
||||
$teacherData[] = [
|
||||
@@ -168,7 +170,7 @@ class TeacherAssignmentService
|
||||
$semester = trim((string) ($input['semester'] ?? $context['semester'] ?? ''));
|
||||
$schoolYear = trim((string) ($input['school_year'] ?? $context['school_year'] ?? ''));
|
||||
|
||||
if ($teacherId <= 0 || $classSectionId <= 0 || ! in_array($position, ['main', 'ta'], true) || $schoolYear === '' || $semester === '') {
|
||||
if ($teacherId <= 0 || $classSectionId <= 0 || !in_array($position, ['main', 'ta'], true) || $schoolYear === '' || $semester === '') {
|
||||
return ['ok' => false, 'message' => 'Missing or invalid data for deletion.'];
|
||||
}
|
||||
|
||||
@@ -180,12 +182,12 @@ class TeacherAssignmentService
|
||||
->where('position', $position)
|
||||
->first();
|
||||
|
||||
if (! $assignment) {
|
||||
if (!$assignment) {
|
||||
return ['ok' => false, 'message' => 'Assignment not found.'];
|
||||
}
|
||||
|
||||
$assignment->delete();
|
||||
|
||||
return ['ok' => true, 'message' => ucfirst($position).' assignment removed successfully.'];
|
||||
return ['ok' => true, 'message' => ucfirst($position) . ' assignment removed successfully.'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TeacherDashboardService
|
||||
{
|
||||
public function __construct(private TeacherConfigService $configService) {}
|
||||
public function __construct(private TeacherConfigService $configService)
|
||||
{
|
||||
}
|
||||
|
||||
public function classView(int $userId, ?int $requestedClassSectionId = null): array
|
||||
{
|
||||
@@ -27,7 +29,7 @@ class TeacherDashboardService
|
||||
->map(fn ($r) => strtolower((string) $r))
|
||||
->all();
|
||||
|
||||
if (! array_intersect($roles, ['teacher', 'teacher_assistant'])) {
|
||||
if (!array_intersect($roles, ['teacher', 'teacher_assistant'])) {
|
||||
throw new \RuntimeException('Access denied.');
|
||||
}
|
||||
|
||||
@@ -48,24 +50,24 @@ class TeacherDashboardService
|
||||
$activeClassSectionId = null;
|
||||
if ($requestedClassSectionId && in_array($requestedClassSectionId, $classSectionIds, true)) {
|
||||
$activeClassSectionId = $requestedClassSectionId;
|
||||
} elseif (! empty($classSectionIds)) {
|
||||
} elseif (!empty($classSectionIds)) {
|
||||
$activeClassSectionId = $classSectionIds[0];
|
||||
}
|
||||
|
||||
$studentsBySection = [];
|
||||
if (! empty($classSectionIds)) {
|
||||
if (!empty($classSectionIds)) {
|
||||
$students = StudentClass::getStudentsByClassSectionIds($classSectionIds);
|
||||
if (! empty($students)) {
|
||||
if (!empty($students)) {
|
||||
$studentIds = array_values(array_unique(array_map(
|
||||
static fn (array $row) => (int) ($row['student_id'] ?? 0),
|
||||
$students
|
||||
)));
|
||||
$studentIds = array_values(array_filter($studentIds));
|
||||
|
||||
$conditionsByStudent = ! empty($studentIds)
|
||||
$conditionsByStudent = !empty($studentIds)
|
||||
? StudentMedicalCondition::getMedicalByStudentIds($studentIds)
|
||||
: [];
|
||||
$allergiesByStudent = ! empty($studentIds)
|
||||
$allergiesByStudent = !empty($studentIds)
|
||||
? StudentAllergy::getAllergiesByStudentIds($studentIds)
|
||||
: [];
|
||||
|
||||
@@ -87,7 +89,7 @@ class TeacherDashboardService
|
||||
}
|
||||
|
||||
$assignedNames = [];
|
||||
if (! empty($classSectionIds)) {
|
||||
if (!empty($classSectionIds)) {
|
||||
$rows = DB::table('teacher_class as tc')
|
||||
->select('tc.class_section_id', 'tc.position', 'u.firstname', 'u.lastname')
|
||||
->join('users as u', 'u.id', '=', 'tc.teacher_id')
|
||||
@@ -101,7 +103,7 @@ class TeacherDashboardService
|
||||
foreach ($rows as $row) {
|
||||
$sid = (int) ($row->class_section_id ?? 0);
|
||||
$pos = strtolower((string) ($row->position ?? ''));
|
||||
$name = trim(($row->firstname ?? '').' '.($row->lastname ?? ''));
|
||||
$name = trim(($row->firstname ?? '') . ' ' . ($row->lastname ?? ''));
|
||||
if ($sid === 0 || $name === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user