<commit_before><?php

namespace App\Http\Controllers;

use App\Services\UploadFileService;
use Illuminate\Support\Facades\Input;
use Carbon\Carbon;

class UploadFileController extends Controller
{

    // services
    public  $uploadFileService =null;

    public function __construct(){
        // initialize benefiters list service
        $this->uploadFileService = new UploadFileService();
    }


    // returns upload csv view
    public function getUploadCSV(){
        $importedCSVFiles_basic_info = $this->uploadFileService->findImportedHistory();
        return view('uploadExcel')->with('importedCSVFiles_basic_info', $importedCSVFiles_basic_info);
    }

    // uploads the file to server
    public function excelUpload(){
        // instantiate the upload file service
        $uploadFileService = new UploadFileService();
        // get the file from the post request
        $file = Input::file('file');
        // set file name
        $filename = Carbon::now('Europe/Athens') . '-' . $file->getClientOriginalName();
        // set file path
        $filepath = public_path() . '/uploads/uploadedExcels/';
        // move file to correct location
        $file->move($filepath, $filename);
        $fullFilePath = $filepath . $filename;
        // Insert upload main info (file name & date) to DB
        $uploadFileService->importedFilesTable($file->getClientOriginalName());
        // insert values to DB
        return $uploadFileService->fileImport($fullFilePath);
    }
//
//
//    //---------------------------------------------------//
//    //---- TO BE DELETED LATER (test outputs) -----------//
//
//    public function testData(){
//        $benefiter_id = 2;
//        $singleRowTestArray = array('folder_number' => 'ΚΚ1',
//            'has_social_reference' => 'ναι',
//            'social_reference_actions' => 'Κ-ενεργεια α',
//            'social_reference_date' => '14-5-2016',
//            'has_medical_reference' => 'ναι',
//            'medical_reference_actions' => 'ι-ενεργεια α',
//            'medical_reference_date' => '14-5-2016',
//            'has_legal_reference' => 'ναι',
//            'legal_reference_actions' => 'ν-ενεργεια α',
//            'legal_reference_date' => '14-5-2016',
//            'has_educational_reference' => 'οχι',
//            'educational_reference_actions' => 'ν-ενεργεια β',
//            'educational_reference_date' => '14-5-2016',);
//        $this->uploadFileService->selectOnlyReferrals($singleRowTestArray, $benefiter_id);
//    }
}
<commit_msg>BEN-428 upload file controller can be used only by admin (using middleware)<commit_after><?php

namespace App\Http\Controllers;

use App\Services\UploadFileService;
use Illuminate\Support\Facades\Input;
use Carbon\Carbon;

class UploadFileController extends Controller
{

    // services
    public  $uploadFileService =null;

    public function __construct(){
        // only for admin
        $this->middleware('admin');
        // initialize benefiters list service
        $this->uploadFileService = new UploadFileService();
    }


    // returns upload csv view
    public function getUploadCSV(){
        $importedCSVFiles_basic_info = $this->uploadFileService->findImportedHistory();
        return view('uploadExcel')->with('importedCSVFiles_basic_info', $importedCSVFiles_basic_info);
    }

    // uploads the file to server
    public function excelUpload(){
        // instantiate the upload file service
        $uploadFileService = new UploadFileService();
        // get the file from the post request
        $file = Input::file('file');
        // set file name
        $filename = Carbon::now('Europe/Athens') . '-' . $file->getClientOriginalName();
        // set file path
        $filepath = public_path() . '/uploads/uploadedExcels/';
        // move file to correct location
        $file->move($filepath, $filename);
        $fullFilePath = $filepath . $filename;
        // Insert upload main info (file name & date) to DB
        $uploadFileService->importedFilesTable($file->getClientOriginalName());
        // insert values to DB
        return $uploadFileService->fileImport($fullFilePath);
    }
//
//
//    //---------------------------------------------------//
//    //---- TO BE DELETED LATER (test outputs) -----------//
//
//    public function testData(){
//        $benefiter_id = 2;
//        $singleRowTestArray = array('folder_number' => 'ΚΚ1',
//            'has_social_reference' => 'ναι',
//            'social_reference_actions' => 'Κ-ενεργεια α',
//            'social_reference_date' => '14-5-2016',
//            'has_medical_reference' => 'ναι',
//            'medical_reference_actions' => 'ι-ενεργεια α',
//            'medical_reference_date' => '14-5-2016',
//            'has_legal_reference' => 'ναι',
//            'legal_reference_actions' => 'ν-ενεργεια α',
//            'legal_reference_date' => '14-5-2016',
//            'has_educational_reference' => 'οχι',
//            'educational_reference_actions' => 'ν-ενεργεια β',
//            'educational_reference_date' => '14-5-2016',);
//        $this->uploadFileService->selectOnlyReferrals($singleRowTestArray, $benefiter_id);
//    }
}

{'fraction_non_alphanumeric': 0.16190659976842917, 'fraction_numerical': 0.012157468159011964, 'mean_word_length': 2.3203074951953875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4143581', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1480, 'n_words': 307}