Skip to content

Commit c1ea27a

Browse files
committed
qol: parsing music ability to display
1 parent 458eb5b commit c1ea27a

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

app/Models/ClubMember.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,40 @@ public static function getApplicationByID(string $id)
177177
->where('member_id', $id)
178178
->get();
179179
}
180+
181+
// Parse array attributes for display, from json
182+
// [{"type":"guitar","data":"checked"},{"type":"bass","data":"checked"}]
183+
// we won't show the checked text, just other data with type
184+
public static function parseAbilitiesForDisplay($ability) {
185+
if (empty($ability) || !is_array($ability)) {
186+
return '-';
187+
}
188+
189+
$options = [
190+
'guitar' => 'กีตาร์ (โปร่ง / ไฟฟ้า)',
191+
'bass' => 'เบส',
192+
'drums' => 'กลองชุด',
193+
'keyboard' => 'คีย์บอร์ด / เปียโน',
194+
'vocal' => 'ร้องเพลง',
195+
'wind' => 'เครื่องเป่าลม',
196+
'other' => 'อื่นๆ',
197+
];
198+
199+
$display = [];
200+
201+
foreach ($ability as $item) {
202+
$type = $item['type'] ?? '';
203+
$data = $item['data'] ?? '';
204+
205+
if (array_key_exists($type, $options)) {
206+
$text = $options[$type];
207+
if (!empty($data) && $data !== 'checked') {
208+
$text .= ' (' . $data . ')';
209+
}
210+
$display[] = $text;
211+
}
212+
}
213+
214+
return empty($display) ? '-' : implode(', ', $display);
215+
}
180216
}

resources/views/admin/club/approve/main.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<tr>
1212
<th scope="col">รหัสการสมัคร</th>
1313
<th scope="col">ชื่อ-นามสกุล ผู้สมัคร</th>
14-
<th scope="col">ความสามารถ</th>
14+
<th scope="col">ความสามารถทางดนตรี</th>
1515
<th scope="col"></th>
1616
</tr>
1717
</thead>
@@ -20,7 +20,7 @@
2020
<tr>
2121
<td> {{ $approval->member_id }} </td>
2222
<td> {{ $approval->user->name }} {{ $approval->user->surname }} </td>
23-
<td> {{ $approval->ability }} </td>
23+
<td> {{ \App\Models\ClubMember::parseAbilitiesForDisplay($approval->instrument) }} </td>
2424
<td>
2525
<a href=" {{ route('admin.club.approve.detail', ['id' => $approval->member_id]) }}" class="btn btn-primary btn-sm">ดูรายละเอียด</a>
2626
</td>

0 commit comments

Comments
 (0)