| 1 |
<?php |
| 2 |
|
| 3 |
namespace Booktics\Calendar; |
| 4 |
|
| 5 |
class Calendar_Manager { |
| 6 |
public static function sync_team_member_calendar( int $team_member_id, string $calendar_id ): array { |
| 7 |
if ( $calendar = Calendar_Registry::get_calendar( $calendar_id ) ) { |
| 8 |
if ( $calendar->is_configured( $team_member_id ) ) { |
| 9 |
return $calendar->sync_events( $team_member_id ); |
| 10 |
} |
| 11 |
throw new \Exception( |
| 12 |
sprintf( |
| 13 |
'Calendar not configured for team member ID: %d', |
| 14 |
intval( $team_member_id ) |
| 15 |
) |
| 16 |
); |
| 17 |
} |
| 18 |
throw new \Exception( sprintf( 'Calendar not found: %s', esc_html( $calendar_id ) ) ); |
| 19 |
} |
| 20 |
|
| 21 |
public static function create_calendar_event( string $calendar_id, int $team_member_id, array $event_data ): bool { |
| 22 |
if ( $calendar = Calendar_Registry::get_calendar( $calendar_id ) ) { |
| 23 |
return $calendar->create_event( array_merge( $event_data, array( 'team_member_id' => $team_member_id ) ) ); |
| 24 |
} |
| 25 |
return false; |
| 26 |
} |
| 27 |
} |
| 28 |
|