Esempio n. 1
0
 public function add()
 {
     $fm = Input::get('form');
     $an = Input::get('anak');
     $jk = Input::get('jenis_kasus');
     $user = Auth::user();
     // inject lka if not set
     if (!isset($fm['no_lka'])) {
         $form = Anak::find($an['id'])->form->first();
         $fm['no_lka'] = $form->no_lka;
     }
     // inject tanggal if not set
     if (!isset($fm['tanggal'])) {
         $fm['tanggal'] = date('Y-m-d');
     }
     $form = FormDAO::saveOrUpdate($fm);
     $anak = Anak::find($an['id']);
     //
     //        //save many to many
     $form = Form::find($form->id);
     $form->Anak()->attach($an['id']);
     $form->user()->attach($user->id);
     JenisKasusDAO::attachAll($jk, $anak);
     //this part must be write after JenisKasusDAO::attachAll
     //and cannot befote JenisKasusDAO::attahcAll
     //otherwise it will detach other jenis kasus
     if (isset($jk['other']['check'])) {
         if ($jk['other']['check'] == 1) {
             JenisKasusDAO::saveOrUpdate($jk, $anak);
         }
     }
     //notifikasi
     FormKA7DisposisiHelper::addNotif($form->id);
     Session::flash('message', "Form with No LKA {$form->no_lka} has been added!");
     return Redirect::to('/dash/formka7');
 }