Skip to content

Commit affe873

Browse files
committed
Image dimensions calculation
Change the image height and width to be calculated on seating plan property save instead of loaded on each page load.
1 parent 8ec8bc5 commit affe873

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

_ide_helper_models.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ class IdeHelperSeat {}
344344
* @property int $order
345345
* @property int $revision
346346
* @property string|null $image_url
347+
* @property string|null $image_height
348+
* @property string|null $image_width
347349
* @property int $scale
348350
* @property \Illuminate\Support\Carbon|null $created_at
349351
* @property \Illuminate\Support\Carbon|null $updated_at

app/Http/Controllers/Admin/SeatingPlanController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ protected function updateObject(SeatingPlan $plan, Request $request)
3535
{
3636
$plan->name = $request->input('name');
3737
$plan->image_url = $request->input('image_url');
38+
$plan->image_height = getimagesize($request->input('image_url'))[1];
39+
$plan->image_width = getimagesize($request->input('image_url'))[0];
3840
$plan->scale = $request->input('scale') ? $request->input('scale') : 100;
3941
$plan->save();
4042
}

database/migrations/2024_09_04_154938_add_scale_to_seating_plans.php renamed to database/migrations/2024_09_04_154938_add_scale_and_sizing_to_seating_plans.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Models\SeatingPlan;
34
use Illuminate\Database\Migrations\Migration;
45
use Illuminate\Database\Schema\Blueprint;
56
use Illuminate\Support\Facades\Schema;
@@ -13,7 +14,18 @@ public function up(): void
1314
{
1415
Schema::table('seating_plans', function (Blueprint $table) {
1516
$table->integer('scale')->default(100)->after('order');
17+
$table->integer('image_height')->after('image_url')->nullable();
18+
$table->integer('image_width')->after('image_height')->nullable();
1619
});
20+
21+
foreach (SeatingPlan::all() as $plan) {
22+
if ($plan->image_url)
23+
{
24+
$plan->image_height = getimagesize($plan->image_url)[1];
25+
$plan->image_width = getimagesize($plan->image_url)[0];
26+
$plan->save();
27+
}
28+
}
1729
}
1830

1931
/**
@@ -23,6 +35,8 @@ public function down(): void
2335
{
2436
Schema::table('seating_plans', function (Blueprint $table) {
2537
$table->dropColumn('scale');
38+
$table->dropColumn('image_height');
39+
$table->dropColumn('image_width');
2640
});
2741
}
2842
};

resources/views/admin/events/seats.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ class="badge bg-muted text-muted-fg">{{ $clanMember->clan->name }}</span>
127127
<div class="seating-plan" style="
128128
@if($plan->image_url)
129129
background-image:url('{{ $plan->image_url }}');
130-
min-height: {{ getimagesize($plan->image_url)[1] }}px"
130+
min-height: {{ $plan->image_height}}px;
131+
min-width: {{ $plan->image_width}}px";
131132
@else
132133
min-height: {{ (collect($seats[$plan->id] ?? [])->max('y') * 2) + 4 }}em;"
133134
@endif

resources/views/admin/seatingplans/show.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ class="btn btn-primary">
123123
<div class="seating-plan" style="
124124
@if($plan->image_url)
125125
background-image:url('{{ $plan->image_url }}');
126-
min-height: {{ getimagesize($plan->image_url)[1] }}px"
126+
min-height: {{ $plan->image_height}}px;
127+
min-width: {{ $plan->image_width}}px";
127128
@else
128129
min-height: {{ (collect($seats[$plan->id] ?? [])->max('y') * 2) + 4 }}em;"
129130
@endif

resources/views/seatingplans/_plan.blade.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
<div class="seating-plan" style="
33
@if($plan->image_url)
44
background-image:url('{{ $plan->image_url }}');
5-
min-height: {{ getimagesize($plan->image_url)[1] }}px"
5+
min-height: {{ $plan->image_height}}px;
6+
min-width: {{ $plan->image_width}}px";
67
@else
7-
min-height: {{ (collect($seats[$plan->id] ?? [])->max('y') * 2) + 4 }}em;"
8+
min-height: {{ (collect($seats[$plan->id] ?? [])->max('y') * 2) + 4 }}em;"
89
@endif
910
>
1011
@foreach($seats[$plan->id] ?? [] as $seat)

0 commit comments

Comments
 (0)