Files
bm/public_html/app/Traits/EventTrait.php
2025-09-24 13:26:28 +02:00

76 lines
2.4 KiB
PHP

<?php
namespace App\Traits;
use App\SingleSeat;
use Request;
trait EventTrait
{
protected function calcSeatMap($seat){
$singleSeats = $seat->singleSeats()->get();
$seats = array();
$highestX = 0; $highestY = 0;
foreach($singleSeats as $singleSeat){
$seats[$singleSeat->x][$singleSeat->y] = $singleSeat->category;
if($singleSeat->x > $highestX) $highestX = $singleSeat->x;
if($singleSeat->y > $highestY) $highestY = $singleSeat->y;
}
$ret = "";
for($i=1; $i<=$highestX; $i++){
for($j=1; $j<=$highestY; $j++){
if(isset($seats[$i][$j]))
$ret .= $seats[$i][$j];
else
$ret.="_";
}
$ret.="\n";
}
return($ret);
}
protected function seatAlreadyExists($seat, $x, $y){
return count($seat->singleSeats()->where("x","=",$x)->where("y","=", $y)->get()) > 0;
}
protected function updateSeatMap($seat)
{
$seatingUpdate = Request::all();
//insert new seats
$seatMap = $seatingUpdate["seatMap"];
$x = 0;
$y = 1;
for ($i=0; $i<strlen($seatMap); $i++) {
if($seatMap[$i] != "\r") {
if ($seatMap[$i] == "\n") {
$x = 0;
$y++;
//$i++;
} else {
$x++;
if (!$this->seatAlreadyExists($seat, $y, $x) && $seatMap[$i] != "_") {
$s = new SingleSeat;
$s->x = $y;
$s->y = $x;
$s->category = $seatMap[$i] . "";
$s->seat()->associate($seat);
$s->save();
}
}
}
}
}
protected function isSomeKindOfReservation($event){
$reservationType = $event->reservation()->first()->name; //e.g. "Ohne Sitzplatz", ...
return $reservationType == "Mit Platzwahl" || $reservationType == "Mit Tischwahl" || $reservationType == "Ohne Platzwahl";
}
protected function hasSeatMap($newEvent){
$reservationType = $newEvent->reservation()->first()->name; //e.g. "Ohne Sitzplatz", ...
return $reservationType == "Mit Platzwahl" || $reservationType == "Mit Tischwahl";
}
}