Προσθήκη δυνατότητας συγχρονισμού μετά από αλλαγή στα στοχεία ενός ραντεβου.

This commit is contained in:
alextselegidis@gmail.com 2013-06-24 09:52:23 +00:00
parent 82d458fe1d
commit 36718c87f9
5 changed files with 100 additions and 49 deletions

View file

@ -112,18 +112,6 @@ class Backend extends CI_Controller {
if (isset($_POST['appointment_data'])) {
$appointment_data = json_decode(stripcslashes($_POST['appointment_data']), true);
$this->Appointments_Model->add($appointment_data);
if ($appointment_data['id_google_calendar'] != NULL) {
$this->load->model('Providers_Model');
$provider_settings = json_decode($this->Providers_Model
->get_setting('google_token', $appointment_data['id_users_provider']));
if ($provider_settings->google_sync == TRUE) {
$this->load->library('Google_Sync');
$this->google_sync->refresh_token($provider_settings->refresh_token);
$this->google_sync->update_appointment($appointment_data['id']);
}
}
}
// :: SAVE CUSTOMER CHANGES TO DATABASE
@ -132,23 +120,31 @@ class Backend extends CI_Controller {
$this->Customers_Model->add($customer_data);
}
$appointment_data = $this->Appointments_Model->get_row($appointment_data['id']);
$provider_data = $this->Providers_Model->get_row($appointment_data['id_users_provider']);
$customer_data = $this->Customers_Model->get_row($appointment_data['id_users_customer']);
$service_data = $this->Services_Model->get_row($appointment_data['id_services']);
$company_settings = array(
'company_name' => $this->Settings_Model->get_setting('company_name')
);
// :: SYNC APPOINTMENT CHANGES WITH GOOGLE CALENDAR
if ($appointment_data['id_google_calendar'] != NULL) {
$google_sync = $this->Providers_Model
->get_setting('google_sync', $appointment_data['id_users_provider']);
if ($google_sync == TRUE) {
$google_token = $this->Providers_Model
->get_setting('google_token', $appointment_data['id_users_provider']);
$google_token = json_decode($this->Providers_Model
->get_setting('google_token', $appointment_data['id_users_provider']));
$this->load->library('Google_Sync');
$this->google_sync->refresh_token($google_token->refresh_token);
$this->google_sync->update_appointment($appointment_data, $provider_data,
$service_data, $customer_data);
$service_data, $customer_data, $company_settings);
}
}
// :: SEND EMAIL NOTIFICATIONS TO PROVIDER AND CUSTOMER
$this->load->library('Notifications');
try {
$customer_title = 'Appointment Changes Saved Successfully!';
$provider_title = 'Appointment Details Have Changed';
@ -157,11 +153,6 @@ class Backend extends CI_Controller {
$this->notifications->send_new_appointment(
$customer_data, $appointment_data, $provider_title);
} catch(NotificationException $nt_exc) {
// @task Display message to the user that the notification messages could
// not be sent.
}
echo json_encode('SUCCESS');
} catch(Exception $exc) {
@ -207,7 +198,8 @@ class Backend extends CI_Controller {
// :: DELETE APPOINTMENT RECORD FROM DATABASE.
$this->Appointments_Model->delete($_POST['appointment_id']);
// :: SYNC CHANGE TO GOOGLE CALENDAR
// :: SYNC DELETE WITH GOOGLE CALENDAR
if ($appointment_data['id_google_calendar'] != NULL) {
$google_sync = $this->Providers_Model->get_setting('google_sync',
$provider_data['id']);
@ -219,11 +211,14 @@ class Backend extends CI_Controller {
$this->google_sync->refresh_token($google_token->refresh_token);
$this->google_sync->delete_appointment($appointment_data['id_google_calendar']);
}
}
// :: SEND NOTIFICATION EMAILS TO PROVIDER AND CUSTOMER.
$this->load->library('Notifications');
$this->notification->send_remove_appointment($appointment_data, $provider_data,
$service_data, $customer_data, $company_settings);
$this->notifications->send_remove_appointment($appointment_data, $provider_data,
$service_data, $customer_data, $company_settings, $provider_data['email']);
$this->notifications->send_remove_appointment($appointment_data, $provider_data,
$service_data, $customer_data, $company_settings, $customer_data['email']);
echo json_encode('SUCCESS');

View file

@ -31,11 +31,14 @@ class Google_Sync {
// Initialize google client and calendar service.
$this->client = new Google_Client();
$this->client->setUseObjects(true);
$this->client->setApplicationName(SystemConfiguration::$google_product_name);
$this->client->setClientId(SystemConfiguration::$google_client_id);
$this->client->setClientSecret(SystemConfiguration::$google_client_secret);
$this->client->setDeveloperKey(SystemConfiguration::$google_api_key);
$this->client->setRedirectUri($this->CI->config->item('base_url') . 'google/oauth_callback');
$this->service = new Google_CalendarService($this->client);
}
@ -165,11 +168,49 @@ class Google_Sync {
* @param array $provider_data Contains the provider record data.
* @param array $service_data Contains the service record data.
* @param array $customer_data Contains the customer recod data.
* @parma array $company_settings Contains some company settings that are used
* by this method. By the time the following values must be in the array:
* 'company_name'.
*
* @return Google_Event Returns the Google_Event class object.
*/
public function update_appointment($appointment_data, $provider_data,
$service_data, $customer_data) {
$service_data, $customer_data, $company_settings) {
$this->CI->load->helper('general');
$event = $this->service->events->get('primary', $appointment_data['id_google_calendar']);
// Convert event to object
$event->setSummary($service_data['name']);
$event->setLocation($company_settings['company_name']);
$start = new Google_EventDateTime();
$start->setDateTime(date3339(strtotime($appointment_data['start_datetime'])));
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime(date3339(strtotime($appointment_data['end_datetime'])));
$event->setEnd($end);
$event_provider = new Google_EventAttendee();
$event_provider->setDisplayName($provider_data['first_name'] . ' '
. $provider_data['last_name']);
$event_provider->setEmail($provider_data['email']);
$event_customer = new Google_EventAttendee();
$event_customer->setDisplayName($customer_data['first_name'] . ' '
. $customer_data['last_name']);
$event_customer->setEmail($customer_data['email']);
$event->attendees = array(
$event_provider,
$event_customer
);
$updated_event = $this->service->events->update('primary', $event->getId(), $event);
return $updated_event;
}
/**

View file

@ -183,18 +183,18 @@ class Notifications {
'$appointment_provider' => $provider_data['first_name'] . ' ' . $provider_data['last_name'],
'$appointment_date' => date('d/m/Y H:i', strtotime($appointment_data['start_datetime'])),
'$appointment_duration' => $service_data['duration'] . ' minutes',
'$company_link' => $company_settings('company_link'),
'$company_name' => $company_settings('company_name')
'$company_link' => $company_settings['company_link'],
'$company_name' => $company_settings['company_name']
);
$email_html = file_get_contents(dirname(dirname(__FILE__))
. '/views/emails/cancel_appointment.php');
. '/views/emails/remove_appointment.php');
$email_html = $this->replace_template_variables($replace_array, $email_html);
// :: SETUP EMAIL OBJECT AND SEND NOTIFICATION
$mail = new PHPMailer();
$mail->From = $company_settings['company_email'];
$mail->FromName = $company_settings['$company_name'];
$mail->FromName = $company_settings['company_name'];
$mail->AddAddress($to_address); // "Name" argument crushes the phpmailer class.
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';

View file

@ -42,6 +42,11 @@
<i class="icon-calendar"></i>
<span>Enable Sync</span>
</button>
<button id="reload-appointments" class="btn" title="Reload calendar appointments.">
<i class="icon-repeat"></i>
<span>Reload</span>
</button>
</div>
<div class="btn-group">

View file

@ -133,6 +133,16 @@ var BackendCalendar = {
}
});
/**
* Event: Reload Button "Click"
*
* When the user clicks the reload button an the calendar items need to
* be refreshed.
*/
$('#reload-appointments').click(function() {
$('#select-filter-item').trigger('change');
});
/**
* Event: Popover Close Button "Click"
*
@ -513,8 +523,8 @@ var BackendCalendar = {
},
error : function(jqXHR, textStatus, errorThrown) {
//////////////////////////////////////////////////////////////////
//console.log('Update Appointment Data Error:', jqXHR, textStatus,
// errorThrown);
console.log('Update Appointment Data Error:', jqXHR, textStatus,
errorThrown);
//////////////////////////////////////////////////////////////////
if (errorCallback !== undefined) {