This commit is contained in:
Kevin Adametz 2024-08-05 11:58:09 +02:00
parent c1c613a4b9
commit 881fc84207
384 changed files with 50679 additions and 990 deletions

234
app/Helper/Booking.php Normal file
View file

@ -0,0 +1,234 @@
<?php
namespace App\Helper;
use App\Models\BookingDocument;
class BookingDocument
{
private static $files_count = 0;
public static function getFilesCount(){
return self::$files_count++;
}
public static function getBookingDocumentsHTMLTable($identifier, $booking){
$ret = "";
$files = self::getV2BookingDocuments($identifier, $booking);
if($files){
$ret .= self::makeHTMLTable($files, $identifier, 'v2');
}
return $ret;
//TODO !!! v3 save data and output
$files = self::getBookingDocuments($identifier, $booking->id);
if($files){
$ret .= self::makeHTMLTable($files, $identifier, 'v3');
}else{
$files = self::getV2BookingDocuments($identifier, $booking);
if($files){
$ret .= self::makeHTMLTable($files, $identifier, 'v2');
}
}
return $ret;
}
public static function getBookingDocuments($identifier, $booking_id){
switch($identifier){
case 'registration':
$files = BookingDocument::where('booking_id', $booking_id)->where('identifier', 'registration')->get();
break;
case 'confirmation':
$files = BookingDocument::where('booking_id', $booking_id)->where('identifier', 'confirmation')->get();
break;
case 'storno':
$files = BookingDocument::where('booking_id', $booking_id)->where('identifier', 'storno')->get();
break;
case 'coupon':
$files = BookingDocument::where('booking_id', $booking_id)->where('identifier', 'coupon')->get();
break;
case 'voucher':
$files = BookingDocument::where('booking_id', $booking_id)->where('identifier', 'voucher')->get();
break;
case 'voucher_agency':
$files = BookingDocument::where('booking_id', $booking_id)->where('identifier', 'voucher_agency')->get();
break;
default:
$files = null;
}
return $files;
}
public static function getV2BookingDocuments($identifier, $booking){
switch($identifier){
case 'registration':
$files = $booking->booking_applications;
break;
case 'confirmation':
$files = $booking->booking_confirmations;
break;
case 'storno':
$files = $booking->booking_stornos;
break;
case 'coupon':
$files = $booking->coupons;
break;
case 'voucher':
$files = $booking->booking_vouchers;
break;
case 'voucher_agency':
$files = $booking->booking_voucher_agencys;
break;
default:
$files = null;
}
return $files;
}
private static function makeHTMLTable($files, $identifier, $version){
$ret = "";
foreach($files as $file){
;
if($version === 'v2'){
$file_details = self::getV2FileDetails($file, $identifier);
}
if($version === 'v3'){
$file_details = self::getV2FileDetails($file, $identifier);
}
if(isset($file_details)){
$ret .= "<tr>";
$ret .= "<th scope='row'>".self::getFilesCount()."</th>";
$ret .= "<td>";
$ret .= "<a href='".route('customer_file_show', [$identifier, $file->id])."' target='_blank' class='badge badge-md badge-".$file_details->color."'>";
$ret .= "<i class='fa fa-file-pdf mr-1'></i> ".$file_details->name;
$ret .= "</a>";
$ret .= "</td>";
$ret .= "<td>".$file_details->cell."</td>";
$ret .= "<td>".$file_details->date."</td>";
$ret .= "<td>";
$ret .= "<a href='".route('customer_file_show', [$identifier, $file->id, true])."' class='btn btn-xs btn-default' title='Download' data-placement='left' rel='tooltip'>";
$ret .= "<i class='fa fa-download'></i>";
$ret .= "</a>";
$ret .= "</td>";
$ret .= "</tr>";
}
}
return $ret;
}
private static function getV3FileDetails($file, $identifier){
$ret = new \stdClass();
switch($identifier){
case 'registration':
$ret->name = "Reiseanmeldung";
$ret->color = "primary";
$ret->cell = "Reise | Gesamtpreis: ".\App\Services\Util::_number_format($file->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'confirmation':
$ret->name = "Reisebestätigung";
$ret->color = "success";
$ret->cell = "Reise | Gesamtpreis: ".\App\Services\Util::_number_format($file->total)." &euro; <br>
Anzahlung: ".\App\Services\Util::_number_format($file->deposit)." &euro; <br>
Restzahlung: ".\App\Services\Util::_number_format($file->final_payment)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'storno':
$ret->name = "Stornobestätigung";
$ret->color = "danger";
$ret->cell = "Storno | Betrag: ".\App\Services\Util::_number_format($file->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'coupon':
$ret->name = "Gutschein ".$file->number;
$ret->color = "danger";
$ret->cell = "Gutschein | Wert: ".\App\Services\Util::_number_format($file->value)." &euro; |
bis: ".\App\Services\Util::_format_date($file->valid_date, 'date')." |
".(($file->is_redeemed) ? '<i class="fa fa-check-circle text-success"></i> '.\App\Services\Util::_format_date($file->redeem_date, 'date') : '<i class="fa fa-times-circle text-danger"></i>')."";
$ret->date = \App\Services\Util::_format_date($file->issue_date, 'date');
break;
case 'voucher':
$ret->name = " Voucher ID ".$file->id;
$ret->color = "dark";
$ret->cell = " Voucher für den Kunden";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'voucher_agency':
$ret->name = "Voucher-Agentur ID ".$file->id;
$ret->color = "dark";
$ret->cell = "Voucher für die Agentur";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
default:
$ret->name = "";
$ret->color = "";
$ret->cell = "";
$ret->date = "";
}
return $ret;
return $ret;
}
private static function getV2FileDetails($file, $identifier){
$ret = new \stdClass();
switch($identifier){
case 'registration':
$ret->name = "Reiseanmeldung";
$ret->color = "primary";
$ret->cell = "Reise | Gesamtpreis: ".\App\Services\Util::_number_format($file->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'confirmation':
$ret->name = "Reisebestätigung";
$ret->color = "success";
$ret->cell = "Reise | Gesamtpreis: ".\App\Services\Util::_number_format($file->total)." &euro; <br>
Anzahlung: ".\App\Services\Util::_number_format($file->deposit)." &euro; <br>
Restzahlung: ".\App\Services\Util::_number_format($file->final_payment)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'storno':
$ret->name = "Stornobestätigung";
$ret->color = "danger";
$ret->cell = "Storno | Betrag: ".\App\Services\Util::_number_format($file->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'coupon':
$ret->name = "Gutschein ".$file->number;
$ret->color = "danger";
$ret->cell = "Gutschein | Wert: ".\App\Services\Util::_number_format($file->value)." &euro; |
bis: ".\App\Services\Util::_format_date($file->valid_date, 'date')." |
".(($file->is_redeemed) ? '<i class="fa fa-check-circle text-success"></i> '.\App\Services\Util::_format_date($file->redeem_date, 'date') : '<i class="fa fa-times-circle text-danger"></i>')."";
$ret->date = \App\Services\Util::_format_date($file->issue_date, 'date');
break;
case 'voucher':
$ret->name = " Voucher ID ".$file->id;
$ret->color = "dark";
$ret->cell = " Voucher für den Kunden";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'voucher_agency':
$ret->name = "Voucher-Agentur ID ".$file->id;
$ret->color = "dark";
$ret->cell = "Voucher für die Agentur";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
default:
$ret->name = "";
$ret->color = "";
$ret->cell = "";
$ret->date = "";
}
return $ret;
}
}

View file

@ -0,0 +1,313 @@
<?php
namespace App\Helper;
use App\Models\Booking;
use App\Models\BookingDocument as BookingDocumentModel;
class BookingDocument
{
private static $files_count = 0;
public static function showButton($identifier, Booking $booking){
switch($identifier){
case 'registration':
return $booking->price > 0 ? true : false;
break;
case 'confirmation':
return $booking->hasDocument('registration') > 0 ? true : false;
break;
case 'storno':
return $booking->hasDocument('confirmation') > 0 ? true : false;
break;
case 'coupon':
return $booking->hasDocument('confirmation') > 0 ? true : false;
case 'voucher':
return $booking->hasDocument('confirmation') > 0 ? true : false;
case 'voucher_agency':
return $booking->hasDocument('confirmation') > 0 ? true : false;
}
return false;
}
/*
functions to make the html table for the booking documents
*/
public static function getFilesCount(){
return self::$files_count++;
}
public static function getBookingDocumentsHTMLTable($identifier, Booking $booking, $look = 'show'){
$ret = "";
$files = self::getBookingDocuments($identifier, $booking->id);
if($files && $files->count() > 0){
$ret .= self::makeHTMLTable($files, $identifier, 'v3', $look);
}
$files = self::getV2BookingDocuments($identifier, $booking);
if($files && $files->count() > 0){
$ret .= self::makeHTMLTable($files, $identifier, 'v2', $look);
}
return $ret;
}
public static function getBookingDocuments($identifier, $booking_id){
switch($identifier){
case 'registration':
$files = BookingDocumentModel::where('booking_id', $booking_id)->where('identifier', 'registration')->get();
break;
case 'confirmation':
$files = BookingDocumentModel::where('booking_id', $booking_id)->where('identifier', 'confirmation')->get();
break;
case 'storno':
$files = null; //BookingDocumentModel::where('booking_id', $booking_id)->where('identifier', 'storno')->get();
break;
case 'coupon':
$files = null; //BookingDocumentModel::where('booking_id', $booking_id)->where('identifier', 'coupon')->get();
break;
case 'voucher':
$files = BookingDocumentModel::where('booking_id', $booking_id)->where('identifier', 'voucher')->get();
break;
case 'voucher_agency':
$files = BookingDocumentModel::where('booking_id', $booking_id)->where('identifier', 'voucher_agency')->get();
break;
default:
$files = null;
}
return $files;
}
public static function getV2BookingDocuments($identifier, Booking $booking){
switch($identifier){
case 'registration':
$files = $booking->booking_applications;
break;
case 'confirmation':
$files = $booking->booking_confirmations;
break;
case 'storno':
$files = $booking->booking_stornos;
break;
case 'coupon':
$files = $booking->coupons;
break;
case 'voucher':
$files = $booking->booking_vouchers;
break;
case 'voucher_agency':
$files = $booking->booking_voucher_agencys;
break;
default:
$files = null;
}
return $files;
}
private static function makeHTMLTable($files, $identifier, $version, $look){
$ret = "";
foreach($files as $file){
;
if($version === 'v2'){
$file_details = self::getV2FileDetails($file, $identifier, $look);
}
if($version === 'v3'){
$file_details = self::getV3FileDetails($file, $identifier, $look);
}
if(isset($file_details)){
$ret .= "<tr>";
$ret .= "<th scope='row'>".self::getFilesCount()."</th>";
$ret .= "<td>";
$ret .= "<a href='".$file_details->route."' target='_blank' class='badge badge-md badge-".$file_details->color."'>";
$ret .= "<i class='fa fa-file-pdf mr-1 ".(($file_details->opacity) ? 'opacity-50' : '')."'></i> ".$file_details->name;
$ret .= "</a>";
$ret .= "</td>";
$ret .= "<td>".$file_details->cell."</td>";
$ret .= "<td>".$file_details->date."</td>";
$ret .= "<td>";
if($look === 'show'){
$ret .= "<a href='".$file_details->donwload."' class='btn btn-xs btn-default' title='Download' data-placement='left' rel='tooltip'>";
$ret .= "<i class='fa fa-download'></i>";
$ret .= "</a>";
}
if($look === 'mail'){
$ret .= "<button data-target='".$file_details->route."' data-name='".$file_details->name.".pdf' class='btn btn-xs btn-primary add-file-to-attachment'";
$ret .= " title='als Anhang hinzufügen' data-placement='left' rel='tooltip'>";
$ret .= "<i class='fa fa-cloud-download-alt'></i>";
$ret .= "</button>";
}
$ret .= "</td>";
$ret .= "</tr>";
}
}
return $ret;
}
private static function getV3FileDetails($file, $identifier, $look){
$ret = new \stdClass();
switch($identifier){
case 'registration':
$ret->name = "Buchnungsauftrag ".$file->data->number;
$ret->color = "primary";
$ret->cell = self::getCellLabel($look, 'GP').": ".\App\Services\Util::_number_format((float) $file->data->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->data->date, 'date');
break;
case 'confirmation':
$ret->name = "Reisebestätigung ".$file->data->number;
$ret->color = "success";
$ret->cell = self::getCellLabel($look, 'GP').": ".\App\Services\Util::_number_format($file->data->total)." &euro; <br>
".self::getCellLabel($look, 'AZ').": ".\App\Services\Util::_number_format($file->data->deposit)." &euro; <br>
".self::getCellLabel($look, 'RZ').": ".\App\Services\Util::_number_format($file->data->final_payment)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->data->date, 'date');
break;
case 'storno':
$ret->name = "Stornobestätigung ".$file->data->number;
$ret->color = "danger";
$ret->cell = self::getCellLabel($look, 'SB').": ".\App\Services\Util::_number_format($file->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->data->date, 'date');
break;
case 'coupon':
$ret->name = "Gutschein ".$file->number;
$ret->color = "warning";
$ret->cell = self::getCellLabel($look, 'GW').": ".\App\Services\Util::_number_format($file->value)." &euro; |
bis: ".\App\Services\Util::_format_date($file->valid_date, 'date')." |
".(($file->is_redeemed) ? '<i class="fa fa-check-circle text-success"></i> '.\App\Services\Util::_format_date($file->redeem_date, 'date') : '<i class="fa fa-times-circle text-danger"></i>')."";
$ret->date = \App\Services\Util::_format_date($file->issue_date, 'date');
break;
case 'voucher':
$ret->name = " Voucher ".$file->data->number;
$ret->color = "dark";
$ret->cell = self::getCellLabel($look, 'VC');
$ret->date = \App\Services\Util::_format_date($file->data->date, 'date');
break;
case 'voucher_agency':
$ret->name = "Voucher-Agentur ".$file->data->number;
$ret->color = "dark";
$ret->cell = self::getCellLabel($look, 'VA');
$ret->date = \App\Services\Util::_format_date($file->data->date, 'date');
break;
default:
$ret->name = "";
$ret->color = "";
$ret->cell = "";
$ret->date = "";
}
$ret->route = $file->getURL('file');
$ret->donwload = $file->getURL('download');
$ret->opacity = false;
return $ret;
}
private static function getV2FileDetails($file, $identifier, $look){
$ret = new \stdClass();
switch($identifier){
case 'registration':
$ret->name = "Reiseanmeldung";
$ret->color = "primary";
$ret->cell = self::getCellLabel($look, 'GP').": ".\App\Services\Util::_number_format($file->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'confirmation':
$ret->name = "Reisebestätigung";
$ret->color = "success";
$ret->cell = self::getCellLabel($look, 'GP').": ".\App\Services\Util::_number_format($file->total)." &euro; <br>
".self::getCellLabel($look, 'AZ').": ".\App\Services\Util::_number_format($file->deposit)." &euro; <br>
".self::getCellLabel($look, 'RZ').": ".\App\Services\Util::_number_format($file->final_payment)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'storno':
$ret->name = "Stornobestätigung";
$ret->color = "danger";
$ret->cell = self::getCellLabel($look, 'SB').": ".\App\Services\Util::_number_format($file->total)." &euro;";
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
if($file->booking_document){
$ret->name .= " ".$file->booking_document->data->number;
$ret->cell = self::getCellLabel($look, 'SB').": ".\App\Services\Util::_number_format($file->storno)." &euro;";
$ret->route = $file->booking_document->getURL('file');
$ret->donwload = $file->booking_document->getURL('download');
$ret->opacity = false;
return $ret;
}
break;
case 'coupon':
$ret->name = "Gutschein ".$file->number;
$ret->color = "warning";
$ret->cell = self::getCellLabel($look, 'GW').": ".\App\Services\Util::_number_format($file->value)." &euro; |
bis: ".\App\Services\Util::_format_date($file->valid_date, 'date')." |
".(($file->is_redeemed) ? '<i class="fa fa-check-circle text-success"></i> '.\App\Services\Util::_format_date($file->redeem_date, 'date') : '<i class="fa fa-times-circle text-danger"></i>')."";
$ret->date = \App\Services\Util::_format_date($file->issue_date, 'date');
if($file->booking_document){
$ret->route = $file->booking_document->getURL('file');
$ret->donwload = $file->booking_document->getURL('download');
$ret->opacity = false;
return $ret;
}
break;
case 'voucher':
$ret->name = " Voucher ID ".$file->id;
$ret->color = "dark";
$ret->cell = self::getCellLabel($look, 'VC');
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
case 'voucher_agency':
$ret->name = "Voucher-Agentur ID ".$file->id;
$ret->color = "dark";
$ret->cell = self::getCellLabel($look, 'VA');
$ret->date = \App\Services\Util::_format_date($file->updated_at, 'date');
break;
default:
$ret->name = "";
$ret->color = "";
$ret->cell = "";
$ret->date = "";
}
$ret->route = route('customer_file_show', [$identifier, $file->id]);
$ret->donwload = route('customer_file_show', [$identifier, $file->id, true]);
$ret->opacity = true;
return $ret;
}
public static function getCellLabel($look, $identifier){
switch($identifier){
case 'GP':
return $look === 'mail' ? 'GP' : 'Reise | Gesamtpreis';
break;
case 'AZ':
return $look === 'mail' ? 'AZ' : 'Anzahlung';
break;
case 'RZ':
return $look === 'mail' ? 'RZ' : 'Restzahlung';
break;
case 'SB':
return $look === 'mail' ? 'GB' : 'Storno | Betrag';
break;
case 'GW':
return $look === 'mail' ? 'W' : 'Gutschein | Wert';
break;
case 'VC':
return $look === 'mail' ? 'für Kunden' : 'Voucher für den Kunden';
break;
case 'VA':
return $look === 'mail' ? 'für Agentur' : 'Voucher für die Agentur';
break;
}
}
}

597
app/Helper/HTMLHelper.php Normal file
View file

@ -0,0 +1,597 @@
<?php
namespace App\Helper;
use App\Models\Draft;
use App\Models\Airline;
use App\Models\CMSAuthor;
use App\Models\DraftType;
use App\Models\Insurance;
use App\Models\CMSContent;
use App\Models\TravelUser;
use App\Models\FewoLodging;
use App\Models\TravelClass;
use App\Models\TravelGuide;
use App\Models\TravelPlace;
use App\Models\IQTravelItem;
use App\Models\IQTravelGroup;
use App\Models\TravelCompany;
use App\Models\TravelCountry;
use App\Models\TravelProgram;
use App\Models\TravelNationality;
use App\Models\TravelBookingFewoChannel;
class HTMLHelper
{
private static $months = [
1 => 'Januar',
2 => 'Februar',
3 => 'März',
4 => 'April',
5 => 'Mai',
6 => 'Juni',
7 => 'Juli',
8 => 'August',
9 => 'September',
10 => 'Oktober',
11 => 'November',
12 => 'Dezember',
];
private static $days = [
0 => 'Sonntag',
1 => 'Montag',
2 => 'Dienstag',
3 => 'Mittwoch',
4 => 'Donnerstag',
5 => 'Freitag',
6 => 'Samstag',
];
private static $shortDays = [
0 => 'So',
1 => 'Mo',
2 => 'Di',
3 => 'Mi',
4 => 'Do',
5 => 'Fr',
6 => 'Sa',
];
public static $de_days = [
1 => 'Montag',
2 => 'Dienstag',
3 => 'Mittwoch',
4 => 'Donnerstag',
5 => 'Freitag',
6 => 'Samstag',
7 => 'Sonntag',
];
private static $roles = [
0 => 'Kunde',
1 => 'Admin',
2 => 'SuperAdmin',
3 => 'SysAdmin',
];
private static $salutation = [
1 => 'Herr',
2 => 'Frau',
3 => 'Divers/keine Anrede',
4 => 'Firma',
];
public static function getMonth($i){
return self::$months[$i];
}
public static function getDay($i){
return self::$days[$i];
}
public static function getShortDay($i){
return self::$shortDays[$i];
}
public static function getDeDays(){
return self::$de_days;
}
public static function getDeDay($i){
return self::$de_days[$i];
}
public static function getRoleLabel($role_id = 0, $pre = "", $post = ""){
return '<span class="badge badge-pill '.self::getLable($role_id).'">'.$pre.self::$roles[$role_id].$post.'</span>';
}
public static function getLable($id){
switch ($id) {
case 0:
return 'badge-default';
break;
case 1:
return 'badge-warning';
break;
case 2:
return 'badge-primary';
break;
case 3:
return 'badge-success';
break;
}
}
public static function getSelectedOptions($values, $id = null, $empty = false){
$ret = "";
if($empty){
$ret .= '<option value="">'.$empty.'</option>\n';
}
foreach ($values as $key => $value){
$attr = ($key == $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$key.'" '.$attr.'>'.$value.'</option>\n';
}
return $ret;
}
public static function getActiveIcon($active){
return $active ? '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
}
public static function getRolesOptions($id = 0){
$ret = "";
foreach (self::$roles as $role_id => $value){
$attr = ($role_id == $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$role_id.'" '.$attr.'>'.$value.'</option>\n';
}
return $ret;
}
public static function getSalutationOptions($id){
$ret = "";
foreach (self::$salutation as $s_id => $value){
$attr = ($s_id == $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$s_id.'" '.$attr.'>'.$value.'</option>\n';
}
return $ret;
}
public static function getYearSelectOptions(){
$start = date("Y", strtotime("-5 years", time()));
$end = date("Y", strtotime("+1 years", time()));
$values = range($start, $end);
$now = date("Y", time());
$ret = "";
foreach ($values as $value){
$attr = ($value == $now) ? 'selected="selected"' : '';
$ret .= '<option value="'.$value.'" '.$attr.'>'.$value.'</option>\n';
}
return $ret;
}
public static function getDraftTypes($setId = false){
$options = DraftType::all()->sortByDesc('id')->sortByDesc('pos');
$ret = "";
foreach ($options as $option){
$attr = ($option->id == $setId) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function createTimeRange($start = '0:00', $end = "23:30", $interval = '30 mins'){
$start_time = strtotime($start);
$end_time = strtotime($end);
$format = 'G:i';
$current = time();
$add_time = strtotime('+'.$interval, $current);
$diff = $add_time - $current;
$times = [];
while ($start_time < $end_time){
$times[] = date($format, $start_time);
$start_time += $diff;
}
$times[] = date($format, $start_time);
return $times;
}
public static function getTimeInSteps($id = false){
$times = self::createTimeRange();
$ret = '';
foreach ($times as $item){
$attr = ($item === $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$item.'" '.$attr.'>'.$item.'</option>\n';
}
return $ret;
}
public static function getRangeOptions($id = false, $range = 30, $name = "", $start=1){
$range = range($start, $range);
$ret = "";
foreach ($range as $item){
$attr = ($item === $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$item.'" '.$attr.'>'.$item.$name.'</option>\n';
}
return $ret;
}
public static function getDraftOptions($setId = false){
$options = Draft::where('active', 1)->orderBy('id', 'DESC')->get();
$ret = "";
foreach ($options as $option){
$attr = ($option->id === $setId) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function getAuthorOptions($setId = false){
$options = CMSAuthor::orderBy('id', "DESC")->get();
$ret = "";
foreach ($options as $option){
$attr = ($option->id === $setId) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function getCMSContentOptions($identifier, $setId = false, $empty=false){
$options = CMSContent::where('identifier', '=', $identifier)->get()->sortBy('pos');
$ret = "";
if($empty){
$ret = '<option value="0">Keine Vorlage</option>\n';
}
foreach ($options as $option){
$attr = ($option->id === intval($setId)) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function getTravelClassOptions($programId = false, $setId = false){
$options = TravelClass::where('program_id', $programId)->get();
$ret = '<option value="">alle Kategorien</option>\n';
foreach ($options as $option){
$attr = ($option->id === $setId) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function getTravelCountriesOptions($countryId = false, $crm = true){
$checked = [];
if($countryId){
!is_array($countryId) ? $checked = array($countryId) : $checked = $countryId;
}
$options = TravelCountry::where('active_backend',1)->get();
$ret = '';
foreach ($options as $option){
$id = $crm ? $option->crm_id : $option->id;
$attr = (in_array($id, $checked)) ? 'selected="selected"' : '';
$ret .= '<option value="'.$id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function getTravelUserOptions($id = false, $order = "ASC", $empty=false){
$options = TravelUser::orderBy('id', $order)->get();
$ret = '';
if($empty){
$ret = '<option value="">Bitte wählen</option>\n';
}
foreach ($options as $option){
$attr = ($option->id === $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->first_name.' '.$option->last_name.' | '.$option->email.' ('.$option->id.')</option>\n';
}
return $ret;
}
public static function getTravelPlaceOptions($id = false, $order = "ASC", $empty=false){
$options = TravelPlace::where('active',1)->orderBy('id', $order)->get();
$ret = '';
if($empty){
$ret = '<option value="">Bitte wählen</option>\n';
}
foreach ($options as $option){
$attr = ($option->id === $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function getIQTravelItemsOptions($id = false, $order = "ASC", $empty=false){
$options = IQTravelItem::where('active',1)->orderBy('id', $order)->get();
$ret = '';
if($empty){
$ret = '<option value="">Bitte wählen</option>\n';
}
foreach ($options as $option){
$attr = ($option->id === $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function getIQTravelGroupsOptions($id = false, $order = "ASC", $empty=false){
$options = IQTravelGroup::where('active',1)->orderBy('id', $order)->get();
$ret = '';
if($empty){
$ret = '<option value="">Bitte wählen</option>\n';
}
foreach ($options as $option){
$attr = ($option->id === $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function getCustomerMailDirsOptions(CMSContent $customer_mail_dir, $checked = []){
//$checked = [];
$model = $customer_mail_dir->getArrayContent('model');
switch ($model){
case 'TravelCountry':
$options = \App\Models\Sym\TravelCountry::where('active_backend',1)->get();
break;
case 'Airline':
$options = Airline::where('name_full', 'like', '%Xemail%')->get();
break;
case 'Insurance':
$options = Insurance::where('active',1)->get();
break;
case 'TravelCompany':
$options = TravelCompany::where('active',1)->get();
break;
default:
return '';
}
$ret = '';
foreach ($options as $option){
$attr = (in_array($option->id, $checked)) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function getFewoLodgingOptions($id = false){
$options = FewoLodging::all();
$ret = '';
foreach ($options as $option){
$attr = ($option->id === $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function getTravelBookingFewoChannelOptions($id = false){
$options = TravelBookingFewoChannel::all();
$ret = '';
foreach ($options as $option){
$attr = ($option->id === $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function getTravelNationalityOptions($id = false){
$options = TravelNationality::where('active',1)->get();
$ret = '';
foreach ($options as $option){
$attr = ($option->id === $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function getTravelGuideOptions($id = false){
$options = TravelGuide::where('active',1)->get();
$ret = '<option value="">keinen Inhalt</option>\n';
foreach ($options as $option){
$attr = ($option->id === $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
}
return $ret;
}
public static function getWeekdaysOptions($programId = false, $weekdays = []){
if($programId){
$tp = TravelProgram::findOrFail($programId);
$options = explode(',', $tp->weekdays);
}else{
$options = range(0, 6);
}
$ret = '<option value="">alle Wochentage</option>\n';
foreach ($options as $option){
$attr = (in_array($option, $weekdays)) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option.'" '.$attr.'>'.self::getDay($option).'</option>\n';
}
return $ret;
}
public static function getWeekdaysString($weekdays = [], $short = false){
$ret = "";
if(is_array($weekdays) && count($weekdays)){
foreach($weekdays as $weekday){
if($weekday !== NULL){
if($short){
$ret .= self::getShortDay($weekday).', ';
}else{
$ret .= self::getDay($weekday).', ';
}
}
}
if($ret != ""){
return rtrim($ret, ", ");
}
}
return "alle Wochentage";
}
public static function getParentBy($obj = NULL, $options, $empty=true){
$ret = "";
$setId = 0;
if($obj){
$setId = $obj->id;
}
if($empty){
// $ret .= '<option value="">Main (No-Parent)</option>\n';
}
foreach ($options as $id => $name){
$attr = ($id === $setId) ? 'selected="selected"' : '';
$ret .= '<option value="'.$id.'" '.$attr.'>'.$name.'</option>\n';
}
return $ret;
}
public static function filterHTML($html, $arg = [], $save = false){
$dom = new \DOMDocument('1.0', 'UTF-8');
//@$dom->loadHTML();
@$dom->loadHTML( mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
if(isset($arg['src'])){
if(in_array('addHost', $arg['src'])){
$images = $dom->getElementsByTagName('img');
foreach ($images as $image) {
$src = $image->getAttribute('src');
if(strpos($src, 'http') === false){
$host = config('app.url_stern');
if(strpos($src, $host) === false){
$src = $host."/".ltrim($src, '/');
}
$image->setAttribute('src', $src);
}
}
}
if(in_array('removeHost', $arg['src'])){
$images = $dom->getElementsByTagName('img');
foreach ($images as $image) {
$src = $image->getAttribute('src');
$host = config('app.url_stern');
if(strpos($src, $host) !== false){
$src = str_replace($host, '', $src);
}
$image->setAttribute('src', $src);
}
}
}
$html = $dom->saveHTML();
$html = preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', $html);
if($save){
return mb_convert_encoding($html, "UTF-8", "HTML-ENTITIES");
}
return $html;
}
/*
public static function getIndustrySectorsWithoutParents($id = false, $sameId = false, $all = true){
$values = IndustrySector::where('parent_id', null)->get();
$ret = "";
if($all){
$ret .= '<option value="">'.__('no').'</option>\n';
}
foreach ($values as $value){
if($sameId == $value->id){
continue;
}
$attr = ($value->id == $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->name.'</option>\n';
}
return $ret;
}
public static function getContriesWithMore($id, $all=true){#
$values = Country::all();
$counter = 1;
$ret = "";
if($all){
$ret .= '<option value="">'.__('please select').'</option>\n';
}
foreach ($values as $value){
if( $counter == 7){
$ret .= '<optgroup label="'.__('further countrie').'">';
}
$attr = ($value->id == $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->getLocated().'</option>\n';
$counter ++;
}
$ret .= '</optgroup>';
return $ret;
}
public static function getContriesCodes($id, $all=true){#
$values = Country::all();
$counter = 1;
$ret = "";
if($all){
$ret .= '<option value="">'.__('please select').'</option>\n';
}
foreach ($values as $value){
if(!$value->phone) continue;
if( $counter == 7){
$ret .= '<optgroup label="'.__('further countrie').'">';
}
$attr = ($value->id == $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->phone.'('.$value->getLocated().')</option>\n';
$counter ++;
}
$ret .= '</optgroup>';
return $ret;
}
public static function getSalutation($id){
$values = array('mr' => __('MR'), 'ms' => __('MS'));
$ret = "";
$ret .= '<option value="">'.__('please select').'</option>\n';
foreach ($values as $key => $value){
$attr = ($key == $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$key.'" '.$attr.'>'.$value.'</option>\n';
}
return $ret;
}
public static function getSalutationLang($id){
$values = array('mr' => __('MR'), 'ms' => __('MS'));
return (!empty($values[$id]) ? $values[$id] : '');
}
*/
}

191
app/Helper/TreeHTML.php Normal file
View file

@ -0,0 +1,191 @@
<?php
namespace App\Helper;
use App\Models\IQContentSiteField;
use App\Models\IQContentTree;
use App\Models\IQContentTreeNode;
class TreeHTML
{
private static $uri = null;
/**
* @param $feature
* @return string
*/
/*public static function makeAttrArray($array = array())
{
if(is_array($array)){
return htmlspecialchars(json_encode($array), ENT_QUOTES, 'UTF-8');
}
return "";
}*/
public static function makeNestableList(IQContentTree $iq_content_tree, $tree_node_id, $lvl = 0, $parent_id = false)
{
if ($parent_id) {
//where('active', true)
$tree_nodes = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl)->where('parent_id', $parent_id)->orderBy('pos', 'ASC')->get();
} else {
$tree_nodes = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl)->orderBy('pos', 'ASC')->get();
}
$out = "";
foreach ($tree_nodes as $node) {
$children = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl + 1)->where('parent_id', $node->id)->count();
$out .= '<li class="dd-item dd-custom-drag-handle" data-id="' . $node->id . '">
<div class="dd-handle">
<span class="ion ion-md-expand text-secondary"></span>
</div>
<div class="dd-content">
<a href="' . route('iq_content_tree_detail', [$iq_content_tree->id, $node->id]) . '">
<div class="dd-content-link">
' . ($tree_node_id == $node->id ? '<strong> <i class="fa fa-chevron-right"></i> ' : '').$node->name.($tree_node_id == $node->id ? '</strong>' : '') . '
</div>
</a>
<div class="float-right">
' . ($node->iq_content_sites->count() ? '<span class="text-light">('.$node->iq_content_sites->count().')</span>' : '') . '
<a href="#" class="iq_update_data_load" data-action="node-set-active" data-target="self" data-url="'.route('iq_content_tree_detail', [$iq_content_tree->id, $node->id]).'">' . ($node->active ? '
<i class="fa fa-eye text-success"></i>' : '<i class="fa fa-eye-slash text-danger"></i>') . '
</a>
</div>
</div>';
if ($children) {
$out .= self::makeNestableList($iq_content_tree, $tree_node_id, $lvl + 1, $node->id);
}
$out .= '</li>';
}
return '<ol class="dd-list">' . $out . '</ol>';
}
public static function getUri()
{
if (strpos($_SERVER['REQUEST_URI'], "/") !== false) {
$uri = explode("/", $_SERVER['REQUEST_URI']);
$uri = array_filter($uri);
return $uri;
}
return false;
}
public static function makeFrontendList(IQContentTree $iq_content_tree, $lvl = 0, $parent_id = false, $url = "", $categories = "")
{
if (self::$uri === null) {
self::$uri = self::getUri();
}
$link = false;
if (!empty(self::$uri[$lvl + 2])) {
$link = (self::$uri[$lvl + 2]);
}
if ($parent_id) {
//where('active', true)
$tree_nodes = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl)->where('active', true)->where('parent_id', $parent_id)->orderBy('pos', 'ASC')->get();
} else {
$url = "/" . $iq_content_tree->identifier . "/";
$tree_nodes = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl)->where('active', true)->orderBy('pos', 'ASC')->get();
}
$out = "";
$class = (!$link) ? 'active' : '';
foreach ($tree_nodes as $node) {
if($node->settings['show_in_navi'] == 'off'){
continue;
}
$children = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl + 1)->where('active', true)->where('parent_id', $node->id)->count();
$class = ($link == $node->identifier) ? 'active' : '';
if ($lvl == 0) {
$out .= '<li class="nav-item mega-dropdown ' . $class . '">
<a class="nav-link dropdown-toggle px-md-3 px-lg-4" href="' . url($url . $node->identifier) . '" data-toggle="mega-dropdown" data-trigger="hover">' . $node->name . '</a>
<div class="dropdown-menu p-0 mt-2 overflow-hidden">
<div class="row no-gutters row-bordered">
<div class="col-12 p-4">
<h6 class="small font-weight-bold text-expanded text-uppercase">'.$categories.'</h6>';
} else {
/*
$site_field = IQContentSiteField::findSiteField($node, 'main-navi', 'menu-navi-image');
$img_src = (isset($site_field->content) ? $site_field->content : '/images/navi_images-assets/titelbild.jpg');
$out .= ' <a href="' .url($url . $node->identifier). '" class="media align-items-center ui-bordered text-body py-2 px-2 mb-2 img-thumbnail-shadow ' . $class . '">
<img src="'.$img_src.'" alt="" class="d-block ui-w-60">
<span class="media-body font-weight-semibold ml-2">' . ($link == $node->identifier ? '<strong>' : '') . $node->name . '</span>' . ($link == $node->identifier ? '</strong>' : '') . '
</a>';
*/
}
if ($children && $lvl == 0) {
$out .= self::makeFrontendList($iq_content_tree, $lvl + 1, $node->id, $url . $node->identifier . "/", $categories);
}
if ($lvl == 0) {
$out .= ' </div>
</div>
</div>
</li>';
}
}
return $out;
}
public static function makeFrontendListFooter(IQContentTree $iq_content_tree, $lvl = 0, $parent_id = false, $url = "")
{
if (self::$uri === null) {
self::$uri = self::getUri();
}
$link = false;
if (!empty(self::$uri[$lvl + 2])) {
$link = (self::$uri[$lvl + 2]);
}
if ($parent_id) {
//where('active', true)
$tree_nodes = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl)->where('active', true)->where('parent_id', $parent_id)->orderBy('pos', 'ASC')->get();
} else {
$url = "/" . $iq_content_tree->identifier . "/";
$tree_nodes = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl)->where('active', true)->orderBy('pos', 'ASC')->get();
}
$out = "";
$class = (!$link) ? 'active' : '';
foreach ($tree_nodes as $node) {
if($node->settings['show_in_navi'] == 'off'){
continue;
}
$children = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl + 1)->where('active', true)->where('parent_id', $node->id)->count();
$class = ($link == $node->identifier) ? 'active' : '';
if ($lvl == 0) {
$out .= '<div class="col-12 col-sm-3 col-md pb-4 border-left-white">
<div class="footer-text small font-weight-bold mb-3 text-uppercase">' . $node->name . '</div>';
} else {
$out .= '<a href="' . url($url . $node->identifier) . '" class="footer-link d-block pb-2">' . ($link == $node->identifier ? '<strong>' : '') . $node->name . '</span>' . ($link == $node->identifier ? '</strong>' : '') . '</a>';
}
if ($children && $lvl == 0) {
$out .= self::makeFrontendListFooter($iq_content_tree, $lvl + 1, $node->id, $url . $node->identifier . "/");
}
if ($lvl == 0) {
$out .= '</div>';
}
}
return $out;
}
}