alextselegidis/easyappointments

Feature Request: Working Plan Exceptions as Calendar Events

Closed this issue · 2 comments

I’ve been using your tool for a few years now and just wanted to say a big thank you for making it!

Like many others, I usually only free up availability on demand, using the “working plan exceptions” feature.

To make this easier, I think it would be great if creating working plan exceptions could work like “negative-space” calendar events.

Ideally, this could be integrated with Google Calendar, so I can set availability while seeing my other commitments.

This way, I could also avoid accidentally scheduling unrelated appointments during times I’ve marked as available but that haven’t been booked yet.

If there is a workaround to achieve something like this, I’d love to hear about it.

I actually managed to make this work! I'm a massive noob, so forgive the crazy jankiness:

In the database, I manually added the row "google_calendar2" to user_settings. This contains the address to a secondary availability calendar on my Google account, no additional API needed.

I added this function to the google_sync.php library. It fetches start and end time of all secondary calendar events in the sync period and writes that to the database.

public function update_working_plan_exceptions(array $provider): void
    {
        $secondary_calendar = $provider['settings']['google_calendar2'] ?? null;

        if (!$secondary_calendar) {
            return;
        }
        
        $sync_past_days = $provider['settings']['sync_past_days'];

        $sync_future_days = $provider['settings']['sync_future_days'];

        $start = strtotime('-' . $sync_past_days . ' days', strtotime(date('Y-m-d')));

        $end = strtotime('+' . $sync_future_days . ' days', strtotime(date('Y-m-d')));

        $events = $this->get_sync_events($secondary_calendar, $start2, $end2);

        $working_plan_exceptions = [];

        foreach ($events->getItems() as $event) {
            $startDateTime = new DateTime($event->getStart()->getDateTime());
            $endDateTime = new DateTime($event->getEnd()->getDateTime());
            $date = $startDateTime->format('Y-m-d');
            $startTime = $startDateTime->format('H:i');
            $endTime = $endDateTime->format('H:i');

            $working_plan_exceptions[$date] = [
                'start' => $startTime,
                'end' => $endTime,
                'breaks' => [], // Add breaks if needed
            ];
        }

        $working_plan_exceptions_json = json_encode($working_plan_exceptions);

        $this->CI->providers_model->set_setting($provider['id'], 'working_plan_exceptions', $working_plan_exceptions_json);
    }

This function is then triggered in the google.php controller

$CI->google_sync->update_working_plan_exceptions($provider);

This way the "synchronization" button above the calendar also updates the working plan exceptions.

It can't handle breaks at the moment (so only one continuous exception per day is possible), there's probably edge cases where it would fail, and it requires messing directly with the database.

But besides that it already works exactly as I need it. Thanks for making the code so easy to understand even for beginners!

Hello!

Thanks for sharing this!

Alex Tselegidis, Easy!Appointments Creator
Need a customization? Get a free quote!