fix parent, teacher and admin pages
This commit is contained in:
@@ -103,11 +103,15 @@ class AuthController extends BaseApiController
|
||||
return $this->respondError('Unauthorized.', 401);
|
||||
}
|
||||
|
||||
$teacherContext = $user->teacherSessionContext();
|
||||
|
||||
return $this->respondSuccess([
|
||||
'id' => (int) $user->id,
|
||||
'firstname' => $user->firstname,
|
||||
'lastname' => $user->lastname,
|
||||
'email' => $user->email,
|
||||
'class_section_id' => $teacherContext['class_section_id'],
|
||||
'class_section_name' => $teacherContext['class_section_name'],
|
||||
], 'OK');
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ class TeacherController extends BaseApiController
|
||||
'students_by_section' => $studentsBySection,
|
||||
'assigned_names' => $data['assignedNames'] ?? [],
|
||||
'active_class_section_id' => $data['active_class_section_id'] ?? null,
|
||||
'class_section_name' => $data['class_section_name'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +106,8 @@ class StudentController extends BaseApiController
|
||||
$validator = Validator::make($data, [
|
||||
'q' => ['nullable', 'string', 'max:255'],
|
||||
'limit' => ['nullable', 'integer', 'min:1', 'max:1000'],
|
||||
'class_section_id' => ['nullable', 'integer', 'min:1'],
|
||||
'school_year' => ['nullable', 'string', 'max:32'],
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
@@ -118,35 +120,24 @@ class StudentController extends BaseApiController
|
||||
$payload = $validator->validated();
|
||||
$query = trim((string) ($payload['q'] ?? ''));
|
||||
$limit = (int) ($payload['limit'] ?? ($query !== '' ? 50 : 1000));
|
||||
$classSectionId = isset($payload['class_section_id']) ? (int) $payload['class_section_id'] : null;
|
||||
$schoolYear = isset($payload['school_year']) ? trim((string) $payload['school_year']) : null;
|
||||
|
||||
$studentsQuery = Student::query()
|
||||
->select('id', 'school_id', 'firstname', 'lastname', 'is_active')
|
||||
->where('is_active', 1);
|
||||
|
||||
if ($query !== '') {
|
||||
$studentsQuery->where(function ($builder) use ($query) {
|
||||
$builder->where('firstname', 'like', '%' . $query . '%')
|
||||
->orWhere('lastname', 'like', '%' . $query . '%')
|
||||
->orWhere('school_id', 'like', '%' . $query . '%');
|
||||
});
|
||||
$user = Auth::user();
|
||||
if (! $user instanceof User) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'Unauthorized.',
|
||||
], 401);
|
||||
}
|
||||
|
||||
$students = $studentsQuery
|
||||
->orderBy('lastname')
|
||||
->orderBy('firstname')
|
||||
->limit($limit)
|
||||
->get()
|
||||
->map(fn (Student $student) => [
|
||||
'id' => (int) $student->id,
|
||||
'student_id' => (int) $student->id,
|
||||
'school_id' => (string) ($student->school_id ?? ''),
|
||||
'firstname' => (string) ($student->firstname ?? ''),
|
||||
'lastname' => (string) ($student->lastname ?? ''),
|
||||
'name' => trim(((string) ($student->firstname ?? '')) . ' ' . ((string) ($student->lastname ?? ''))),
|
||||
'is_active' => (int) ($student->is_active ?? 0),
|
||||
])
|
||||
->values()
|
||||
->all();
|
||||
$students = $this->scoreCardService->scoreCardSelectableStudents(
|
||||
$user,
|
||||
$query,
|
||||
$limit,
|
||||
$classSectionId > 0 ? $classSectionId : null,
|
||||
$schoolYear !== '' ? $schoolYear : null,
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Settings\SchoolCalendar\SchoolCalendarContextService;
|
||||
use App\Services\Settings\SchoolCalendar\SchoolCalendarFormatterService;
|
||||
use App\Services\Settings\SchoolCalendar\SchoolCalendarMeetingService;
|
||||
use App\Services\Settings\SchoolCalendar\SchoolCalendarQueryService;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class TeacherCalendarPageController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private SchoolCalendarContextService $contextService,
|
||||
private SchoolCalendarQueryService $queryService,
|
||||
private SchoolCalendarMeetingService $meetingService,
|
||||
private SchoolCalendarFormatterService $formatterService,
|
||||
) {
|
||||
}
|
||||
|
||||
public function show(): View
|
||||
{
|
||||
$schoolYear = $this->contextService->defaultSchoolYear();
|
||||
$events = $this->queryService
|
||||
->filterEventsForAudience(
|
||||
$this->queryService->listEvents([
|
||||
'school_year' => $schoolYear,
|
||||
]),
|
||||
'teacher',
|
||||
)
|
||||
->map(fn ($event) => $this->formatterService->formatEvent($event, 'teacher'))
|
||||
->values()
|
||||
->all();
|
||||
|
||||
foreach ($this->meetingService->listMeetings($schoolYear, 'teacher', null) as $meeting) {
|
||||
$events[] = $this->formatterService->formatMeetingEvent($meeting, 'teacher');
|
||||
}
|
||||
|
||||
usort($events, function (array $left, array $right): int {
|
||||
return strcmp((string) ($left['start'] ?? ''), (string) ($right['start'] ?? ''));
|
||||
});
|
||||
|
||||
return view('teacher.calendar', [
|
||||
'events' => $events,
|
||||
'schoolYear' => $schoolYear,
|
||||
'defaultSemester' => $this->contextService->defaultSemester(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user