Ejemplo n.º 1
0
 public function addSeat(Request $r, $performance, $seat)
 {
     $ss = $this->getSS();
     $prfModel = Performance::findOrFail($performance);
     $seatModel = Seat::findOrFail($seat);
     $rateModel = Rate::findOrFail($r->input('rate'));
     // Check show, map compatibility
     $prfMap = $prfModel->seatMap()->first();
     $seatMap = $seatModel->blockRow()->first()->seatmapBlock()->first()->seatMap()->first();
     $rateShow = $rateModel->show()->first();
     $prfShow = $prfModel->show()->first();
     if (!$ss->ephemeral || $ss->annulled) {
         return new Response(NULL, 403);
     }
     if ($seatModel->hidden) {
         return new Response(NULL, 400);
     }
     if ($prfMap->id != $seatMap->id || $rateShow->id != $prfShow->id) {
         return new Response(NULL, 400);
     }
     // If we already have a booking for this seat, update it
     if (DB::table('booking_seats')->select('*')->where('seat_set_id', $ss->id)->where('seat_id', $seatModel->id)->where('performance_id', $prfModel->id)->count()) {
         return $this->updateBookingSeat($ss, $prfModel, $seatModel, $rateModel);
     }
     // Else create a new one
     $bookSeat = new BookingSeat();
     $bookSeat->performance()->associate($prfModel);
     $bookSeat->seat()->associate($seatModel);
     $bookSeat->rate()->associate($rateModel);
     $bookSeat->seatSet()->associate($ss);
     return $this->catchIntegrityViolation(function () use($bookSeat) {
         $bookSeat->save();
         return new Response(NULL, 204);
     });
 }
Ejemplo n.º 2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $s = new Show();
     $s->name = 'Sweeney Todd';
     $s->fullName = 'Sweeney Todd: The Demon Barber of Fleet Street';
     $s->venue = 'ICU Concert Hall';
     $s->description = 'Sweeney Todd: The Demon Barber of Fleet Street is a 1979 musical thriller with music and lyrics by Stephen Sondheim and book by Hugh Wheeler. The musical details the return of barber Sweeney Todd to London after 15 years of exile, in order to take revenge on the corrupt judge who banished him, by conspiring with a local baker, Mrs. Lovett, who is in desperate need of fresh meat for her pies.';
     $s->save();
     $rates = [];
     $first = TRUE;
     $defaultId = NULL;
     foreach (['Adult', 'Concession'] as $rname) {
         $rate = new Rate();
         $rate->name = $rname;
         $rate->show()->associate($s);
         $rate->save();
         if ($first) {
             $first = FALSE;
             $defaultId = $rate;
         }
         $rates[$rname] = $rate;
     }
     $defaultRate = new ShowDefaultRate();
     $defaultRate->show()->associate($s);
     $defaultRate->rate()->associate($defaultId);
     $defaultRate->save();
     $sm = new Seatmap();
     $sm->save();
     $dt = new \DateTime('2016-03-02 19:30:00');
     $clone = function () use($dt) {
         return clone $dt;
     };
     $perfTimes = [[$dt, 20], [$clone()->add(new \DateInterval('P1D')), 20], [$clone()->add(new \DateInterval('P1DT23H')), 10], [$clone()->add(new \DateInterval('P2DT2H30M')), 10], [new \DateTime('2016-03-05 14:30:00'), 20], [$clone()->add(new \DateInterval('P3D')), 20]];
     $performances = [];
     foreach ($perfTimes as $time) {
         $doorsTime = clone $time[0];
         $doorsTime->sub(new \DateInterval("PT{$time[1]}M"));
         $doorsTimeStr = $doorsTime->format('G:i');
         $performances[] = $p = new Performance();
         $p->show()->associate($s);
         $p->seatMap()->associate($sm);
         $p->startsAt = $time[0];
         $p->description = "Doors open {$time[1]} minutes before the performance starts.";
         $p->ticketNote = "Doors at {$doorsTimeStr}";
         $p->save();
     }
     $bands = [];
     foreach (['Standard', 'Restricted View'] as $name) {
         $bnd = new Band();
         $bnd->seatmap()->associate($sm);
         $bnd->name = $name;
         $bnd->save();
         $bands[$name] = $bnd;
     }
     $makeBlock = function ($name, $coords, $rotation, $block) use($sm) {
         $blk = new SeatmapBlock();
         $blk->seatmap()->associate($sm);
         $blk->name = $name;
         $blk->xOffset = $coords[0];
         $blk->yOffset = $coords[1];
         $blk->rotation = $rotation;
         $blk->save();
         $block($blk);
     };
     $makeRows = function ($block, $rowSpec, $startAt, $inc = TRUE, $firstRow = 'A', $rowFix = NULL) use($bands) {
         $last = ord($firstRow) + count($rowSpec) - 1;
         $startAt--;
         foreach ($rowSpec as $i => $rowcount) {
             $rowStart = $startAt;
             $row = new BlockRow();
             $row->seatmapBlock()->associate($block);
             $row->name = chr($last - $i);
             $row->rank = $i;
             $row->leftAlign = $inc;
             $seatFix = NULL;
             if ($rowFix && ($newStart = $rowFix($i, $row, $seatFix))) {
                 $rowStart = $newStart - 1;
             }
             $row->save();
             $band = $bands['Standard'];
             for ($j = 1; $j <= $rowcount; $j++) {
                 $seat = new Seat();
                 $seat->blockRow()->associate($row);
                 $seat->seatNum = $inc ? $j + $rowStart : 1 + $rowStart + $rowcount - $j;
                 $seat->band()->associate($band);
                 $seat->restricted = FALSE;
                 if ($seatFix) {
                     $seatFix($j, $seat);
                 }
                 $seat->save();
             }
         }
     };
     $makeBlock('Stalls L', [5, 0], 0, function ($blk) use($makeRows) {
         $makeRows($blk, [8, 8, 8, 8, 8, 4], 1, TRUE, 'A', function ($i, $row, &$seatFix) {
             if ($i == 5) {
                 $row->leftAlign = FALSE;
                 return 5;
             } else {
                 if ($i == 0) {
                     $seatFix = function ($i, $seat) {
                         $seat->hidden = TRUE;
                     };
                 }
             }
         });
     });
     $makeBlock('Stalls R', [25, 0], 0, function ($blk) use($makeRows) {
         $makeRows($blk, [8, 8, 8, 8, 8, 4], 9);
     });
     $makeBlock('Promenade L', [-10, 28], -90, function ($blk) use($makeRows) {
         $makeRows($blk, [15, 11, 10], 1, false);
     });
     $makeBlock('Promenade R', [31, 22], 90, function ($blk) use($makeRows, $bands) {
         $makeRows($blk, [11, 11, 10], 1, true, 'D');
         $rstBand = $bands['Restricted View']->id;
         foreach (['D' => 7, 'E' => 6, 'F' => 2] as $row => $seat) {
             $blk->rows()->where('name', $row)->first()->seats()->where('seatNum', '>=', $seat)->update(['restricted' => TRUE, 'band_id' => $rstBand]);
         }
     });
     foreach ($bands as $band) {
         foreach ($rates as $rate) {
             $sbr = new ShowBandRate();
             $sbr->band()->associate($band);
             $sbr->rate()->associate($rate);
             $sbr->price = 100 * rand(1, 20);
             $sbr->save();
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $s = new Show();
     $s->name = 'oklahoma';
     $s->fullName = 'ICU MTSoc Presents: Oklahoma!';
     $s->venue = 'Hammersmith Apollo';
     $s->description = 'Ermagerd this show is 5* go see it!';
     $s->save();
     $rates = [];
     $first = TRUE;
     $defaultId = NULL;
     foreach (['Adult', 'Concession', 'VIP'] as $rname) {
         $rate = new Rate();
         $rate->name = $rname;
         $rate->show()->associate($s);
         $rate->save();
         if ($first) {
             $first = FALSE;
             $defaultId = $rate;
         }
         $rates[$rname] = $rate;
     }
     $defaultRate = new ShowDefaultRate();
     $defaultRate->show()->associate($s);
     $defaultRate->rate()->associate($defaultId);
     $defaultRate->save();
     $sm = new Seatmap();
     $sm->save();
     $dt = new \DateTime();
     $performances = [];
     for ($i = 3; $i--;) {
         $performances[] = $p = new Performance();
         $p->show()->associate($s);
         $p->seatMap()->associate($sm);
         $p->startsAt = clone $dt;
         $p->description = "Doors open 15 minutes before the performance starts.";
         $p->save();
         $dt->add(new \DateInterval("P1D"));
     }
     $bands = [];
     foreach (['Premium', 'Standard', 'Restricted'] as $name) {
         $bnd = new Band();
         $bnd->seatmap()->associate($sm);
         $bnd->name = $name;
         $bnd->save();
         $bands[$name] = $bnd;
     }
     $offset = 0;
     foreach (['Stalls', 'Circle'] as $name) {
         $blk = new SeatmapBlock();
         $blk->seatmap()->associate($sm);
         $blk->name = $name;
         $blk->xOffset = $offset;
         $offset += 30;
         $blk->yOffset = 0;
         $blk->rotation = 0;
         $blk->save();
         for ($i = 10; $i--;) {
             $row = new BlockRow();
             $row->seatmapBlock()->associate($blk);
             $row->name = chr(ord('A') + $i);
             $row->rank = $i;
             $row->save();
             if ($i == 9) {
                 $seatBnd = $bands['Restricted'];
             } else {
                 if ($i < 3) {
                     $seatBnd = $bands['Premium'];
                 } else {
                     $seatBnd = $bands['Standard'];
                 }
             }
             for ($j = 10; $j--;) {
                 $seat = new Seat();
                 $seat->blockRow()->associate($row);
                 $seat->seatNum = $j;
                 $seat->band()->associate($seatBnd);
                 $seat->restricted = $i == 9;
                 $seat->save();
             }
         }
     }
     foreach ($bands as $band) {
         foreach ($rates as $rate) {
             $sbr = new ShowBandRate();
             $sbr->band()->associate($band);
             $sbr->rate()->associate($rate);
             $sbr->price = 100 * rand(1, 20);
             $sbr->save();
         }
     }
 }