how to make Google synchronization automatic in Easy!Appointments 1.0

658 views
Skip to first unread message

Glen Davis

unread,
Jan 20, 2015, 6:03:18 PM1/20/15
to easy-app...@googlegroups.com
Here's how I was able to make Google sync occur automatically so that I never accidentally double-book. This may not work for servers with heavy traffic, but I imagine it will work just fine for most people. The way it works is that anytime someone tries to book an appointment google sync runs in the background before the list of available times is displayed.

Change 1
in application/controllers/google.php comment out lines 82 & 83 so that no one needs to be logged into the system for Google sync to occur. It should look like this when you are done:
            //$this->load->library('session');
            //if ($this->session->userdata('user_id') == FALSE) return;

note: this is the change I understood the least. There may be a good reason to be sure the provider is logged in before you sync their calendar, I just can't think of what it is.

Change 2
Next you need to tell the application to sync once someone chooses their service provider on the booking screen
so in assets/js/frontend_book.js around line 103 change
  $('#select-provider').change(function() {
            FrontendBook.getAvailableHours(Date.today().toString('dd-MM-yyyy'));
            FrontendBook.updateConfirmFrame();
});

to
  $('#select-provider').change(function() {
            FrontendBook.googleSync(); // this will make the google calendar for the newly selected provider sync
            FrontendBook.getAvailableHours(Date.today().toString('dd-MM-yyyy'));
            FrontendBook.updateConfirmFrame();
});


Change 3
next you need to tell the application to do a sync upon loading in case the client does not change the default provider
a few lines down in the same file assets/js/frontend_book.js add this line around line 130:

it is currently
            FrontendBook.getAvailableHours($('#select-date').val());
            FrontendBook.updateConfirmFrame();

change it to 
FrontendBook.googleSync(); // this will sync the calendar for the default provider
FrontendBook.getAvailableHours($('#select-date').val());
FrontendBook.updateConfirmFrame();

Change 4
finally you need to add the googleSync function.
Later in the same file  assets/js/frontend_book.js add the function googleSync in the list of parameters to the initialize method. It can be anywhere, I guess. I added it at line 286 right above the call to getAvailableHours. It should look like this when you are done.

  },
 googleSync: function() {
                provider_id= $('#select-provider').val();
                getUrl = GlobalVariables.baseUrl + 'google/sync/' + provider_id;
                jQuery.get(getUrl,provider_id, console.log('Google sync successful'),'json');
    },

    /**
     * This function makes an ajax call and returns the available
     * hours for the selected service, provider and date.
     *
     * @param {string} selDate The selected date of which the available
     * hours we need to receive.
     */
  getAvailableHours: function(selDate) {

coding note: I'm pretty sure including provider_id in the parameter list to jQuery.get is unnecessary - I just typed it that way and things work so I'm leaving it

Change 5
In addition to the changes above, I strongly suggest you add the patch at https://groups.google.com/d/msg/easy-appointments/6AmeSjn4Llk/hbMfRi0hlJgJ to make recurring appointments import properly.

Summary & Limitations
Now whenever a potential client accesses your Easy!Appointments website the provider's calendar will be automatically updated.

Some limitations:
  • I don't do any checking to be sure that the provider has enabled google sync. I just assume that everyone does. The sync function in application/controllers/google.php does check, but if Google sync is not enabled it throws an exception.
  • This is not very efficient for heavily-trafficked sites (you will call sync way more often than needed), but for a less-visited site it may be more efficient than a recurring cron job. I don't think this will matter much as the sync seems very quick.
  • The relevant google limitations are 5 requests per second per account and one million requests per day. Those are large enough limits that I don't think you need to worry.
  • Also, I suppose I might have introduced some kind of security vulnerability with the first change (not checking for user being logged in), but I can't see what it might be. If you see a way to be nefarious please let me know.

I think those are all the changes I made. If you try it and it doesn't work let me know and I'll see if I changed anything else. 

Gary Lee

unread,
May 1, 2019, 9:44:21 AM5/1/19
to Easy!Appointments - Support Group
maybe im missing something, the code lines are a bit off but im assuming thats because im on the latest version but I can find the codes referenced.  when I edit them as shown for some reason when i go to the front end to test it the provider list will noo longer show any providers.

Gary Lee

unread,
May 2, 2019, 11:14:57 AM5/2/19
to Easy!Appointments - Support Group
for me commenting out:
Change 1
in application/controllers/google.php comment out lines 82 & 83 so that no one needs to be logged into the system for Google sync to occur. It should look like this when you are done:
            //$this->load->library('session');
            //if ($this->session->userdata('user_id') == FALSE) return;

note: this is the change I understood the least. There may be a good reason to be sure the provider is logged in before you sync their calendar, I just can't think of what it is.

results in a cannot establish connection to google server error when manually syncing.

also

Change 4
finally you need to add the googleSync function.
Later in the same file  assets/js/frontend_book.js add the function googleSync in the list of parameters to the initialize method. It can be anywhere, I guess. I added it at line 286 right above the call to getAvailableHours. It should look like this when you are done.

  },
 googleSync: function() {
                provider_id= $('#select-provider').val();
                getUrl = GlobalVariables.baseUrl + 'google/sync/' + provider_id;
                jQuery.get(getUrl,provider_id, console.log('Google sync successful'),'json');
    },

    /**
     * This function makes an ajax call and returns the available
     * hours for the selected service, provider and date.
     *
     * @param {string} selDate The selected date of which the available
     * hours we need to receive.
     */
  getAvailableHours: function(selDate) {

specifically makes it so that when on the front end booking page no providers are displayed..

craigtu...@gmail.com

unread,
May 2, 2019, 3:44:46 PM5/2/19
to Easy!Appointments - Support Group
This was done on version 1.0. I tried it back then and found that it did not work.

craigtu...@gmail.com

unread,
May 3, 2019, 8:24:37 AM5/3/19
to Easy!Appointments - Support Group
I think part of the issue is that the google sync on the back end is based on the logged in user.  It will sync to their calendar.  What is needed is a routine that will cycle through all users or that will identify who the user is that you are syncing.  That way google will know who's calendar to sync to.  
Reply all
Reply to author
Forward
0 new messages