2022-11-23 09:32:34 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Seat extends Model
|
|
|
|
{
|
|
|
|
|
|
|
|
protected $table = 'seats';
|
|
|
|
protected $primaryKey = 'seat_id';
|
|
|
|
public $timestamps = false;
|
|
|
|
protected $fillable = [
|
|
|
|
'seat_row',
|
|
|
|
'seat_number',
|
2023-01-01 20:13:11 +01:00
|
|
|
'seat_type', // enum('standard', 'wheelchair', 'loveseat', 'not_available')
|
|
|
|
'seat_linked_id', // if this is a loveseat, this is the other seat
|
2022-11-23 09:32:34 +01:00
|
|
|
'room_id',
|
|
|
|
];
|
|
|
|
|
|
|
|
protected $hidden = [
|
|
|
|
'created_at',
|
|
|
|
'updated_at',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function room()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Room::class, 'room_id', 'room_id');
|
|
|
|
}
|
|
|
|
|
2023-01-01 20:13:11 +01:00
|
|
|
public function tickets()
|
2022-11-23 09:32:34 +01:00
|
|
|
{
|
2023-01-01 20:13:11 +01:00
|
|
|
return $this->hasMany(Ticket::class, 'seat_id', 'seat_id');
|
2022-11-23 09:32:34 +01:00
|
|
|
}
|
|
|
|
|
2023-01-01 20:13:11 +01:00
|
|
|
public function linked_seat()
|
2022-12-08 09:30:07 +01:00
|
|
|
{
|
2023-01-01 20:13:11 +01:00
|
|
|
return $this->belongsTo(Seat::class, 'seat_linked_id', 'seat_id');
|
2022-12-08 09:30:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2023-01-01 20:13:11 +01:00
|
|
|
public function isReserved(int $showing_id): bool
|
2022-12-08 09:30:07 +01:00
|
|
|
{
|
2023-01-01 20:13:11 +01:00
|
|
|
$tickets = $this->tickets->where('showing_id', $showing_id);
|
2022-12-08 09:30:07 +01:00
|
|
|
foreach ($tickets as $ticket) {
|
2023-01-01 20:13:11 +01:00
|
|
|
if ($ticket->showing_id == $showing_id) {
|
2022-12-08 09:30:07 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2022-11-23 09:32:34 +01:00
|
|
|
}
|