Sprache bei Mail; hinzufügen Spendenverordnung
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Mail\PreApplicationMail;
|
||||
use App\Models\ChaosEvents;
|
||||
use App\Models\PreApplications;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Log;
|
||||
@@ -14,6 +15,20 @@ use Nette\Utils\Random;
|
||||
|
||||
class PreApplicationController extends Controller
|
||||
{
|
||||
|
||||
private function generateReferenceNumber($eventId, $passportType, $firstName){
|
||||
$reference_number = null;
|
||||
|
||||
$ce = ChaosEvents::find($eventId);
|
||||
$free_reference_number = false;
|
||||
$counter = 1;
|
||||
while(!$free_reference_number){
|
||||
$reference_number = $ce->shortname . strtoupper($passportType) . '-' . strtoupper($firstName[0]) . Carbon::now()->format('ymd') . sprintf("%04d", $counter++);
|
||||
$free_reference_number = !PreApplications::where('reference_number', $reference_number)->exists();
|
||||
}
|
||||
return $reference_number;
|
||||
}
|
||||
|
||||
public function send(Request $request){
|
||||
$event = $request->input('district_region');
|
||||
|
||||
@@ -53,20 +68,13 @@ class PreApplicationController extends Controller
|
||||
//Log::debug('fn: ' . var_export($fn, true) . ' ln: ' . var_export($ln, true) . ' loc: ' . var_export($loc, true) . '');
|
||||
|
||||
if($fn && $ln && $loc){
|
||||
|
||||
$free_reference_number = false;
|
||||
while(!$free_reference_number){
|
||||
$reference_number = $ce->shortname . '-' . strtoupper($passport_type) . '-' . Random::generate(4, "0-9") . '-' . Random::generate(4, "0-9") . '-' . Random::generate(4, "0-9");
|
||||
$free_reference_number = !PreApplications::where('reference_number', $reference_number)->exists();
|
||||
}
|
||||
|
||||
try{
|
||||
$pa = new PreApplications();
|
||||
$pa->first_name = $first_name;
|
||||
$pa->last_name = $last_name;
|
||||
$pa->location = $location;
|
||||
$pa->passport_type = $passport_type;
|
||||
$pa->reference_number = $reference_number;
|
||||
$pa->reference_number = $this->generateReferenceNumber($event, $passport_type, $first_name);
|
||||
$pa->event_id = $event;
|
||||
$pa->email = $email;
|
||||
$pa->save();
|
||||
@@ -101,13 +109,7 @@ class PreApplicationController extends Controller
|
||||
$pa->event_id = $request->input('district_region');
|
||||
$pa->email = $request->input('mail');
|
||||
|
||||
$ce = ChaosEvents::find($pa->event_id);
|
||||
$free_reference_number = false;
|
||||
while(!$free_reference_number){
|
||||
$reference_number = $ce->shortname . '-' . strtoupper($pa->passport_type) . '-' . Random::generate(4, "0-9") . '-' . Random::generate(4, "0-9") . '-' . Random::generate(4, "0-9");
|
||||
$free_reference_number = !PreApplications::where('reference_number', $reference_number)->exists();
|
||||
}
|
||||
$pa->reference_number = $reference_number;
|
||||
$pa->reference_number = $this->generateReferenceNumber($request->input('district_region'), $request->input('passport_type'), $request->input('first_name'));
|
||||
|
||||
$pa->save();
|
||||
return ["messageStatus" => "success", "errorMessage" => ""];
|
||||
|
||||
@@ -9,19 +9,6 @@ use Illuminate\Support\Facades\Auth;
|
||||
class WebsiteController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setLang($_COOKIE['lang'] ?? 'de');
|
||||
}
|
||||
|
||||
private function setLang($lang)
|
||||
{
|
||||
if (!in_array($lang, ['de', 'en'])) {
|
||||
$lang = 'de';
|
||||
}
|
||||
|
||||
App::setLocale($lang);
|
||||
}
|
||||
|
||||
//
|
||||
public function index(Request $request)
|
||||
|
||||
28
app/Http/Middleware/SetLocale.php
Normal file
28
app/Http/Middleware/SetLocale.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SetLocale
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$lang = $request->cookie('lang', 'de');
|
||||
if (!in_array($lang, ['de', 'en'])) {
|
||||
$lang = 'de';
|
||||
}
|
||||
|
||||
App::setLocale($lang);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ class PreApplicationMail extends Mailable
|
||||
public function __construct(protected App\Models\PreApplications $pa, protected string $lang = 'de')
|
||||
{
|
||||
//
|
||||
$this->locale($this->lang);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +40,6 @@ class PreApplicationMail extends Mailable
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
App::setLocale($this->lang);
|
||||
return new Content(
|
||||
view: 'mail.preapplication',
|
||||
with: ['pa' => $this->pa],
|
||||
@@ -53,13 +53,21 @@ class PreApplicationMail extends Mailable
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
$lang = match (App::getLocale()) {
|
||||
$langFb = match ($this->locale) {
|
||||
'de' => 'dk',
|
||||
'en' => 'ek',
|
||||
default => 'dk',
|
||||
};
|
||||
|
||||
$langDonation = match ($this->locale) {
|
||||
'de' => '',
|
||||
'en' => '_en',
|
||||
};
|
||||
|
||||
return [
|
||||
Attachment::fromPath(public_path('Dokumente/c3gov_fb5' . $lang . '.pdf'))
|
||||
Attachment::fromPath(public_path('Dokumente/c3gov_fb5' . $langFb . '.pdf'))
|
||||
->withMime('application/pdf'),
|
||||
Attachment::fromPath(public_path('Dokumente/C3GovSpGV' . $langDonation . '.pdf'))
|
||||
->withMime('application/pdf'),
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user