tweaks for seat-chooser

This commit is contained in:
Didier Slof 2023-01-02 00:51:48 +01:00
parent b0cc5b5278
commit 2451ab45cb
Signed by: didier
GPG key ID: 01E71F18AA4398E5
4 changed files with 174 additions and 29 deletions

View file

@ -47,15 +47,9 @@ class Room extends Model
{
$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) {
if (!isset($matrix[$seat->seat_row - 1])) $matrix[$seat->seat_row - 1] = [];
$matrix[$seat->seat_row-1][$seat->seat_column-1] = [
'seat_id' => $seat->seat_id,
'seat_row' => $seat->seat_row,
@ -65,7 +59,24 @@ class Room extends Model
'reserved' => $showing_id ? $seat->isReserved($showing_id) : false,
];
}
return $matrix;
return fix_matrix($matrix, $this->room_columns-1, $this->room_rows-1);
}
}
function fix_matrix($m, $h, $w) {
$_nm = [];
// write the matrix into _nm and fill the empty spaces with null
for ($i = 0; $i <= $h; $i++) {
$_nm[$i] = [];
for ($j = 0; $j <= $w; $j++) {
if (isset($m[$i][$j])) {
$_nm[$i][$j] = $m[$i][$j];
} else {
$_nm[$i][$j] = null;
}
}
}
return $_nm;
}