| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\App\Services; |
| 4 |
|
| 5 |
use FluentBooking\App\Models\Calendar; |
| 6 |
use FluentBooking\Framework\Support\Arr; |
| 7 |
|
| 8 |
class CalendarEventService |
| 9 |
{ |
| 10 |
public static function processEvent($calendarEvent) |
| 11 |
{ |
| 12 |
$calendarEvent->payment_html = $calendarEvent->getPaymentHtml(); |
| 13 |
|
| 14 |
$calendarEvent->public_url = $calendarEvent->getPublicUrl(); |
| 15 |
|
| 16 |
$calendarEvent->durations = $calendarEvent->getAvailableDurations(); |
| 17 |
|
| 18 |
$calendarEvent->description = $calendarEvent->getDescription(); |
| 19 |
|
| 20 |
$calendarEvent->locations = $calendarEvent->defaultLocationHtml(); |
| 21 |
|
| 22 |
do_action_ref_array('fluent_booking/processed_event', [&$calendarEvent]); |
| 23 |
|
| 24 |
return $calendarEvent; |
| 25 |
} |
| 26 |
|
| 27 |
public static function processEvents(Calendar $calendar, $calendarEvents) |
| 28 |
{ |
| 29 |
$eventOrder = $calendar->getMeta('event_order'); |
| 30 |
|
| 31 |
if (!empty($eventOrder)) { |
| 32 |
$calendarEvents = $calendarEvents->sortBy(function($event) use ($eventOrder) { |
| 33 |
return array_search($event->id, $eventOrder); |
| 34 |
})->values(); |
| 35 |
} |
| 36 |
|
| 37 |
foreach ($calendarEvents as $calendarEvent) { |
| 38 |
$calendarEvent = self::processEvent($calendarEvent); |
| 39 |
} |
| 40 |
|
| 41 |
return $calendarEvents; |
| 42 |
} |
| 43 |
|
| 44 |
public static function isSharedCalendarEvent($calendarEvent) |
| 45 |
{ |
| 46 |
$userId = get_current_user_id(); |
| 47 |
|
| 48 |
if ($calendarEvent->user_id == $userId) { |
| 49 |
return true; |
| 50 |
} |
| 51 |
|
| 52 |
$teamMembers = Arr::get($calendarEvent, 'settings.team_members', []); |
| 53 |
|
| 54 |
return in_array($userId, $teamMembers); |
| 55 |
} |
| 56 |
} |
| 57 |
|