mirror of
https://github.com/robonen/education-project.git
synced 2026-03-20 02:44:31 +00:00
Получение предметов и учеников класса, классов учителя
This commit is contained in:
@@ -51,7 +51,7 @@ class SchoolClassController extends Controller
|
||||
}
|
||||
|
||||
//добавление, изменение классного руководителя
|
||||
public function addClassroomTeacher(SchoolClass $class, Request $request)
|
||||
public function addTeacher(SchoolClass $class, Request $request)
|
||||
{
|
||||
$teacher = Teacher::findOrfail((int)$request->input('teacher_id'));
|
||||
$class->classroom_teacher = $teacher->id;
|
||||
@@ -59,4 +59,26 @@ class SchoolClassController extends Controller
|
||||
return response()->json(SchoolClass::find($class->id), 200);
|
||||
}
|
||||
|
||||
//получение всех учеников в классе
|
||||
public function getStudents(SchoolClass $class)
|
||||
{
|
||||
$students = $class->students;
|
||||
$studentsOnlyFIO = [];
|
||||
foreach ($students as $student) {
|
||||
array_push($studentsOnlyFIO, $student->only('id', 'name', 'surname', 'patronymic'));
|
||||
}
|
||||
return response()->json($studentsOnlyFIO, 200);
|
||||
}
|
||||
|
||||
//получение всех предметов для класса
|
||||
public function getSubjects(SchoolClass $class)
|
||||
{
|
||||
$subjects = $class->subjects;
|
||||
$subjectExceptPivot = [];
|
||||
foreach ($subjects as $subject) {
|
||||
array_push($subjectExceptPivot, collect($subject)->except('pivot'));
|
||||
}
|
||||
return response()->json($subjectExceptPivot, 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,4 +44,14 @@ class TeacherController extends Controller
|
||||
$teacher->update($request->all());
|
||||
return response()->json($teacher, 200);
|
||||
}
|
||||
|
||||
public function getClasses(Teacher $teacher)
|
||||
{
|
||||
$timetables = $teacher->timetables;
|
||||
$classes = [];
|
||||
foreach ($timetables as $timetable) {
|
||||
array_push($classes, $timetable->schoolClass->only('id','number','letter'));
|
||||
}
|
||||
return response()->json(collect($classes)->unique(), 200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,13 @@ class SchoolClass extends Model
|
||||
|
||||
public function students()
|
||||
{
|
||||
return $this->hasMany(Student::class);
|
||||
return $this->hasMany(Student::class, 'class_id');
|
||||
}
|
||||
|
||||
public function subjects()
|
||||
{
|
||||
return $this->belongsToMany(Subject::class, 'academic_plans')->withPivot('hours_per_week', 'hours_per_year');
|
||||
return $this->belongsToMany(Subject::class, 'academic_plans', 'class_id')
|
||||
->withPivot('hours_per_week', 'hours_per_year');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ class Subject extends Model
|
||||
|
||||
public function schoolClasses()
|
||||
{
|
||||
return $this->belongsToMany(SchoolClass::class, 'academic_plans')->withPivot('hours_per_week', 'hours_per_year');
|
||||
return $this->belongsToMany(SchoolClass::class, 'academic_plans', 'class_id')
|
||||
->withPivot('hours_per_week', 'hours_per_year');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,4 +19,9 @@ class Teacher extends Model
|
||||
return $this->hasOne(SchoolClass::class, 'classroom_teacher');
|
||||
}
|
||||
|
||||
public function timetables()
|
||||
{
|
||||
return $this->hasMany(Timetable::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user