fix+add: seats + seat-chooser

This commit is contained in:
Didier Slof 2023-01-01 20:13:11 +01:00
parent 2c6745e812
commit b0cc5b5278
Signed by: didier
GPG key ID: 01E71F18AA4398E5
31 changed files with 808 additions and 115 deletions

View file

@ -29,5 +29,10 @@ class Address extends Model
return $this->belongsTo(User::class, 'user_id', 'id');
}
public function string()
{
return $this->address_street . ", " . $this->address_city . ", " . $this->address_state . " " . $this->address_zip . ", " . $this->address_country;
}
}

View file

@ -43,4 +43,29 @@ class Room extends Model
return $this->belongsTo(Cinema::class, 'cinema_id', 'cinema_id');
}
public function seatMatrix($showing_id = null)
{
$seats = $this->seats;
$matrix = [];
// first, create an empty matrix
for ($i = 0; $i < $this->room_rows-1; $i++) {
$matrix[$i] = [];
for ($j = 0; $j < $this->room_columns-1; $j++) {
$matrix[$i][$j] = null;
}
}
// then, fill it with the seats
foreach ($seats as $seat) {
$matrix[$seat->seat_row-1][$seat->seat_column-1] = [
'seat_id' => $seat->seat_id,
'seat_row' => $seat->seat_row,
'seat_column' => $seat->seat_column,
'seat_type' => $seat->seat_type,
'seat_linked_id' => $seat->seat_linked_id,
'reserved' => $showing_id ? $seat->isReserved($showing_id) : false,
];
}
return $matrix;
}
}

View file

@ -13,7 +13,8 @@ class Seat extends Model
protected $fillable = [
'seat_row',
'seat_number',
'seat_type', // enum('standard', 'wheelchair', 'loveseat')
'seat_type', // enum('standard', 'wheelchair', 'loveseat', 'not_available')
'seat_linked_id', // if this is a loveseat, this is the other seat
'room_id',
];
@ -27,28 +28,27 @@ class Seat extends Model
return $this->belongsTo(Room::class, 'room_id', 'room_id');
}
public function orders()
{
return $this->belongsToMany(Order::class, 'order_seats', 'seat_id', 'order_id');
}
public function tickets()
{
return $this->hasMany(Ticket::class, 'seat_id', 'seat_id');
}
public function linked_seat()
{
return $this->belongsTo(Seat::class, 'seat_linked_id', 'seat_id');
}
// isReserved(int showing_id) method
// Looks at showing / order / ticket if it's reserved
// Returns true if it is reserved, false if it isn't
public function is_reserved(int $showing_id)
public function isReserved(int $showing_id): bool
{
$tickets = $this->tickets()->where('showing_id', $showing_id)->get();
$tickets = $this->tickets->where('showing_id', $showing_id);
foreach ($tickets as $ticket) {
if ($ticket->order->order_status == 'pending' || $ticket->order->order_status == 'paid') {
if ($ticket->showing_id == $showing_id) {
return true;
}
}
return false;
}
}

View file

@ -2,6 +2,7 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
@ -45,4 +46,29 @@ class Showing extends Model
return $this->where('showing_start', '>=', now())->get();
}
public function end_time() {
$date = new Carbon($this->showing_start);
$date->addMinutes($this->movie->movie_length);
return $date;
}
public function tickets()
{
return $this->hasMany(Ticket::class, 'showing_id', 'showing_id');
}
public function tickets_available() {
$tickets = $this->room->seats()->count();
$tickets_sold = $this->tickets()->count();
return $tickets - $tickets_sold;
}
public function find($id)
{
return Showing::where('showing_id', $id)->first();
}
public function seatMatrix() {
return $this->room->seatMatrix($this->showing_id);
}
}

View file

@ -62,9 +62,6 @@ class User extends Authenticatable
public function allowedTo($permission): bool
{
if($this->role === 'manage') {
return true;
}
if ($this->permissions()->where('permission_name', $permission)->first()) {
return true;
}