diff --git a/clients/gplan.inc b/clients/gplan.inc index 37c595f..1e679b6 100644 --- a/clients/gplan.inc +++ b/clients/gplan.inc @@ -28,8 +28,17 @@ class AppointmentsGPlanClient extends AppointmentsClientApi { } $options = variable_get('dvg_appointments_soap_options', array()); + // This triggers Exceptions by soap client. + $options['exceptions'] = TRUE; + drupal_alter('dvg_appointment_soap_options', $options); - $this->soap_client = new SoapClient($link, $options); + + try { + $this->soap_client = new SoapClient($this->url, $options); + } + catch (SoapFault $soapFault) { + throw new Exception('Appointments WSDL is not available.'); + } } public static function config_form() { @@ -388,7 +397,7 @@ class AppointmentsGPlanClient extends AppointmentsClientApi { return $right_dates; } - public function get_book_fields() { + public static function get_book_fields() { return array( 'clientInitials' => 'Initials', 'clientLastName' => 'Name', diff --git a/clients/gplan_multiple.inc b/clients/gplan_multiple.inc index 25df1fa..86f3e16 100644 --- a/clients/gplan_multiple.inc +++ b/clients/gplan_multiple.inc @@ -28,8 +28,17 @@ class AppointmentsGPlanMultipleClient extends AppointmentsClientApi { } $options = variable_get('dvg_appointments_soap_options', array()); + // This triggers Exceptions by soap client. + $options['exceptions'] = TRUE; + drupal_alter('dvg_appointment_soap_options', $options); - $this->soap_client = new SoapClient($link, $options); + + try { + $this->soap_client = new SoapClient($this->url, $options); + } + catch (SoapFault $soapFault) { + throw new Exception('Appointments WSDL is not available.'); + } } public static function config_form() { @@ -316,7 +325,7 @@ class AppointmentsGPlanMultipleClient extends AppointmentsClientApi { return $right_dates; } - public function get_book_fields() { + public static function get_book_fields() { return array( 'clientInitials' => 'Initials', 'clientLastName' => 'Name', diff --git a/clients/orchestra.inc b/clients/orchestra.inc index 9a50ce7..e13affc 100644 --- a/clients/orchestra.inc +++ b/clients/orchestra.inc @@ -303,7 +303,7 @@ class AppointmentsOrchestraClient extends AppointmentsClientApi { return $starting_times; } - public function get_book_fields() { + public static function get_book_fields() { return array( 'firstName' => 'First Name', 'lastName' => 'Last Name', diff --git a/dvg_appointments.client.inc b/dvg_appointments.client.inc index 9bf3bea..3f2c670 100644 --- a/dvg_appointments.client.inc +++ b/dvg_appointments.client.inc @@ -105,7 +105,7 @@ abstract class AppointmentsClientApi { return strcmp($a['name'], $b['name']); } - abstract public function get_book_fields(); + abstract public static function get_book_fields(); public function set_booking_value($field, $value) { return $value; diff --git a/dvg_appointments.module b/dvg_appointments.module index 371f18f..ff3eeb9 100644 --- a/dvg_appointments.module +++ b/dvg_appointments.module @@ -50,14 +50,32 @@ function dvg_appointments_module_implements_alter(&$implementations, $hook) { * @return AppointmentsClientApi */ function dvg_appointments_get_client_api() { - $modules = module_invoke_all('dvg_appointments_api_client'); - $api_client = variable_get('dvg_appointments_api_client', FALSE); + $api_client = dvg_appointments_get_client_class(); - if (!$api_client || !isset($modules[$api_client])) { + if (!$api_client) { throw new Exception('No appointment API client found.'); } - return new $modules[$api_client]['class'](); + return new $api_client(); +} + +/** + * Return the class name of the current api client. + * + * @return AppointmentsClientApi|NULL + * Class name only. + */ +function dvg_appointments_get_client_class() { + $client_class = NULL; + + $modules = module_invoke_all('dvg_appointments_api_client'); + $api_client = variable_get('dvg_appointments_api_client', FALSE); + if ($api_client && isset($modules[$api_client])) { + /** @var AppointmentsClientApi $client_api */ + $client_class = $modules[$api_client]['class']; + } + + return $client_class; } /** @@ -1923,9 +1941,16 @@ function dvg_appointments_form_webform_configure_form_alter(&$form, &$form_state $mapping = !empty($node->webform['appointment_mapping']) ? unserialize($node->webform['appointment_mapping']) : array(); try { - $client_api = dvg_appointments_get_client_api(); + $book_fields = array(); + + $modules = module_invoke_all('dvg_appointments_api_client'); + $appointment_client = variable_get('dvg_appointments_api_client', FALSE); + if ($appointment_client && isset($modules[$appointment_client])) { + /** @var AppointmentsClientApi $client_api */ + $client_class = $modules[$appointment_client]['class']; + $book_fields = $client_class::get_book_fields(); + } - $book_fields = $client_api->get_book_fields(); $components = array( '' => t('Select a component'), );