public function students($classroom_id, $student_id = null) { $classroom = Classroom::findOrFail($classroom_id); //->has('students', '<=', 'classrooms.attendees_limit') $classrooms = Classroom::select(DB::raw('CONCAT(hour , "-", code , "-" , day) as code , id'))->where('subject_subject_id', $classroom->subject_subject_id)->whereIn('classrooms.gender', [$classroom->gender, 'b'])->inCurrentSemester()->pluck('code', 'id')->toArray(); $days = $this->days; foreach ($classrooms as $key => $value) { $day = substr($value, -1); $new_day = $days[$day]; $classrooms[$key] = substr_replace($classrooms[$key], $new_day, -1); } $subjects = Subject::where('id', $classroom->subject_subject_id)->first()->name; $students = Student::with(['classrooms' => function ($query) use($classroom_id, $student_id) { return $query->where('classrooms.id', $classroom_id); }]); if (isset($student_id)) { $students = $students->whereHas('classrooms', function ($query) use($classroom_id, $student_id) { $query->where('classrooms.id', $classroom_id)->where('students.username', $student_id); })->get(); } else { $students = $students->whereHas('classrooms', function ($query) use($classroom_id, $student_id) { $query->where('classrooms.id', $classroom_id); })->get(); } // dd($classrooms); return view('classrooms::classrooms.students', compact('students', 'classroom', 'classrooms', 'subjects')); }
public function delete(Request $request) { $input = $request->all(); $this->student->classrooms()->detach($input['classroom_id']); event(new StudentExitClassroom(Classroom::find($input['classroom_id']), $this->student, new User())); $classroom = Classroom::select('cs.student_id as chosen', 'classrooms.attendees_limit', 'classrooms.name', 'classrooms.code', 'classrooms.id', 'classrooms.teacher_id', 'classrooms.subject_subject_id', 'classrooms.day', 'classrooms.hour')->join('subject_subjects as subsub', 'subsub.id', '=', 'classrooms.subject_subject_id')->join('student_subjects as stusub', function ($join) { $join->on('stusub.subject_id', '=', 'subsub.id')->where('stusub.student_id', '=', $this->student->id); })->leftJoin('classroom_students as cs', function ($j) { $j->on('cs.classroom_id', '=', 'classrooms.id')->where('cs.student_id', '=', $this->student->id)->where('cs.semester_id', '=', semester()->id); })->whereIn('classrooms.gender', [$this->student->gender, 'b'])->with('subject')->withCount('students')->find($input['classroom_id']); return response()->json($classroom, 200, [], JSON_NUMERIC_CHECK); }
public function index() { $available_classrooms = Classroom::select('classrooms.attendees_limit', 'classrooms.name', 'classrooms.code', 'classrooms.id', 'classrooms.teacher_id', 'classrooms.subject_subject_id', 'classrooms.day', 'classrooms.hour')->join('subject_subjects as subsub', 'subsub.id', '=', 'classrooms.subject_subject_id')->join('student_subjects as stusub', function ($join) { $join->on('stusub.subject_id', '=', 'subsub.id')->where('stusub.student_id', '=', student()->id); })->whereIn('classrooms.gender', [student()->gender, 'b'])->whereHas('students', function ($query) { return $query->havingRaw('COUNT(students.id) < attendees_limit'); })->whereNotIn('subject_subject_id', function ($query) { $query->select('classrooms.subject_subject_id')->from('classrooms')->join('classroom_students as clastud', function ($join) { $join->on('clastud.classroom_id', '=', 'classrooms.id')->where('clastud.student_id', '=', student()->id); }); })->with('teacher', 'subject', 'students')->groupBy('teacher_id', 'subject_subject_id')->get(); //return $available_classrooms; $event = SemesterEvent::classroom()->first(); $chosen_classrooms = Classroom::whereHas('students', function ($query) { $query->where('students.id', student()->id); })->get(); return view('students::classrooms.index', compact('available_classrooms', 'chosen_classrooms', 'event')); }
private function getClassrooms() { $classrooms = Classroom::select('cs.student_id as chosen', 'classrooms.attendees_limit', 'classrooms.name', 'classrooms.code', 'classrooms.id', 'classrooms.teacher_id', 'classrooms.subject_subject_id', 'classrooms.day', 'classrooms.hour')->join('subject_subjects as subsub', 'subsub.id', '=', 'classrooms.subject_subject_id')->join('student_subjects as stusub', function ($join) { $join->on('stusub.subject_id', '=', 'subsub.id')->where('stusub.student_id', '=', $this->student->id)->where('stusub.state', '=', 'study')->where('stusub.semester_id', '=', $this->semester->id); })->leftJoin('classroom_students as cs', function ($j) { $j->on('cs.classroom_id', '=', 'classrooms.id')->where('cs.student_id', '=', $this->student->id)->where('cs.semester_id', '=', semester()->id); })->whereIn('classrooms.gender', [$this->student->gender, 'b'])->with('subject')->withCount('students')->groupBy('classrooms.id')->get()->groupBy('subject_subject_id')->toArray(); $new_classrooms = []; foreach ($classrooms as $classroom) { $exist = array_where($classroom, function ($key, $value) { return $value['chosen'] > 0; }); if (!count($exist)) { $new_classrooms[] = $classroom; } } return $new_classrooms; }
public function addclassroom($subject_id, $student_id) { # code... // $classrooms = Classroom::with('students') // ->where('subject_subject_id',$subject_id) // ->get(); // $times = $classrooms->pluck('hour','id'); $classrooms = Classroom::select(DB::raw('CONCAT(hour , "-", code , "-" , day) as code , id'))->where('subject_subject_id', $subject_id)->inCurrentSemester()->pluck('code', 'id')->toArray(); // dd($classrooms); $days = $this->days; foreach ($classrooms as $key => $value) { $day = substr($value, -1); $new_day = $days[$day]; $classrooms[$key] = substr_replace($classrooms[$key], $new_day, -1); } return view('students::classrooms.addclassroom', compact('classrooms', 'subject_id', 'student_id', 'times')); }