/** * Update an existing appointment that is already synced with Google Calendar. * * This method updates the google calendar event item that is connected with the * provided appointment record of Easy!Appointments. * * @param array $appointment Contains the appointment record data. * @param array $provider Contains the provider record data. * @param array $service Contains the service record data. * @param array $customer 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, $provider, $service, $customer, $company_settings) { $this->CI->load->helper('general'); $event = $this->service->events->get($provider['settings']['google_calendar'], $appointment['id_google_calendar']); $event->setSummary($service['name']); $event->setLocation($company_settings['company_name']); $start = new Google_EventDateTime(); $start->setDateTime(date3339(strtotime($appointment['start_datetime']))); $event->setStart($start); $end = new Google_EventDateTime(); $end->setDateTime(date3339(strtotime($appointment['end_datetime']))); $event->setEnd($end); $event->attendees = array(); $event_provider = new Google_EventAttendee(); $event_provider->setDisplayName($provider['first_name'] . ' ' . $provider['last_name']); $event_provider->setEmail($provider['email']); $event->attendees[] = $event_provider; if ($customer != NULL) { $event_customer = new Google_EventAttendee(); $event_customer->setDisplayName($customer['first_name'] . ' ' . $customer['last_name']); $event_customer->setEmail($customer['email']); $event->attendees[] = $event_customer; } $updated_event = $this->service->events->update($provider['settings']['google_calendar'], $event->getId(), $event); return $updated_event; }
/** * Creates a Google Event object and set its parameters * @param app: Appointment object to be set as event */ function set_event_parameters($app, $worker_id = 0) { global $appointments; $a = $appointments; $summary = sprintf(__('%s Appointment', 'appointments'), $a->get_service_name($app->service)); if (isset($this->options["gcal_location"]) && '' != trim($this->options["gcal_location"])) { $location = str_replace(array('ADDRESS', 'CITY'), array($app->address, $app->city), $this->options["gcal_location"]); } else { $location = get_bloginfo('description'); } // Find time difference from Greenwich as GCal asks UTC if (!current_time('timestamp')) { $tdif = 0; } else { $tdif = current_time('timestamp') - time(); } $start = new Google_EventDateTime(); $start->setDateTime(date("Y-m-d\\TH:i:s\\Z", strtotime($app->start) - $tdif)); $end = new Google_EventDateTime(); $end->setDateTime(date("Y-m-d\\TH:i:s\\Z", strtotime($app->end) - $tdif)); // An email is always required if (!$app->email) { $email = $a->get_worker_email($app->worker); } else { $email = $app->email; } if (!$email) { $email = $a->get_admin_email(); } $attendee1 = new Google_EventAttendee(); $attendee1->setEmail($email); $attendees = array($attendee1); $this->event = new Google_Event(); $this->event->setSummary($summary); $this->event->setLocation($location); $this->event->setStart($start); $this->event->setEnd($end); $this->event->setSummary(apply_filters('app-gcal-set_summary', $a->_replace($this->get_summary($worker_id), $app->name, $a->get_service_name($app->service), $a->get_worker_name($app->worker), $app->start, $app->price, $a->get_deposit($app->price), $app->phone, $app->note, $app->address, $app->email, $app->city), $app)); $this->event->setDescription(apply_filters('app-gcal-set_description', $a->_replace($this->get_description($worker_id), $app->name, $a->get_service_name($app->service), $a->get_worker_name($app->worker), $app->start, $app->price, $a->get_deposit($app->price), $app->phone, $app->note, $app->address, $app->email, $app->city), $app)); $this->event->attendees = $attendees; // Alright, now deal with event sequencing if (!empty($app->gcal_ID)) { $tmp = $this->service->events->get($this->get_selected_calendar($worker_id), $app->gcal_ID); $sequence = is_object($tmp) && !empty($tmp->sequence) ? $tmp->sequence : (is_array($tmp) && !empty($tmp['sequence']) ? $tmp['sequence'] : false); if (!empty($sequence)) { $this->event->sequence = $sequence; } // Add sequence if we have it } }