public function mass(Request $request) { if (!$request->ajax()) { abort(404); } $this->validate($request, ['type' => 'required|integer']); $semester = Semester::get_active_semester()->id; if (!($prevSemester = Semester::get_previous_semester())) { return response("Semester sebelumnya tidak dapat ditemukan.", 422); } $prevSemester = $prevSemester->id; if ($request->type == 1 || $request->type == 2) { $targets = Mapel::get_unset_kb(); foreach ($targets as $target) { $new = new KetuntasanBelajar(); $new->id_mapel = $target->id; $new->id_semester = $semester; if ($target->kelompok == 'A' | $target->kelompok == 'B' | $target->kelompok == 'C1') { $n = 60; } elseif ($target->kelompok == 'C2' | $target->kelompok == 'C3') { $n = 70; } $new->kb_tingkat_1p = $n; $new->kb_tingkat_2p = $n; $new->kb_tingkat_3p = $n; $new->kb_tingkat_1k = $n; $new->kb_tingkat_2k = $n; $new->kb_tingkat_3k = $n; $new->save(); } } if ($request->type == 2) { $targets = Mapel::get_set_kb(); foreach ($targets as $target) { $new = KetuntasanBelajar::where('id_mapel', '=', $target->id)->where('id_semester', '=', $semester)->first(); $new->id_semester = $semester; if ($target->kelompok == 'A' | $target->kelompok == 'B' | $target->kelompok == 'C1') { $n = 60; } elseif ($target->kelompok == 'C2' | $target->kelompok == 'C3') { $n = 70; } KetuntasanBelajar::where('id_mapel', '=', $target->id)->where('id_semester', '=', $semester)->update(['kb_tingkat_1p' => $n, 'kb_tingkat_2p' => $n, 'kb_tingkat_3p' => $n, 'kb_tingkat_1k' => $n, 'kb_tingkat_2k' => $n, 'kb_tingkat_3k' => $n]); } } if ($request->input('type') == 3) { $copy = null; try { $copy = KetuntasanBelajar::copy($prevSemester, $semester); } catch (Exception $e) { return response("Penyalinan aturan ketuntasan belajar dari semester sebelumnya gagal dilakukan.", 422); } } return 'KB berhasil diubah secara massal.'; }