public function save(Request $request) { $this->validate($request, ['semester' => 'required', 'tahun_ajaran' => 'required', 'password' => 'required']); if (!\Hash::check($request->input('password'), \Auth::user()->password)) { return redirect()->route('semester')->with('message', "Password tidak tepat."); } $check = Semester::where('semester', $request->input('semester'))->where('tahun_ajaran', $request->input('tahun_ajaran'))->first(); if ($check) { return redirect()->route('semester')->with('message', "Semester sudah ada."); } $old = Semester::get_active_semester(); Semester::where('aktif', 1)->update(['aktif' => 0]); try { $new = new Semester(); $new->semester = $request->input('semester'); $new->tahun_ajaran = $request->input('tahun_ajaran'); $new->aktif = 1; $new->save(); } catch (\Illuminate\Database\QueryException $e) { $old->aktif = 1; $old->save(); } // Naik kelas if ($request->input('semester') == 1) { $all_kelas = Kelas::get(); foreach ($all_kelas as $kelas) { $kelas->tingkat = $kelas->tingkat + 1; $kelas->save(); } } // AUTO // Buat kelas X if ($request->input('autoKelas')) { $all_kelas = Kelas::where('tingkat', '=', 2)->get(); foreach ($all_kelas as $kelas) { $new = new Kelas(); $new->tingkat = 1; $new->id_jurusan = $kelas->id_jurusan; $new->kelas = $kelas->kelas; $new->angkatan = $kelas->angkatan; $new->save(); } } // Ketuntasan Belajar if ($request->input('autoKB')) { KetuntasanBelajar::copy(); } // Asosiasi Mengajar if ($request->input('autoMengajar')) { Mengajar::copy(); } return redirect()->route('panel_utama')->with('message', "Semester telah berhasil dimajukan."); }
public function mass(Request $request) { $this->validate($request, ['tingkat' => 'required|integer', 'kelas' => 'required', 'angkatan' => 'required|integer']); $jurusan = Jurusan::all(); $fails = []; foreach ($jurusan as $j) { try { $new = new Kelas(); $new->tingkat = $request->tingkat; $new->id_jurusan = $j->id; $new->kelas = $request->kelas; $new->angkatan = $request->angkatan; $new->save(); } catch (\Illuminate\Database\QueryException $e) { $fails[] = "{$request->tingkat} {$j->singkat} {$request->kelas}"; } } if (count($fails) == count($jurusan)) { return response("Operasi gagal; mungkin kelasnya sudah ada.", 422); } elseif (count($fails) > 0) { $responseText = "Kelas berhasil ditambahkan kecuali kelas: "; foreach ($fails as $f) { $responseText .= "{$f}, "; } return response(rtrim($responseText, ', '), 422); } else { return response(count($jurusan) . " kelas berhasil ditambahkan.", 200); } }