Upload Files Booking, Mails, Attachments,

This commit is contained in:
Kevin Adametz 2020-04-17 15:51:22 +02:00
parent 5daea268f7
commit 68b9d1ff88
92 changed files with 2837 additions and 1778 deletions

View file

@ -0,0 +1,52 @@
<?php
namespace App\Repositories;
use App\Models\BookingFile;
use Response;
class BookingFileRepository extends FileRepository {
protected $booking_file;
protected $booking_id;
protected $identifier;
public function __construct(BookingFile $model){
parent::__construct();
$this->model = $model;
}
public function save(){
$this->booking_file = BookingFile::create([
'booking_id' => $this->booking_id,
'identifier' => $this->identifier,
'filename' => $this->allowed_filename,
'dir' => $this->dir,
'original_name' => $this->originalName,
'ext' => $this->extension,
'mine' => $this->mine,
'size' => $this->size
]);
}
public function response(){
return Response::json([
'error' => false,
'filename' => $this->allowed_filename,
'file_id' =>$this->booking_file->id,
'file_data' => $this->extension,
'file_icon' => $this->booking_file->getIconExt(),
'file_format_bytes' => $this->booking_file->formatBytes(),
'file_url' => $this->booking_file->getURL(),
'redirect' => '',
'code' => 200
], 200);
}
}

View file

@ -0,0 +1,53 @@
<?php
namespace App\Repositories;
use App\Models\CMSContent;
use Response;
class CMSFileRepository extends FileRepository {
protected $identifier;
public function __construct($model){
parent::__construct();
$this->model = $model;
}
public function save(){
$file_data = [
'identifier' => $this->identifier,
'filename' => $this->allowed_filename,
'dir' => $this->dir,
'original_name' => $this->originalName,
'ext' => $this->extension,
'mine' => $this->mine,
'size' => $this->size
];
$data = [
"name" => $this->originalName,
"field" => "file",
"full_text" => \GuzzleHttp\json_encode($file_data),
];
$this->model = CMSContent::create($data);
//store in cms old Datebase
\App\Models\Sym\CmsContent::create($data);
}
public function response(){
return Response::json([
'error' => false,
'filename' => $this->allowed_filename,
'file_id' => $this->model->id,
'file_data' => $this->extension,
'file_icon' => $this->model->getIconExt(),
'file_format_bytes' => $this->model->formatBytes(),
'file_url' => $this->model->getURL(),
'redirect' => '',
'code' => 200
], 200);
}
}

View file

@ -3,145 +3,53 @@
namespace App\Repositories;
use App\Models\CustomerFile;
use Request;
use Response;
use Storage;
use Util;
use Validator;
class CustomerFileRepository extends FileRepository {
class CustomerFileRepository extends BaseRepository {
protected $rules;
protected $messages;
protected $disk;
protected $dir;
protected $customer_file;
protected $customer_id;
protected $customer_mail_id;
protected $identifier;
public function __construct(CustomerFile $model){
parent::__construct();
$this->model = $model;
$this->rules = [
'file' => 'required|mimes:pdf,jpeg,png|max:32768'
];
$this->messages = [
'file.mimes' => 'Datei ist kein PDF/JPG/PNG Format',
'file.required' => 'PDF/JPG/PNG-Datei wird benötigt'
];
}
public function _set($name, $value){
$this->{$name} = $value;
}
/* public function load($id){
$this->model = $id;
}
*/
public function uploadFile( $form_data )
{
$validator = Validator::make($form_data, $this->rules, $this->messages);
if ($validator->fails()) {
return Response::json([
'error' => true,
'message' => $validator->messages()->first(),
'code' => 400
], 400);
}
$file = $form_data['file'];
$originalName = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$mine = $file->getClientMimeType();
$size = $file->getClientSize();
$originalNameWithoutExt = substr($originalName, 0, strlen($originalName) - strlen($extension) - 1);
$filename = Util::sanitize($originalNameWithoutExt, true, false, true);
$allowed_filename = uniqid() . '_' . $filename.".".$extension;
//$dir = $this->model->getInvoiceStorageAttDir();
if(!Storage::disk($this->disk)->exists( $this->dir )){
Storage::disk($this->disk)->makeDirectory($this->dir); //creates directory
}
Storage::disk($this->disk)->put($this->dir.$allowed_filename, file_get_contents($file->getRealPath()));
$customer_file = CustomerFile::create([
public function save(){
$this->customer_file = CustomerFile::create([
'customer_id' => $this->customer_id,
'customer_mail_id' => $this->customer_mail_id,
'identifier' => $this->identifier,
'filename' => $allowed_filename,
'filename' => $this->allowed_filename,
'dir' => $this->dir,
'original_name' => $originalName,
'ext' => $extension,
'mine' => $mine,
'size' => $size
'original_name' => $this->originalName,
'ext' => $this->extension,
'mine' => $this->mine,
'size' => $this->size
]);
}
public function response(){
return Response::json([
'error' => false,
'filename' => $allowed_filename,
'file_id' =>$customer_file->id,
'file_data' => $extension,
'file_icon' => $customer_file->getIconExt(),
'file_format_bytes' => $customer_file->formatBytes(),
'file_url' => $customer_file->getURL(),
'original_name' => $this->originalName,
'filename' => $this->allowed_filename,
'file_id' =>$this->customer_file->id,
'file_data' => $this->extension,
'file_icon' => $this->customer_file->getIconExt(),
'file_format_bytes' => $this->customer_file->formatBytes(),
'file_url' => $this->customer_file->getURL(),
'redirect' => '',
'code' => 200
], 200);
}
/* public function createFile(Request $request)
{
$locale = \App::getLocale();
$data = [
'step' => 2,
'locale' => $locale,
];
$rules = array(
'network_name' => 'required|max:255',
'input_file_now' => 'required|mimes:png,pdf,jpg,jpeg|max:30000'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
// get the error messages from the validator
$messages = $validator->messages();
// redirect our user back to the form with the errors from the validator
return view('user.register_complete', $data)->withErrors($validator);
} else {
$user = \Auth::user();
if(!$user->account->network_name){
$file = request()->file('input_file_now');
//$ext = $file->guessClientExtension();
//$file->storeAs('user/' . $user->id .'/verification');
$data = $file->store('user/' . $user->id .'/verification');
$account = $user->account;
$account->network_name = Input::get('network_name');
$account->network_verification = basename($data);
$account->save();
$user->role_id = 2; //set as User by default!
$user->save();
}
return redirect('complete_register');
//return view('user.register_complete', $data);
}
}*/
}

View file

@ -6,6 +6,7 @@ namespace App\Repositories;
use App\Mail\MailSendInfo;
use App\Models\Airline;
use App\Models\Booking;
use App\Models\CMSContent;
use App\Models\CustomerFile;
use App\Models\CustomerMail;
use App\Services\Util;
@ -168,12 +169,12 @@ class CustomerMailRepository extends BaseRepository {
return true;
}
private function prepareContent($booking, $content){
$first_name = $booking->customer->firstname;
$last_name = $booking->customer->name;
$title = $booking->customer->title;
$country = $booking->travel_country_id ? $booking->travel_country->name : "-";
$program = $booking->travelagenda_id ? $booking->travel_agenda->name : "-";
$salutation = $booking->customer->salutation->name;
@ -183,8 +184,8 @@ class CustomerMailRepository extends BaseRepository {
$airline = $booking->airline ? $booking->airline->name_full : '-';
$dear = $booking->customer->salutation_id == 1 ? 'geehrter' : 'geehrte';
$search = ['#geehrte/r#', '#Anrede#', '#Vorname#', '#Nachname#', '#Reiseland#', '#Programm#', '#Anreisedatum#', '#Abreisedatum#', '#Buchungsdatum#', '#Airline#'];
$replace = [$dear, $salutation, $first_name, $last_name, $country, $program, $start_date, $end_date, $booking_date, $airline];
$search = ['#geehrte/r#', '#Anrede#', '#Titel#', '#Vorname#', '#Nachname#', '#Reiseland#', '#Programm#', '#Anreisedatum#', '#Abreisedatum#', '#Buchungsdatum#', '#Airline#'];
$replace = [$dear, $salutation, $title, $first_name, $last_name, $country, $program, $start_date, $end_date, $booking_date, $airline];
$content = str_replace($search, $replace, $content);
return $content;
@ -287,19 +288,22 @@ class CustomerMailRepository extends BaseRepository {
if ($data['action'] === "new-customer-mail") {
$value->id = "";
$value->draft = false;
$lead_id = "-";
//singel
if (isset($data['booking_id']) && $booking = Booking::find($data['booking_id'])) {
$value->id = $data['booking_id'];
$value->booking = $booking;
$value->show = 'single';
$value->draft = true;
$lead_id = " - (".$value->booking->lead_id.")";
}else{
//multi
$value->show = 'multi';
}
$value->customers = $data['customers'];
$value->subject = "";
$value->message = "<p>Sehr #geehrte/r# #Anrede# #Vorname# #Nachname#,</p><p>Text ...</p>";
$value->subject = $lead_id ;
$value->message = CMSContent::getContentBySlug('mailvorlage');
$value->s_placeholder = "Betreff der E-Mail";
$value->m_placeholder = "Nachricht der E-Mail";
if(isset($data['customer_mail_id']) && $customer_mail = CustomerMail::find($data['customer_mail_id'])){

View file

@ -0,0 +1,108 @@
<?php
namespace App\Repositories;
use Response;
use Storage;
use Util;
use Validator;
class FileRepository extends BaseRepository {
protected $rules;
protected $messages;
protected $disk;
protected $dir;
protected $filename;
protected $allowed_filename;
protected $originalName;
protected $extension;
protected $mine;
protected $size;
public function __construct(){
$this->rules = [
'file' => 'required|mimes:pdf,jpeg,png|max:32768'
];
$this->messages = [
'file.mimes' => 'Datei ist kein PDF/JPG/PNG Format',
'file.required' => 'PDF/JPG/PNG-Datei wird benötigt'
];
}
public function _set($name, $value){
$this->{$name} = $value;
}
public function uploadFile( $form_data )
{
$validator = Validator::make($form_data, $this->rules, $this->messages);
if ($validator->fails()) {
return Response::json([
'error' => true,
'message' => $validator->messages()->first(),
'code' => 400
], 400);
}
$file = $form_data['file'];
$this->originalName = $file->getClientOriginalName();
$this->extension = strtolower($file->getClientOriginalExtension());
$this->mine = $file->getClientMimeType();
$this->size = $file->getClientSize();
$this->makeFilename();
//$dir = $this->model->getInvoiceStorageAttDir();
$this->store(file_get_contents($file->getRealPath()));
$this->save();
return $this->response();
}
public function storeFile( $content )
{
$this->makeFilename();
$this->store($content);
$this->size = Storage::disk($this->disk)->size($this->dir.$this->allowed_filename);
$this->save();
return $this->response();
}
public function store($content){
if(!Storage::disk($this->disk)->exists( $this->dir )){
Storage::disk($this->disk)->makeDirectory($this->dir); //creates directory
}
Storage::disk($this->disk)->put($this->dir.$this->allowed_filename, $content);
}
public function save(){
}
public function response(){
return Response::json([
'error' => false,
'filename' => $this->allowed_filename,
'originalName' => $this->originalName,
'file_data' => $this->extension,
'mine' => $this->mine,
'size' => $this->size,
'redirect' => '',
'code' => 200
], 200);
}
private function makeFilename(){
$originalNameWithoutExt = substr($this->originalName, 0, strlen($this->originalName) - strlen($this->extension) - 1);
$this->filename = Util::sanitize($originalNameWithoutExt, true, false, true);
$this->allowed_filename = uniqid("", true) . '_' . $this->filename.".".$this->extension;
}
}