mein-sterntours/app/Services/Placeholder.php

212 lines
No EOL
8.8 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Services;
use App\Models\Booking;
use App\Models\TravelUserBookingFewo;
use App\Models\Lead;
class Placeholder
{
public static $placeholder_booking = [
'dear' => '#geehrte/r#',
'salutation' => '#Anrede#',
'title' => '#Titel#',
'first_name' => '#Vorname#',
'last_name' => '#Nachname#',
'country' => '#Reiseland#',
'program' => '#Programm#',
'start_date' => '#Anreisedatum#',
'end_date' => '#Abreisedatum#',
'participants' => '#Teilnehmer#',
'booking_date' => '#Buchungsdatum#',
'airline' => '#Airline#'
];
public static $placeholder_lead = [
'dear' => '#geehrte/r#',
'salutation' => '#Anrede#',
'title' => '#Titel#',
'first_name' => '#Vorname#',
'last_name' => '#Nachname#',
'country' => '#Reiseland#',
'program' => '#Programm#',
'start_date' => '#Anreisedatum#',
'end_date' => '#Abreisedatum#',
'participants' => '#Teilnehmer#',
'booking_date' => '#Buchungsdatum#',
];
public static $placeholder_fewo= [
'dear' => '#geehrte/r#',
'salutation' => '#Anrede#',
'title' => '#Titel#',
'first_name' => '#Vorname#',
'last_name' => '#Nachname#',
'program' => '#Programm#',
'start_date' => '#Anreisedatum#',
'end_date' => '#Abreisedatum#',
'booking_date' => '#Buchungsdatum#',
];
public static function getOptionsQuill($key){
$ret = "";
switch ($key) {
case 'booking':
$placehoder = self::$placeholder_booking;
break;
case 'lead':
$placehoder = self::$placeholder_lead;
break;
case 'fewo':
$placehoder = self::$placeholder_fewo;
break;
default:
$placehoder = self::$placeholder_booking;
break;
}
foreach ($placehoder as $key => $value) {
$value = str_replace('#', '', $value);
$ret .= "{id: '".$value."', label: '".$value."'},"."\n";
}
return $ret;
}
public static function getBookingOptions(){
$ret = "";
foreach (self::$placeholder_booking as $key => $value) {
$value = str_replace('#', '', $value);
$ret .= '<option value="'.$value.'">'.$value.'</option>'."\n";
}
return $ret;
}
public static function getLeadOptions(){
$ret = "";
foreach (self::$placeholder_lead as $key => $value) {
$value = str_replace('#', '', $value);
$ret .= '<option value="'.$value.'">'.$value.'</option>'."\n";
}
return $ret;
}
public static function getFewoOptions(){
$ret = "";
foreach (self::$placeholder_fewo as $key => $value) {
$value = str_replace('#', '', $value);
$ret .= '<option value="'.$value.'">'.$value.'</option>'."\n";
}
return $ret;
}
public static function replaceBooking(Booking $booking, $content)
{
$dear = $booking->customer->salutation_id == 1 ? 'geehrter' : 'geehrte';
$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 = isset($booking->customer->salutation) ? $booking->customer->salutation->name : '-';
$start_date = $booking->getStartDateFormat();
$end_date = $booking->getEndDateFormat();
$booking_date = $booking->getBookingDateFormat();
$airline = $booking->airline ? $booking->airline->name_full : '-';
$participants = "Teilnehmer:<br>";
//first
if($booking->participant_firstname){
$participants .= $booking->participant_salutation_id ? \App\Services\Model::getSalutationById($booking->participant_salutation_id)." " : '';
$participants .= $booking->participant_firstname." ".$booking->participant_name;
$participants .= $booking->participant_birthdate ? ' | '._format_date($booking->participant_birthdate) : '';
$participants .= $booking->travel_nationality ? ' | '.$booking->travel_nationality->name : '';
$participants .= '<br>';
}
if($booking->participants->count()){
foreach($booking->participants as $participant){
$participants .= $participant->salutation ? $participant->salutation->name." " : '';
$participants .= $participant->participant_firstname." ".$participant->participant_name;
$participants .= $participant->participant_birthdate ? ' | '._format_date($participant->participant_birthdate) : '';
$participants .= $participant->travel_nationality ? ' | '.$participant->travel_nationality->name : '';
$participants .= $participant->participant_child ? ' | Kind' : '';
$participants .= '<br>';
}
}
$search = [];
$replace = [];
foreach (self::$placeholder_booking as $key => $value) {
$search[] = $value;
$replace[] = ${$key};
}
$content = str_replace($search, $replace, $content);
$content = preg_replace('/<placeholder.*?>(.*?)<\/placeholder>/', '$1', $content);
$content = preg_replace('/<span contenteditable="false">(.*?)<\/span>/', '$1', $content);
return $content;
}
public static function replaceBookingFewo(TravelUserBookingFewo $booking_fewo, $content)
{
$dear = $booking_fewo->travel_user->salutation_id == 1 ? 'geehrter' : 'geehrte';
$first_name = $booking_fewo->travel_user->first_name;
$last_name = $booking_fewo->travel_user->last_name;
$title = $booking_fewo->travel_user->title;
$program = $booking_fewo->fewo_lodging_id ? $booking_fewo->fewo_lodging->name : "-";
$salutation = $booking_fewo->travel_user->salutation_id == 1 ? 'Herr' : 'Frau';
$start_date = $booking_fewo->from_date;
$end_date = $booking_fewo->to_date;
$booking_date = $booking_fewo->booking_date;
$search = [];
$replace = [];
foreach (self::$placeholder_fewo as $key => $value) {
$search[] = $value;
$replace[] = ${$key};
}
$content = str_replace($search, $replace, $content);
$content = preg_replace('/<placeholder.*?>(.*?)<\/placeholder>/', '$1', $content);
$content = preg_replace('/<span contenteditable="false">(.*?)<\/span>/', '$1', $content);
return $content;
}
public static function replaceLead(Lead $lead, $content)
{
$dear = $lead->customer->salutation_id == 1 ? 'geehrter' : 'geehrte';
$first_name = $lead->customer->firstname;
$last_name = $lead->customer->name;
$title = $lead->customer->title;
$country = $lead->travelcountry_id ? $lead->travel_country->name : "-";
$program = $lead->travelagenda_id ? $lead->travel_agenda->name : "-";
$salutation = $lead->customer->salutation_id == 1 ? 'Herr' : 'Frau';
$start_date = $lead->travelperiod_start ? _format_date($lead->travelperiod_start) : '-';
$end_date = $lead->travelperiod_end ? _format_date($lead->travelperiod_end) : '-';
$booking_date = $lead->request_date ? _format_date($lead->request_date) : '-';
$participants = "";
if($lead->lead_participants->count()){
$participants = "Teilnehmer:<br>";
foreach($lead->lead_participants as $participant){
$participants .= $participant->salutation ? $participant->salutation->name." " : '';
$participants .= $participant->participant_firstname." ".$participant->participant_name;
$participants .= $participant->participant_birthdate ? ' | '._format_date($participant->participant_birthdate) : '';
//$participants .= $participant->participant_child ? ' | Kind' : ' | Erwachsener';
//$participants .= $participant->travel_nationality ? ' | '.$participant->travel_nationality->name : '';
$participants .= '<br>';
}
}
$search = [];
$replace = [];
foreach (self::$placeholder_lead as $key => $value) {
$search[] = $value;
$replace[] = ${$key};
}
$content = str_replace($search, $replace, $content);
$content = preg_replace('/<placeholder.*?>(.*?)<\/placeholder>/', '$1', $content);
$content = preg_replace('/<span contenteditable="false">(.*?)<\/span>/', '$1', $content);
return $content;
}
}