public function action($typeId, $step = 1)
 {
     $page = $step - 1;
     if (Request::isMethod('post')) {
         //cek
         // create the validation rules ------------------------
         $rules = array('level' => 'required', 'evidence' => 'required');
         // create custom validation messages ------------------
         $messages = array('required' => 'form :attribute wajib diisi.');
         $validator = Validator::make(Input::all(), $rules, $messages);
         if ($validator->fails()) {
         } else {
             $userNip = Auth::user()->nip;
             $userId = Auth::user()->id;
             // cek memiliki recap_id atau enggak
             $recap = CompetencyRecap::where('competency_id', '=', $this->competencyId)->where('user_id', '=', $userId)->where('user_nip', '=', $userNip)->first();
             if (is_null($recap)) {
                 $recap = new CompetencyRecap();
                 $recap->competency_id = $this->competencyId;
                 $recap->user_id = $userId;
                 $recap->user_nip = $userNip;
                 $recap->occupation_id = '';
                 $recap->save();
             }
             //simpan ke dalam database
             $test = new CompetencyTest();
             $test->competency_id = $this->competencyId;
             $test->competency_recap_id = $recap->id;
             $test->competency_dictionary_id = Input::get('compId');
             $test->user_id = $userId;
             $test->rater_id = $userId;
             $test->level = Input::get('level');
             $test->evidence = Input::get('evidence');
             if ($test->save()) {
                 $newStep = $step + 1;
                 return Redirect::to('competency/test/inv/' . $typeId . '/' . $newStep . '');
             }
         }
     } else {
         //data dari session
         $nip = Auth::user()->nip;
         //cek data master golongan
         $userData = CompetencyHistoryUser::where('nip', $nip)->where('competency_id', $this->competencyId)->first();
         $jabatan = RiwJabStruk::getJabatanOnCompetency($this->competencyData->date_start, $nip);
         //getProfile
         $profiles = CompetencyProfile::getProfilebyJabatan($jabatan->unit_staf_id, $typeId)->take(1)->skip($page)->first();
         //            //jika ada fung_id maka tidak menggunakan struk_id
         //            if($userData->fung_id != 0){
         //                //get profile
         //                $profiles = CompetencyProfile::with('competencyDictionary', 'competencyDictionary.level')
         //                    ->join('competency_dictionaries', 'competency_profiles.competency_dictionary_id', '=', 'competency_dictionaries.id')
         //                    ->where('competency_dictionaries.type_id', '=', $typeId)
         //                    ->where('struktural_id', '=', $userData->struk_id)
         //                    ->where('jabatan_id', '=', $userData->unit_id)
         //                    ->groupBy('competency_dictionary_id')
         //                    ->take(1)
         //                    ->skip($page)
         //                    ->first();
         //            }else {
         //                //get profile
         //                $profiles = CompetencyProfile::with('competencyDictionary', 'competencyDictionary.level')
         //                    ->join('competency_dictionaries', 'competency_profiles.competency_dictionary_id', '=', 'competency_dictionaries.id')
         //                    ->where('competency_dictionaries.type_id', '=', $typeId)
         //                    ->where('fungsional_id', '=', $userData->fung_id)
         //                    ->where('jabatan_id', '=', $userData->unit_id)
         //                    ->groupBy('competency_dictionary_id')
         //                    ->take(1)
         //                    ->skip($page)
         //                    ->first();
         //            }
         $this->layout->content = View::make('competency::test.individu', compact('profiles'));
     }
 }
 public function postUpdate($dictionary_id, $peersNip)
 {
     $userNip = Auth::user()->nip;
     $pegawai = MasterPegawai::find($peersNip);
     // cek memiliki recap_id atau enggak
     $recap = CompetencyRecap::where('competency_id', '=', $this->competencyData->id)->where('user_nip', '=', $pegawai->nip)->first();
     if (is_null($recap)) {
         //get jabatan
         $riwJabatan = RiwJabStruk::getJabatanOnCompetency($this->competencyData->date_start, $pegawai->nip);
         $recap = new CompetencyRecap();
         $recap->competency_id = $this->competencyData->id;
         $recap->user_nip = $pegawai->nip;
         $recap->occupation_id = $riwJabatan->unit_staf_id;
         $recap->save();
     }
     //simpan ke dalam database
     $test = new CompetencyTest();
     $test->competency_id = $this->competencyData->id;
     $test->competency_recap_id = $recap->id;
     $test->competency_dictionary_id = Input::get('compId');
     $test->user_id = $pegawai->nip;
     $test->rater_id = $userNip;
     $test->level = Input::get('level');
     $test->evidence = Input::get('evidence');
     if ($test->save()) {
         return Redirect::to('competency/progress/prs');
     }
 }