159 lines
No EOL
6.9 KiB
PHP
159 lines
No EOL
6.9 KiB
PHP
<?php
|
||
namespace App\Services;
|
||
|
||
use App\Models\Booking;
|
||
use App\Models\TravelUserBookingFewo;
|
||
use App\Models\Lead;
|
||
|
||
|
||
class Placeholder
|
||
{
|
||
|
||
public static $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 function getBookingQuill(){
|
||
$ret = "";
|
||
foreach (self::$booking as $key => $value) {
|
||
$value = str_replace('#', '', $value);
|
||
$ret .= "{id: '".$value."', label: '".$value."'},"."\n";
|
||
}
|
||
return $ret;
|
||
}
|
||
|
||
public static function getBookingOptions(){
|
||
$ret = "";
|
||
foreach (self::$booking 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::$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;
|
||
$country = "";
|
||
$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;
|
||
$participants = "";
|
||
$airline = "";
|
||
$search = [];
|
||
$replace = [];
|
||
|
||
foreach (self::$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 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 = "";
|
||
$program = "";
|
||
$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 = "";
|
||
$airline = "";
|
||
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::$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;
|
||
}
|
||
|
||
|
||
} |