/** * Delete entity from database. * * @return bool|false|int */ public function delete() { $parent_result = parent::delete(); if ($parent_result && $this->get('google_event_id')) { $google = new AB_Google(); $google->loadByStaffId($this->get('staff_id')); $google->delete($this->get('google_event_id')); return $parent_result; } else { return false; } }
/** * @return bool|object */ public function save() { //verify google calendar if (array_key_exists('google_calendar_id', $this->data) && !empty($this->data['google_calendar_id'])) { $google = new AB_Google(); if (!$google->loadByStaffId($this->data['id']) || !$google->validateCalendar($this->data['google_calendar_id'])) { $this->errors['google_calendar'] = implode('<br>', $google->getErrors()); return false; } } return parent::save(); }
/** * Delete event from Google Calendar associated to this appointment. * * @return bool */ public function deleteGoogleCalendarEvent() { $google = new AB_Google(); if ($google->loadByStaffId($this->get('staff_id'))) { // Delete existing event in Google Calendar. return $google->delete($this->get('google_event_id')); } return false; }
/** * Prepare data for staff. * * @param DateTime $start_date */ private function _prepareStaffData(DateTime $start_date) { $this->staffData = array(); $services = AB_StaffService::query('ss')->select('ss.staff_id, ss.price, ss.capacity')->whereIn('ss.staff_id', $this->staff_ids)->where('ss.service_id', $this->userData->get('service_id'))->fetchArray(); foreach ($services as $item) { $this->staffData[$item['staff_id']] = array('price' => $item['price'], 'capacity' => $item['capacity'], 'holidays' => array(), 'bookings' => array(), 'working_hours' => array()); } // Load holidays. $holidays = AB_Holiday::query('h')->whereIn('h.staff_id', $this->staff_ids)->fetchArray(); foreach ($holidays as $item) { $this->staffData[$item['staff_id']]['holidays'][] = $item; } // Load working schedule. $working_schedule = AB_StaffScheduleItem::query('ssi')->select('ssi.*, break.start_time AS break_start, break.end_time AS break_end')->leftJoin('AB_ScheduleItemBreak', 'break', 'break.staff_schedule_item_id = ssi.id')->whereIn('ssi.staff_id', $this->staff_ids)->whereNot('ssi.start_time', null)->fetchArray(); foreach ($working_schedule as $item) { if (!isset($this->staffData[$item['staff_id']]['working_hours'][$item['day_index']])) { $this->staffData[$item['staff_id']]['working_hours'][$item['day_index']] = array('start_time' => $item['start_time'], 'end_time' => $item['end_time'], 'breaks' => array()); } if ($item['break_start']) { $this->staffData[$item['staff_id']]['working_hours'][$item['day_index']]['breaks'][] = array('start' => $item['break_start'], 'end' => $item['break_end']); } } // Load bookings. $bookings = AB_CustomerAppointment::query('ca')->select('a.*, SUM(ca.number_of_persons) AS number_of_bookings')->leftJoin('AB_Appointment', 'a', 'a.id = ca.appointment_id')->leftJoin('AB_StaffService', 'ss', 'ss.staff_id = a.staff_id AND ss.service_id = a.service_id')->whereIn('a.staff_id', $this->staff_ids)->whereGte('a.start_date', $this->userData->get('date_from'))->groupBy('a.start_date')->groupBy('a.staff_id')->groupBy('a.service_id')->fetchArray(); foreach ($bookings as $item) { $item['from_google'] = false; // Handle bookings which end at 24:00. if (substr($item['end_date'], 11) == '00:00:00') { // Set time to 24:00:00 (date part does not matter, it just needs to be 10 characters length). $item['end_date'] = '10_symbols 24:00:00'; } $this->staffData[$item['staff_id']]['bookings'][] = $item; } // Handle Google Calendar events. if (get_option('ab_settings_google_two_way_sync')) { $query = AB_Staff::query('s')->whereIn('s.id', array_merge($this->userData->get('staff_ids'), array(0))); foreach ($query->find() as $staff) { $google = new AB_Google(); if ($google->loadByStaff($staff)) { $this->staffData[$staff->get('id')]['bookings'] = array_merge($this->staffData[$staff->get('id')]['bookings'], $google->getCalendarEvents($start_date) ?: array()); } } } }
<td> <?php AB_Utils::popover(__('The client secret obtained from the Developers Console', 'bookly')); ?> </td> </tr> <tr> <td> <label for="ab_redirect_uri"><?php _e('Redirect URI', 'bookly'); ?> </label> </td> <td> <input id="ab_redirect_uri" class="form-control" type="text" readonly value="<?php echo AB_Google::generateRedirectURI(); ?> " onclick="this.select();" style="cursor: pointer;" /> </td> <td> <?php AB_Utils::popover(__('Enter this URL as a redirect URI in the Developers Console', 'bookly')); ?> </td> </tr> <tr> <td> <label for="ab_settings_google_two_way_sync"><?php _e('2 way sync', 'bookly'); ?> </label>
public function executeEditStaff() { $this->form = new AB_StaffMemberEditForm(); $this->staff = new AB_Staff(); $this->staff->load($this->getParameter('id')); $staff_errors = array(); if (isset($_SESSION['bookly_updated'])) { unset($_SESSION['bookly_updated']); $this->updated = true; } else { if (isset($_SESSION['google_calendar_error'])) { $staff_errors[] = __('Calendar ID is not valid.', 'bookly') . ' (' . $_SESSION['google_calendar_error'] . ')'; unset($_SESSION['google_calendar_error']); } } if (isset($_SESSION['google_auth_error'])) { foreach (json_decode($_SESSION['google_auth_error']) as $error) { $staff_errors[] = $error; } unset($_SESSION['google_auth_error']); } if ($this->staff->get('google_data') == '') { if (get_option('ab_settings_google_client_id') == '') { $this->authUrl = false; } else { $google = new AB_Google(); $this->authUrl = $google->createAuthUrl($this->getParameter('id')); } } // Register string for translate in WPML. do_action('wpml_register_single_string', 'bookly', 'staff_' . $this->staff->get('id'), $this->staff->get('full_name')); $this->render('edit', array('staff_errors' => $staff_errors)); exit; }