|
@@ -63,8 +63,8 @@ class AppointmentController extends Controller
|
|
"clientUid" => $appointment->client->uid,
|
|
"clientUid" => $appointment->client->uid,
|
|
"proId" => $appointment->pro->id,
|
|
"proId" => $appointment->pro->id,
|
|
"proUid" => $appointment->pro->uid,
|
|
"proUid" => $appointment->pro->uid,
|
|
- "start" => $this->convertToTimezone($appointment->start_time, $timeZone),
|
|
|
|
- "end" => $this->convertToTimezone($appointment->end_time, $timeZone),
|
|
|
|
|
|
+ "start" => convertToTimezone($appointment->start_time, $timeZone),
|
|
|
|
+ "end" => convertToTimezone($appointment->end_time, $timeZone),
|
|
"clientOnly" => !in_array($appointment->pro->id, $proIds),
|
|
"clientOnly" => !in_array($appointment->pro->id, $proIds),
|
|
"otherClient" => ($appointment->client->id != $clientId),
|
|
"otherClient" => ($appointment->client->id != $clientId),
|
|
"status" => $appointment->status,
|
|
"status" => $appointment->status,
|
|
@@ -120,9 +120,10 @@ class AppointmentController extends Controller
|
|
// 3. calculate pairs of start-end of availability
|
|
// 3. calculate pairs of start-end of availability
|
|
|
|
|
|
// 1. enumerate days between start and end (inclusive)
|
|
// 1. enumerate days between start and end (inclusive)
|
|
- $phpTZ = $this->appTZtoPHPTZ($timeZone);
|
|
|
|
- $startDate = new \DateTime($start, new \DateTimeZone($phpTZ));
|
|
|
|
- $endDate = new \DateTime($end, new \DateTimeZone($phpTZ));
|
|
|
|
|
|
+ $phpTZ = appTZtoPHPTZ($timeZone);
|
|
|
|
+ $phpTZObject = new \DateTimeZone($phpTZ);
|
|
|
|
+ $startDate = new \DateTime($start, $phpTZObject);
|
|
|
|
+ $endDate = new \DateTime($end, $phpTZObject);
|
|
$endDate->setTime(23, 59, 59);
|
|
$endDate->setTime(23, 59, 59);
|
|
$period = new \DatePeriod($startDate, \DateInterval::createFromDateString('1 day'), $endDate);
|
|
$period = new \DatePeriod($startDate, \DateInterval::createFromDateString('1 day'), $endDate);
|
|
$days = [];
|
|
$days = [];
|
|
@@ -172,15 +173,15 @@ class AppointmentController extends Controller
|
|
});
|
|
});
|
|
foreach ($proGenAvailForTheDay as $ga) {
|
|
foreach ($proGenAvailForTheDay as $ga) {
|
|
|
|
|
|
- $gaStart = new \DateTime($day["date"], new \DateTimeZone($this->appTZtoPHPTZ($ga->timezone)));
|
|
|
|
|
|
+ $gaStart = new \DateTime($day["date"], new \DateTimeZone(appTZtoPHPTZ($ga->timezone)));
|
|
$parts = explode(":", $ga->start_time);
|
|
$parts = explode(":", $ga->start_time);
|
|
$gaStart->setTime(intval($parts[0]), intval($parts[1]), intval($parts[2]));
|
|
$gaStart->setTime(intval($parts[0]), intval($parts[1]), intval($parts[2]));
|
|
- $gaStart->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
|
|
|
+ $gaStart->setTimezone($phpTZObject);
|
|
|
|
|
|
- $gaEnd = new \DateTime($day["date"], new \DateTimeZone($this->appTZtoPHPTZ($ga->timezone)));
|
|
|
|
|
|
+ $gaEnd = new \DateTime($day["date"], new \DateTimeZone(appTZtoPHPTZ($ga->timezone)));
|
|
$parts = explode(":", $ga->end_time);
|
|
$parts = explode(":", $ga->end_time);
|
|
$gaEnd->setTime(intval($parts[0]), intval($parts[1]), intval($parts[2]));
|
|
$gaEnd->setTime(intval($parts[0]), intval($parts[1]), intval($parts[2]));
|
|
- $gaEnd->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
|
|
|
+ $gaEnd->setTimezone($phpTZObject);
|
|
|
|
|
|
$proTimeLine->addAvailability($gaStart, $gaEnd);
|
|
$proTimeLine->addAvailability($gaStart, $gaEnd);
|
|
}
|
|
}
|
|
@@ -189,19 +190,19 @@ class AppointmentController extends Controller
|
|
|
|
|
|
// specific availability
|
|
// specific availability
|
|
foreach ($proSpecAvail as $sa) {
|
|
foreach ($proSpecAvail as $sa) {
|
|
- $saStart = new \DateTime($sa->start_time, new \DateTimeZone($this->appTZtoPHPTZ($sa->timezone)));
|
|
|
|
- $saStart->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
|
- $saEnd = new \DateTime($sa->end_time, new \DateTimeZone($this->appTZtoPHPTZ($sa->timezone)));
|
|
|
|
- $saEnd->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
|
|
|
+ $saStart = new \DateTime($sa->start_time, new \DateTimeZone(appTZtoPHPTZ($sa->timezone)));
|
|
|
|
+ $saStart->setTimezone($phpTZObject);
|
|
|
|
+ $saEnd = new \DateTime($sa->end_time, new \DateTimeZone(appTZtoPHPTZ($sa->timezone)));
|
|
|
|
+ $saEnd->setTimezone($phpTZObject);
|
|
$proTimeLine->addAvailability($saStart, $saEnd);
|
|
$proTimeLine->addAvailability($saStart, $saEnd);
|
|
}
|
|
}
|
|
|
|
|
|
// specific unavailability
|
|
// specific unavailability
|
|
foreach ($proSpecUnavail as $sua) {
|
|
foreach ($proSpecUnavail as $sua) {
|
|
- $suaStart = new \DateTime($sua->start_time, new \DateTimeZone($this->appTZtoPHPTZ($sua->timezone)));
|
|
|
|
- $suaStart->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
|
- $suaEnd = new \DateTime($sua->end_time, new \DateTimeZone($this->appTZtoPHPTZ($sua->timezone)));
|
|
|
|
- $suaEnd->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
|
|
|
+ $suaStart = new \DateTime($sua->start_time, new \DateTimeZone(appTZtoPHPTZ($sua->timezone)));
|
|
|
|
+ $suaStart->setTimezone($phpTZObject);
|
|
|
|
+ $suaEnd = new \DateTime($sua->end_time, new \DateTimeZone(appTZtoPHPTZ($sua->timezone)));
|
|
|
|
+ $suaEnd->setTimezone($phpTZObject);
|
|
$proTimeLine->removeAvailability($suaStart, $suaEnd);
|
|
$proTimeLine->removeAvailability($suaStart, $suaEnd);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -211,8 +212,8 @@ class AppointmentController extends Controller
|
|
});
|
|
});
|
|
foreach ($proAppointments as $appointment) {
|
|
foreach ($proAppointments as $appointment) {
|
|
if ($appointment->start_time && $appointment->end_time) {
|
|
if ($appointment->start_time && $appointment->end_time) {
|
|
- $appStart = $this->convertToTimezone($appointment->start_time, $timeZone, 'UTC', true);
|
|
|
|
- $appEnd = $this->convertToTimezone($appointment->end_time, $timeZone, 'UTC', true);
|
|
|
|
|
|
+ $appStart = convertToTimezone($appointment->start_time, $timeZone, 'UTC', true);
|
|
|
|
+ $appEnd = convertToTimezone($appointment->end_time, $timeZone, 'UTC', true);
|
|
$proTimeLine->removeAvailability($appStart, $appEnd);
|
|
$proTimeLine->removeAvailability($appStart, $appEnd);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -220,10 +221,10 @@ class AppointmentController extends Controller
|
|
foreach ($proTimeLine->available as $item) {
|
|
foreach ($proTimeLine->available as $item) {
|
|
|
|
|
|
$eStart = new \DateTime('@' . $item->start);
|
|
$eStart = new \DateTime('@' . $item->start);
|
|
- $eStart->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
|
|
|
+ $eStart->setTimezone($phpTZObject);
|
|
|
|
|
|
$eEnd = new \DateTime('@' . $item->end);
|
|
$eEnd = new \DateTime('@' . $item->end);
|
|
- $eEnd->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
|
|
|
+ $eEnd->setTimezone($phpTZObject);
|
|
|
|
|
|
$events[] = [
|
|
$events[] = [
|
|
"type" => "availability",
|
|
"type" => "availability",
|
|
@@ -244,37 +245,4 @@ class AppointmentController extends Controller
|
|
return json_encode($events);
|
|
return json_encode($events);
|
|
}
|
|
}
|
|
|
|
|
|
- private function convertToTimezone($_dateTime, $_targetTimezone, $_sourceTimezone = 'UTC', $_returnRaw = false) {
|
|
|
|
- if(!$_dateTime) return $_dateTime;
|
|
|
|
- $date = new \DateTime($_dateTime, new \DateTimeZone($_sourceTimezone));
|
|
|
|
- $date->setTimezone(new \DateTimeZone($this->appTZtoPHPTZ($_targetTimezone)));
|
|
|
|
- return $_returnRaw ? $date : $date->format('Y-m-d H:i:s');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private function appTZtoPHPTZ($_timezone) {
|
|
|
|
- switch($_timezone) {
|
|
|
|
- case 'ALASKA':
|
|
|
|
- $timezone = "US/Alaska";
|
|
|
|
- break;
|
|
|
|
- case 'CENTRAL':
|
|
|
|
- $timezone = "US/Central";
|
|
|
|
- break;
|
|
|
|
- case 'HAWAII':
|
|
|
|
- $timezone = "US/Hawaii";
|
|
|
|
- break;
|
|
|
|
- case 'MOUNTAIN':
|
|
|
|
- $timezone = "US/Mountain";
|
|
|
|
- break;
|
|
|
|
- case 'PACIFIC':
|
|
|
|
- $timezone = "US/Pacific";
|
|
|
|
- break;
|
|
|
|
- case 'PUERTO_RICO':
|
|
|
|
- $timezone = "America/Puerto_Rico";
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- $timezone = "US/Eastern";
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- return $timezone;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|