Skip to content

Commit

Permalink
Accomodate some new waitwhile API features
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcuzz committed Oct 4, 2018
1 parent 367ab5e commit 2ef70b7
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Notes for Everyday Waitwhile

## 1.1.5 - 2018-10-04
- Added `craft.waitwhile.getAbsoluteBusinessHours` to accomodate Waitwhile's newest API addition in `businessHoursByDate`
- Added `craft.waitwhile.getAbsoluteWaitlistHours` to accomodate Waitwhile's newest API addition in `businessWaitlistByDate`
- Added `craft.waitwhile.getAbsoluteBookingHours` to accomodate Waitwhile's newest API addition in `businessBookingByDate`
- `craft.waitwhile.getBookingTimesForDay` now uses `getAbsoluteWaitlistHours`

## 1.1.4 - 2018-09-19
- Added a birthdate field to Booking and Guest. This is a useful field a lot of people have a need for. Validation is if it's numeric and 6 in length (ddmmyy).
- The above is sent as an addition to a note as I can not seem to make custom fields work at all
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "everyday-as/craft-waitwhile",
"description": "A plugin that integrates waitwhile.com for Craft CMS",
"version": "1.1.4",
"version": "1.1.5",
"type": "craft-plugin",
"require": {
"craftcms/cms": "^3.0.0",
Expand Down
99 changes: 97 additions & 2 deletions src/models/Waitwhile.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function init()
* Fetch the waitwhile session
*
* @return mixed
* @throws \craft\errors\MissingComponentException
*/
public function getSession()
{
Expand Down Expand Up @@ -179,6 +178,102 @@ public function getResources(): array
}, 300);
}

/**
* @return array
* @throws \Exception
*/
private function getWeekDays(): array
{
$days = [
'mon',
'tue',
'wed',
'thu',
'fri',
'sat',
'sun',
];

$date = (new \DateTime('monday this week'));
foreach($days as $key => $day){
$days[(int)$date->format('Ymd')] = $day;
unset($days[$key]);

$date->add(new \DateInterval('P1D'));
}

return $days;
}

/**
* @return array
* @throws \Exception
*/
public function getAbsoluteBusinessHours(): array
{
$waitlist = $this->getWaitlist();

$days = $this->getWeekDays();

$hours = $waitlist['businessHours'];
$hoursByDate = $waitlist['businessHoursByDate'];

foreach($days as $date => $day){
$isOverrideSet = isset($hoursByDate[$date]);
if($isOverrideSet){
$hours[$day] = $hoursByDate[$date];
}
}

return $hours;
}

/**
* @return array
* @throws \Exception
*/
public function getAbsoluteWaitlistHours(): array
{
$waitlist = $this->getWaitlist();

$days = $this->getWeekDays();

$hours = $waitlist['waitlistHours'];
$hoursByDate = $waitlist['waitlistHoursByDate'];

foreach($days as $date => $day){
$isOverrideSet = isset($hoursByDate[$date]);
if($isOverrideSet){
$hours[$day] = $hoursByDate[$date];
}
}

return $hours;
}

/**
* @return array
* @throws \Exception
*/
public function getAbsoluteBookingHours(): array
{
$waitlist = $this->getWaitlist();

$days = $this->getWeekDays();

$hours = $waitlist['bookingHours'];
$hoursByDate = $waitlist['bookingHoursByDate'];

foreach($days as $date => $day){
$isOverrideSet = isset($hoursByDate[$date]);
if($isOverrideSet){
$hours[$day] = $hoursByDate[$date];
}
}

return $hours;
}

/**
* @param string $date
* @return array
Expand All @@ -194,7 +289,7 @@ public function getBookingTimesForDay(string $date): array
// bookings from start of today
$bookings = $this->getBookingsFrom($startOfDateUnixMs);

$waitlistHours = $this->getWaitlist()['waitlistHours'];
$waitlistHours = $this->getAbsoluteWaitlistHours();
$currentDayAbbreviation = strtolower($startOfDate->format('D'));
$waitlistHoursToday = $waitlistHours[$currentDayAbbreviation]['periods'];
$isOpen = $waitlistHours[$currentDayAbbreviation]['isOpen'];
Expand Down

0 comments on commit 2ef70b7

Please sign in to comment.