Example #1
0
 public function saveStartApp()
 {
     $input = Input::all();
     $scholarship = Scholarship::where('user_id', '=', $input['user_id'])->first();
     $appData = ApplicationData::where('user_id', '=', $input['user_id'])->first();
     $form_comp_data = FormCompleteData::find(Input::all()['user_id']);
     //checks to see if user already has scholaship details and return the details if they exist,
     //if it doesnt exist, it inserts a new row in the database with
     //return var_dump($appData);
     if (!is_null($scholarship)) {
         $essayfile_path = $scholarship->essay_url;
         $essayfile_name = new SplFileInfo($essayfile_path);
         $essayfile_name = $essayfile_name->getFilename();
         $scholarship->reg_number = $scholarship->generateRegNumber($input['user_id'], $input['scholarship_type']['name']);
         $scholarship->scholarship_type = $input['scholarship_type']['name'];
         $scholarship->course_of_study = $input['course_of_study'];
         $scholarship->government_bounded = $input['ready_to_bound'] == 'YES' ? 'YES' : 'NO';
         $scholarship->already_in_school = $input['already_in_school'] == 'YES' ? 'YES' : 'NO';
         $scholarship->has_admission = $input['has_an_admission'] == 'YES' ? 'YES' : 'NO';
         $scholarship->essay_url = $input['path_to_essay'];
         $scholarship->save();
         return Response::json(array("user_id" => $scholarship->user_id, "reg_number" => $scholarship->reg_number, "course_of_study" => $scholarship->course_of_study, "scholarship_type" => $scholarship->scholarship_type, "government_bounded" => $scholarship->government_bounded, "already_in_school" => $scholarship->already_in_school, "has_admission" => $scholarship->has_admission, "essay_url" => $essayfile_name), 200);
     } else {
         $scholarship = new Scholarship();
         $scholarship->user_id = $input['user_id'];
         $scholarship->reg_number = $scholarship->generateRegNumber($input['user_id'], $input['scholarship_type']['name']);
         $scholarship->scholarship_type = $input['scholarship_type']['name'];
         $scholarship->course_of_study = $input['course_of_study'];
         $scholarship->government_bounded = $input['ready_to_bound'] == 'YES' ? 'YES' : 'NO';
         $scholarship->already_in_school = $input['already_in_school'] == 'YES' ? 'YES' : 'NO';
         $scholarship->has_admission = $input['has_an_admission'] == 'YES' ? 'YES' : 'NO';
         $scholarship->essay_url = $input['path_to_essay'];
         $scholarship->push();
         $form_comp_data->scholarship_app_completed = "1";
         $form_comp_data->save();
         $appData->app_progress = 20 + $appData->app_progress;
         $appData->save();
         return Response::json(array("Message" => "Just added New stuff"));
     }
 }