186 lines
5.9 KiB
PHP
186 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\EventControllerHelper;
|
|
|
|
use App\Concession;
|
|
use App\CulturecardTicket;
|
|
use App\Event;
|
|
use App\Order;
|
|
use App\Paymentmethod;
|
|
use App\Seat;
|
|
use App\SingleSeat;
|
|
use DateInterval;
|
|
use DatePeriod;
|
|
use App\SingleSeatsUser;
|
|
use App\Traits\EventTrait;
|
|
use App\Traits\MoneyTrait;
|
|
use App\Traits\ReservationTrait;
|
|
use App\User;
|
|
use DateTime;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Cookie;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Request;
|
|
|
|
class EventStoreController {
|
|
use ReservationTrait;
|
|
use MoneyTrait;
|
|
use EventTrait;
|
|
|
|
private $request;
|
|
|
|
public function store()
|
|
{
|
|
$this->request = Request::all();
|
|
|
|
$this->fixCurrencyVariations();
|
|
|
|
if(!isset($this->request["end_date"])){
|
|
$this->request["end_date"] = $this->request["start_date"];
|
|
}
|
|
|
|
if(isset($this->request["payableWithCulturecard"])){
|
|
$this->request["payableWithCulturecard"] = 1;
|
|
}else{
|
|
$this->request["payableWithCulturecard"] = 0;
|
|
}
|
|
if(isset($this->request["hide_externally"])){
|
|
$this->request["hide_externally"] = 1;
|
|
}else{
|
|
$this->request["hide_externally"] = 0;
|
|
}
|
|
|
|
$newEvent = Event::create($this->request);
|
|
|
|
$newEvent->shorttext=$this->request["shorttext"];
|
|
$this->handleConcessions($newEvent, $this->request);
|
|
$newEvent->categories()->sync($this->request["cat"]);
|
|
$this->handleImageUpload($newEvent);
|
|
|
|
if($this->isSomeKindOfReservation($newEvent)){
|
|
$reservationType = $newEvent->reservation()->first()->name;
|
|
if($reservationType == "Mit Tischwahl"){
|
|
$dates = array('2025-06-20', '2025-06-21', '2025-06-27', '2025-06-28', '2025-07-04', '2025-07-05', '2025-07-06', '2025-07-11', '2025-07-12', '2025-07-18', '2025-07-19', '2025-07-20' );
|
|
//$dates = array('2025-12-21');
|
|
//$dates = array($this->request["start_date"]);
|
|
$newEvent->start_date = $dates[0];
|
|
$newEvent->end_date = end($dates);
|
|
$newEvent->save();
|
|
foreach ($dates as $day ){
|
|
$seat = new Seat;
|
|
$seat->date = $day;
|
|
$seat->event()->associate($newEvent);
|
|
$seat->save();
|
|
$this->updateSeatMapWithTables($seat);
|
|
}
|
|
}else{
|
|
$begin = new DateTime( $this->request["start_date"] );
|
|
$end = new DateTime( $this->request["end_date"] );
|
|
date_add($end, date_interval_create_from_date_string('1 day'));
|
|
|
|
$interval = DateInterval::createFromDateString('1 day');
|
|
$period = new DatePeriod($begin, $interval, $end);
|
|
foreach ($period as $dt ){
|
|
$day = $dt->format('Y-m-d');
|
|
$seat = new Seat;
|
|
$seat->date = $day;
|
|
$seat->event()->associate($newEvent);
|
|
$seat->save();
|
|
if($this->hasSeatMap($newEvent)){
|
|
$this->updateSeatMap($seat);
|
|
}else{
|
|
$this->updateSeatMapNoSeat($seat, $this->request["amountSeats"]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
\Session::flash('flash_message', 'Die Veranstaltung '.$newEvent["title"].' wurde erfolgreich erstellt.');
|
|
return redirect('admin/events');
|
|
}
|
|
|
|
private function handleConcessions($event, $data){
|
|
$names = $data["concessionNames"];
|
|
$percs = $data["concessionPercs"];
|
|
|
|
for($i=0; $i<count($names); $i++){
|
|
$name = $names[$i];
|
|
$perc = $percs[$i];
|
|
$concession = Concession::where('name', '=', $name)->where('perc', '=', $perc)->first();
|
|
if ($concession === null) {
|
|
$concession = new Concession();
|
|
$concession->name = $name;
|
|
$concession->perc = $perc;
|
|
$concession->save();
|
|
}
|
|
|
|
$event->concessions()->attach($concession->id);
|
|
}
|
|
}
|
|
|
|
private function fixCurrencyVariations(){
|
|
$this->fixCurrencyVariationsSingle("price_cat_a");
|
|
$this->fixCurrencyVariationsSingle("price_cat_b");
|
|
$this->fixCurrencyVariationsSingle("price_cat_c");
|
|
}
|
|
|
|
private function fixCurrencyVariationsSingle($priceCat){
|
|
if(isset($this->request[$priceCat])){
|
|
$this->request[$priceCat] = str_replace('.', '', $this->request[$priceCat]);
|
|
$this->request[$priceCat] = str_replace(',', '.', $this->request[$priceCat]);
|
|
$this->request[$priceCat] = str_replace('€', '', $this->request[$priceCat]);
|
|
}else{
|
|
$this->request[$priceCat] = "0";
|
|
}
|
|
}
|
|
|
|
private function handleImageUpload($newEvent){
|
|
$image = $this->request["cropped_image"];
|
|
$fileName = time()."_".$image->getClientOriginalName();
|
|
$image->move("imgs/events",$fileName);
|
|
$newEvent["image"] = $fileName;
|
|
$newEvent->save();
|
|
}
|
|
|
|
|
|
|
|
private function updateSeatMapNoSeat($seat, $amountSeats)
|
|
{
|
|
for($i=0; $i<$amountSeats; $i++){
|
|
$s = new SingleSeat;
|
|
$s->x = 1;
|
|
$s->y = $i+1;
|
|
$s->category = "s";
|
|
$s->seat()->associate($seat);
|
|
$s->save();
|
|
}
|
|
}
|
|
|
|
private function updateSeatMapWithTables($seat)
|
|
{
|
|
for($x = 1; $x <= 13; $x ++){
|
|
$cols = 16;
|
|
if ($x >= 12) {
|
|
$cols = 10;
|
|
}else if($x >= 11) {
|
|
$cols = 12;
|
|
}
|
|
for($y = 1; $y <= $cols; $y++){
|
|
$s = new SingleSeat;
|
|
$s->x = $x;
|
|
$s->y = $y;
|
|
if($x <= 5){
|
|
$s->category = 'b';
|
|
} else{
|
|
$s->category = 'a';
|
|
}
|
|
$s->seat()->associate($seat);
|
|
$s->save();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|