Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

book online website pages #14

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
/node_modules
/public/hot
/public/storage
/public/css
/public/js
/public/sitemap.xml
/public/main_sitemap.xml
/public/blog_sitemap.xml
/storage/*.key
/vendor
.env
Expand All @@ -14,3 +19,4 @@ Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
composer.lock
17 changes: 17 additions & 0 deletions app/Helpers/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

function cleanSlug($string)
{
$string = preg_replace('/\%/', ' percentage', $string);
$string = preg_replace('/\@/', ' at ', $string);
$string = preg_replace('/\&/', ' and ', $string);
$string = preg_replace('/\s[\s]+/', '-', $string); // Strip off multiple spaces
$string = preg_replace('/[^\\pL\d_]+/u', '-', $string);
$string = iconv('utf-8', 'us-ascii//TRANSLIT', $string);
$string = strtolower($string);
$string = preg_replace('/[^-a-z0-9_]+/', '', $string);
$string = preg_replace('/[\s\W]+/', '-', $string); // Strip off spaces and non-alpha-numeric
$string = trim($string, '-'); // Strip off the starting & ending hyphens

return $string;
}
26 changes: 26 additions & 0 deletions app/Helpers/Website.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Tipoff\Locations\Models\Location;
use Tipoff\Locations\Models\Market;
use App\Services\Breakdown;
use Tipoff\Locations\Services\LocationRouter;

function markdown($text)
{
return (new Breakdown())->parse($text);
}

function getCurrentMarket($request)
{
return Market::find($request->session()->get('current_market_id'));
}

function setCurrentMarket($request, $market)
{
$request->session()->put('current_market_id', $market->id);
}

function locationRoute(string $routeName, Market $market, Location $location): string
{
return LocationRouter::build($routeName, $market, $location);
}
147 changes: 147 additions & 0 deletions app/Http/Controllers/Api/AvailabilityController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\Availability\CreateHold;
use App\Http\Requests\Availability\IndexAvailabilities;
use Tipoff\Locations\Models\Location;
use Tipoff\Scheduler\Models\EscaperoomSlot;
use Tipoff\Scheduler\Services\EscaperoomSchedulingService as CalendarService;
use App\Transformers\AvailabilitySlotTransformer;
use Carbon\Carbon;
use Illuminate\Validation\ValidationException;

class AvailabilityController extends Controller
{
/**
* @var App\Transformers\AvailabilitySlotTransformer
*/
protected $transformer;

public function __construct(AvailabilitySlotTransformer $transformer)
{
$this->transformer = $transformer;
}

/**
* @var CalendarService
*/
public $calendarService;

/**
* Get calendar service instance.
* @return CalendarService
*/
public function getCalendaService()
{
if (empty($this->calendarService)) {
$this->calendarService = app(CalendarService::class);
}

return $this->calendarService;
}

/**
* Find slot by slot by number.
*
* Includes viertual slots.
*
* @return Slot
*/
public function findByLocationSlug($locationSlug, $slotNumber)
{
$location = Location::where('slug', $locationSlug)->firstOrFail();
$slot = $location->findOrGenerateSlot($slotNumber);

return fractal($slot, $this->transformer)
->respond();
}

/**
* Get hold.
*
* @param string $locationSlug
* @param string $slotNumber
* @return array
*/
public function getHold($locationSlug, $slotNumber)
{
$location = Location::where('slug', $locationSlug)->firstOrFail();
$slot = $location->findOrGenerateSlot($slotNumber);

return $slot->getHold();
}

/**
* Set slot hold. Throw error if lock already exists.
*
* @param Location $location
* @param string $slotNumber
* @return array
*/
public function setHold(Location $location, $slotNumber, CreateHold $request)
{
$slot = $location->findOrGenerateSlot($slotNumber);

if ($slot->hasHold()) {
throw ValidationException::withMessages([
'slot_number' => 'The slot is already locked.',
]);
}

$slot->setHold($request->user()->id);

return fractal($slot, $this->transformer)
->includeHold()
->respond();
}

/**
* Delete hold.
*
* @param string $locationSlug
* @param string $slotNumber
* @return array
*/
public function deleteHold($locationSlug, $slotNumber)
{
$location = Location::where('slug', $locationSlug)->firstOrFail();
$slot = $location->findOrGenerateSlot($slotNumber);

return $slot->releaseHold();
}

/**
* List slots by location slug.
*
* @return \Illuminate\Http\Response
*/
public function indexByLocationSlug($locationSlug, IndexAvailabilities $request)
{
$calendarService = $this->getCalendaService();
$location = $request->getLocation();

$initialDate = $request->input('initial_date');
$finalDate = $request->input('final_date');

$slots = $calendarService->getLocationSlotsForDateRange($location->id, $initialDate, $finalDate);

$recurringSchedules = $calendarService->getLocationRecurringScheduleForDateRange($location->id, $initialDate, $finalDate);
$erasers = $calendarService->getLocationScheduleErasersForDateRange(
$location->id,
Carbon::parse($initialDate, $location->getPhpTzAttribute()),
Carbon::parse($finalDate ?? $initialDate, $location->getPhpTzAttribute())->addDays(1)->setTime(0, 0, 0),
);

$slots = $slots
->applyRecurringSchedules($recurringSchedules, $initialDate, $finalDate)
->applyFilters($request->filter)
->removeConflicts()
->applyErasers($erasers)
->sortBy($request->input('sort', 'start_at'));

return fractal($slots, $this->transformer)
->respond();
}
}
38 changes: 38 additions & 0 deletions app/Http/Controllers/Api/ThemesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\Theme\IndexThemes;
use Tipoff\EscapeRoom\Models\EscaperoomTheme;
use App\Transformers\ThemeTransformer;

class ThemesController extends Controller
{
/**
* @var App\Transformers\ThemeTransformer
*/
protected $transformer;

public function __construct(ThemeTransformer $transformer)
{
$this->transformer = $transformer;
}

/**
* Display a listing of the resource.
*
* @param \App\Http\Requests\Theme\IndexThemes $request
* @return \Illuminate\Http\Response
*/
public function index(IndexThemes $request)
{
$themes = EscaperoomTheme::filter($request->filter)
->paginate(
$request->getPageSize()
);

return fractal($themes, $this->transformer)
->respond();
}
}
35 changes: 35 additions & 0 deletions app/Http/Controllers/Web/Site/CompanyController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Http\Controllers\Web\Site;

use App\Http\Controllers\Controller;
use Tipoff\Locations\Models\Location;
use DrewRoberts\Media\Models\Image;
use Illuminate\Http\Request;

class CompanyController extends Controller
{
public function __invoke(Request $request)
{
$current = getCurrentMarket($request);
$locations = Location::all()->join('phones', 'phones.id', '=', 'locations.phone_id');

$image = Image::find(43)->url;

return view('website.pages.company.company', [
'market' => $current,
'locations' => $locations,
'html' => null, // set to true if need to use html page instead of AMP
'title' => 'About The Great Escape Room',
'subtitle' => 'Voted #1 Escape Room across America - A truly innovative experience that will keep you coming back for more!',
'cta' => true,
'seotitle' => 'About The Great Escape Room',
'seodescription' => 'Find out more about The Great Escape Room, a leader in the escape room industry with ' . $locations->count() . ' locations.',
'ogtitle' => 'About The Great Escape Room',
'ogdescription' => 'Find out more about The Great Escape Room, a leader in the escape room industry with ' . $locations->count() . ' locations.',
'canonical' => route('company'),
'image' => $image,
'ogimage' => $image === null ? url('img/ogimage.jpg') : $image,
]);
}
}
98 changes: 98 additions & 0 deletions app/Http/Controllers/Web/Site/MarketController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace App\Http\Controllers\Web\Site;

use App\Http\Controllers\Controller;
use Tipoff\EscapeRoom\Models\EscaperoomTheme;
use Tipoff\Locations\Models\Market;
use Tipoff\Reviews\Models\Review;
use Tipoff\EscapeRoom\Models\Room;
use Illuminate\Http\Request;

class MarketController extends Controller
{
public function __invoke(Request $request)
{
// Custom routing due to catch-all fallback in web routes
$market = Market::where('slug', $request->segment(1))->first();
if (is_null($market)) {
abort(404);
}
if (! is_null($request->segment(2))) {
return redirect()->to($market->path);
}

setCurrentMarket($request, $market);

$locations = $market->locations;

// Get all rooms for those locations
$rooms = Room::whereIn('location_id', $locations->pluck('id'))
->whereNull('closed_at')
->orderByDesc('priority')
->get();

$roomPriority = $rooms->pluck('priority', 'theme_id');
$roomnotes = $rooms->filter->note->pluck('note', 'theme_id');
$roomtitles = $rooms->filter->title->pluck('title', 'theme_id');
$roomexcerpts = $rooms->filter->excerpt->pluck('excerpt', 'theme_id');
$roomdescriptions = $rooms->filter->description->pluck('description', 'theme_id');

$comingsoon = $rooms->filter(function ($room) {
return $room->isComing();
})->pluck('opened_at', 'theme_id');

// Get the themes, ordered by rooms->priority exclude closed themes and remove duplicates
$themes = EscaperoomTheme::whereIn('id', $rooms->pluck('theme_id'))
->get()
->sortBy(function ($theme) use ($roomPriority) {
return $roomPriority[$theme->id];
});

$marketreviews = Review::where('is_displayable', true)->whereIn('location_id', $locations->pluck('id'))->orderByDesc('reviewed_at')->limit(6)->get();
if ($marketreviews->count() <= 3) {
$marketreviews = null;
}

$image = $market->image === null ? url('img/hero/tger.jpg') : $market->image->url;

return view('website.markets.show', [
'market' => $market,
'themes' => $themes,
'availablelocations' => $this->availableLocations($themes, $rooms, $locations),
'notes' => $roomnotes,
'titles' => $roomtitles,
'excerpts' => $roomexcerpts,
'descriptions' => $roomdescriptions,
'comingsoon' => $comingsoon,
'reviews' => $marketreviews,
'html' => null, // set to true if need to use html page instead of AMP
'title' => $market->title,
'subtitle' => 'Voted #1 Escape Room across America - A truly innovative experience that will keep you coming back for more!',
'cta' => true,
'seotitle' => $market->title,
'seodescription' => $market->description,
'ogtitle' => $market->title,
'ogdescription' => $market->description,
'canonical' => 'https://thegreatescaperoom.com'.$market->path,
'image' => $image,
'ogimage' => $market->ogimage === null ? $image : $market->ogimage->url,
]);
}

private function availableLocations($themes, $rooms, $locations)
{
// For each theme, return $themeId => [locations that have this theme]
return $themes->mapWithKeys(function ($theme) use ($rooms, $locations) {
$availablerooms = $rooms->filter(function ($room) use ($theme) {
return $room->theme_id === $theme->id;
});

return [
$theme->id => $locations->filter(function ($location) use ($availablerooms) {
return $availablerooms->contains('location_id', $location->id);
}),
];
});
}
}
Loading