app/Http/Controllers/UploadResultController.php
/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
Store a newly created resource in storage.
@return Response
Store a newly created resource in storage . @return Response
public function store(Request $request)
	{
		$file 				= $request->file('file');
		if($file == null)
		{
			$message = $this->getMessage('messages.file_required');
			Toast::message($message, 'danger');
		}
		else{
			$ext                = $file->getClientOriginalExtension();
			if($ext == "xls" || $ext == "xlsx"){
				Excel::load(Input::file('file'), function ($reader) {
					try{
					$error =false;
					$int_obj = new IntegrationHandler();
					$reader_ary = $reader->toArray();
					if(isset($reader_ary[0][0]))
					{
						$reader_ary = $reader_ary[0];
					}
					$sc_result = ""; $tc_result = ""; $ts_result = "";
					$email = session()->get('email');
					foreach ($reader_ary as $row) {
						if(isset($row['scenario_id'])){
							$sc_result = $row['scenario_result'];
							if($sc_result == "" || $sc_result == null)
								$sc_result = "";
							$update_sc = [ 'result' => $sc_result, 
											'execution_type' => 'manual',
											'execution_by' => $email ];
							\App\ScenarioLab::find($row['scenario_id'])->update($update_sc);
						}
						if(isset($row['test_case_id'])){
							$exe_result = "";
							if(isset($row['case_result']) && ($row['case_result']) != ""){
								$tc_result = $row['case_result'];
							}else
							{
								 $tc_result = $sc_result;
							}
							$update_case = [ 'execution_result' =>$tc_result, 
											 'checkpoint_result' =>  $tc_result, 
											 'tc_status' => 'executed',  
											 'execution_type' => 'manual', 
											 'execution_by' => $email, 
											 'execution_by_name' => $email];
							\App\Lab::find($row['test_case_id'])->update($update_case);
						}
						if(isset($row['test_step_id'])){
							if(isset($row['step_result']) && ($row['step_result'] != "" || $row['step_result'] != null )){
								$step_result = $row['step_result'];
							}else
							{
								$step_result = $tc_result;
							}
							$update_step = ['execution_result' => $step_result, 
											 'checkpoint_result' =>  $step_result, 
											 'execution_by' => $email, 
											 'execution_by_name' => $email];				
							\App\Execution::find($row['test_step_id'])->update($update_step);
						}
					}
					}catch(Exception $e){
						$message = $this->getMessage('messages.upload_failed');
						Toast::message($message, 'danger');
					}
					if($error == false)
					{
						$message = $this->getMessage('messages.upload_success');
						Toast::message($message, 'success');
					}
				});
				$message = $this->getMessage('messages.upload_completed');
				Toast::message($message, 'info');
			}else{
				$message = $this->getMessage('messages.invalid_format');
				Toast::message($message, 'danger');
			}
		}
		return redirect()->back();
	}
public function store ( Request $ request ) { $ file = $ request -> file ( 'file' ) ; if ( $ file == null ) { $ message = $ this -> getMessage ( 'messages.file_required' ) ; Toast :: message ( $ message , 'danger' ) ; } else { $ ext = $ file -> getClientOriginalExtension ( ) ; if ( $ ext == " xls " || $ ext == " xlsx " ) { Excel :: load ( Input :: file ( 'file' ) , function ( $ reader ) { try { $ error = false ; $ int_obj = new IntegrationHandler ( ) ; $ reader_ary = $ reader -> toArray ( ) ; if ( isset ( $ reader_ary [ 0 ] [ 0 ] ) ) { $ reader_ary = $ reader_ary [ 0 ] ; } $ sc_result = " " ; $ tc_result = " " ; $ ts_result = " " ; $ email = session ( ) -> get ( 'email' ) ; foreach ( $ reader_ary as $ row ) { if ( isset ( $ row [ 'scenario_id' ] ) ) { $ sc_result = $ row [ 'scenario_result' ] ; if ( $ sc_result == " " || $ sc_result == null ) $ sc_result = " " ; $ update_sc = [ 'result' => $ sc_result , 'execution_type' => 'manual' , 'execution_by' => $ email ] ; \ App \ ScenarioLab :: find ( $ row [ 'scenario_id' ] ) -> update ( $ update_sc ) ; } if ( isset ( $ row [ 'test_case_id' ] ) ) { $ exe_result = " " ; if ( isset ( $ row [ 'case_result' ] ) && ( $ row [ 'case_result' ] ) != " " ) { $ tc_result = $ row [ 'case_result' ] ; } else { $ tc_result = $ sc_result ; } $ update_case = [ 'execution_result' => $ tc_result , 'checkpoint_result' => $ tc_result , 'tc_status' => 'executed' , 'execution_type' => 'manual' , 'execution_by' => $ email , 'execution_by_name' => $ email ] ; \ App \ Lab :: find ( $ row [ 'test_case_id' ] ) -> update ( $ update_case ) ; } if ( isset ( $ row [ 'test_step_id' ] ) ) { if ( isset ( $ row [ 'step_result' ] ) && ( $ row [ 'step_result' ] != " " || $ row [ 'step_result' ] != null ) ) { $ step_result = $ row [ 'step_result' ] ; } else { $ step_result = $ tc_result ; } $ update_step = [ 'execution_result' => $ step_result , 'checkpoint_result' => $ step_result , 'execution_by' => $ email , 'execution_by_name' => $ email ] ; \ App \ Execution :: find ( $ row [ 'test_step_id' ] ) -> update ( $ update_step ) ; } } } catch ( Exception $ e ) { $ message = $ this -> getMessage ( 'messages.upload_failed' ) ; Toast :: message ( $ message , 'danger' ) ; } if ( $ error == false ) { $ message = $ this -> getMessage ( 'messages.upload_success' ) ; Toast :: message ( $ message , 'success' ) ; } } ) ; $ message = $ this -> getMessage ( 'messages.upload_completed' ) ; Toast :: message ( $ message , 'info' ) ; } else { $ message = $ this -> getMessage ( 'messages.invalid_format' ) ; Toast :: message ( $ message , 'danger' ) ; } } return redirect ( ) -> back ( ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//Create object of IntegrationHandler class to access methods to process conversion of xls to db format //print_r($row); exit;