| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\App\Services; |
| 4 |
|
| 5 |
use FluentBooking\App\Models\Calendar; |
| 6 |
|
| 7 |
class CalendarEventService |
| 8 |
{ |
| 9 |
public static function processEvent($calendarEvent) |
| 10 |
{ |
| 11 |
$calendarEvent->payment_html = $calendarEvent->getPaymentHtml(); |
| 12 |
|
| 13 |
$calendarEvent->public_url = $calendarEvent->getPublicUrl(); |
| 14 |
|
| 15 |
$calendarEvent->durations = $calendarEvent->getAvailableDurations(); |
| 16 |
|
| 17 |
$calendarEvent->description = $calendarEvent->getDescription(); |
| 18 |
|
| 19 |
$calendarEvent->locations = $calendarEvent->defaultLocationHtml(); |
| 20 |
|
| 21 |
do_action_ref_array('fluent_booking/processed_event', [&$calendarEvent]); |
| 22 |
|
| 23 |
return $calendarEvent; |
| 24 |
} |
| 25 |
|
| 26 |
public static function processEvents(Calendar $calendar, $calendarEvents) |
| 27 |
{ |
| 28 |
$eventOrder = $calendar->getMeta('event_order'); |
| 29 |
|
| 30 |
if (!empty($eventOrder)) { |
| 31 |
$calendarEvents = $calendarEvents->sortBy(function($event) use ($eventOrder) { |
| 32 |
return array_search($event->id, $eventOrder); |
| 33 |
})->values(); |
| 34 |
} |
| 35 |
|
| 36 |
foreach ($calendarEvents as $calendarEvent) { |
| 37 |
$calendarEvent = self::processEvent($calendarEvent); |
| 38 |
} |
| 39 |
|
| 40 |
return $calendarEvents; |
| 41 |
} |
| 42 |
} |
| 43 |
|