1 | <?php |
||
2 | |||
3 | namespace App; |
||
4 | |||
5 | use Illuminate\Database\Eloquent\Model; |
||
6 | |||
7 | class Ticket extends Model |
||
8 | { |
||
9 | // |
||
10 | protected $fillable = ['random_id', 'seat_number', 'purchase_id', 'event_id', 'price_category_id']; |
||
11 | |||
12 | /** |
||
13 | * Get the route key for the model. |
||
14 | * |
||
15 | * @return string |
||
16 | */ |
||
17 | public function getRouteKeyName() |
||
18 | { |
||
19 | return 'random_id'; |
||
20 | } |
||
21 | |||
22 | public function price() |
||
23 | { |
||
24 | return $this->priceCategory->price; |
||
25 | } |
||
26 | |||
27 | public function purchase() |
||
28 | { |
||
29 | return $this->belongsTo('App\Purchase'); |
||
30 | } |
||
31 | |||
32 | public function event() |
||
33 | { |
||
34 | return $this->belongsTo('App\Event'); |
||
35 | } |
||
36 | |||
37 | public function priceCategory() |
||
38 | { |
||
39 | return $this->belongsTo('App\PriceCategory'); |
||
40 | } |
||
41 | |||
42 | public function getRowAndSeat() |
||
43 | { |
||
44 | if( !$this->event->seatMap->layout ) { |
||
45 | return null; |
||
46 | } |
||
47 | |||
48 | $counter = 0; |
||
49 | $columnCounter = 0; |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
50 | $result = []; |
||
51 | $rows = json_decode($this->event->seatMap->layout); |
||
52 | foreach( $rows as $rowId => $row ) { |
||
53 | $columnCounter = 0; |
||
54 | foreach( str_split($row) as $charId => $char) { |
||
55 | if($char === 'a') { |
||
56 | $counter++; |
||
57 | $columnCounter++; |
||
58 | } |
||
59 | if($counter === $this->seat_number) { |
||
60 | $result['row'] = $rowId+1; |
||
61 | $result['seat'] = $columnCounter; |
||
62 | break; |
||
63 | } |
||
64 | } |
||
65 | } |
||
66 | return $result; |
||
67 | } |
||
68 | } |
||
69 |