Skip to content

Commit

Permalink
Issue #339 cableman: Added SMS and phone number to alma
Browse files Browse the repository at this point in the history
  • Loading branch information
cableman committed May 20, 2014
1 parent c4460bb commit c24d9f9
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 17 deletions.
82 changes: 82 additions & 0 deletions alma.features.field_base.inc
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,88 @@ function alma_field_default_field_bases() {
),
);

// Exported field_base: 'field_alma_sms'
$field_bases['field_alma_sms'] = array(
'active' => 1,
'cardinality' => 1,
'deleted' => 0,
'entity_types' => array(),
'field_name' => 'field_alma_sms',
'foreign keys' => array(
'format' => array(
'columns' => array(
'format' => 'format',
),
'table' => 'filter_format',
),
),
'indexes' => array(
'format' => array(
0 => 'format',
),
),
'locked' => 0,
'module' => 'text',
'settings' => array(
'max_length' => 255,
'profile2_private' => 0,
),
'storage' => array(
'active' => 1,
'module' => 'virtual_field',
'settings' => array(),
'type' => 'virtual_field',
),
'translatable' => 0,
'type' => 'text',
'virtual_field' => array(
'entity_types' => array(
0 => 'profile2',
),
),
);

// Exported field_base: 'field_alma_sms_id'
$field_bases['field_alma_sms_id'] = array(
'active' => 1,
'cardinality' => 1,
'deleted' => 0,
'entity_types' => array(),
'field_name' => 'field_alma_sms_id',
'foreign keys' => array(
'format' => array(
'columns' => array(
'format' => 'format',
),
'table' => 'filter_format',
),
),
'indexes' => array(
'format' => array(
0 => 'format',
),
),
'locked' => 0,
'module' => 'text',
'settings' => array(
'max_length' => 255,
'profile2_private' => 0,
),
'storage' => array(
'active' => 1,
'module' => 'virtual_field',
'settings' => array(),
'type' => 'virtual_field',
),
'translatable' => 0,
'type' => 'text',
'virtual_field' => array(
'entity_types' => array(
0 => 'profile2',
),
),
);

// Exported field_base: 'field_alma_street_name'
$field_bases['field_alma_street_name'] = array(
'active' => 1,
Expand Down
84 changes: 75 additions & 9 deletions alma.features.field_instance.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function alma_field_default_field_instances() {
'label' => 'hidden',
'settings' => array(),
'type' => 'hidden',
'weight' => 9,
'weight' => 10,
),
),
'entity_type' => 'profile2',
Expand All @@ -36,7 +36,7 @@ function alma_field_default_field_instances() {
'module' => 'virtual_field',
'settings' => array(),
'type' => 'hidden',
'weight' => 9,
'weight' => 10,
),
);

Expand Down Expand Up @@ -118,7 +118,7 @@ function alma_field_default_field_instances() {
'module' => 'list',
'settings' => array(),
'type' => 'list_default',
'weight' => 8,
'weight' => 9,
),
),
'entity_type' => 'profile2',
Expand Down Expand Up @@ -182,7 +182,7 @@ function alma_field_default_field_instances() {
'module' => 'text',
'settings' => array(),
'type' => 'text_default',
'weight' => 5,
'weight' => 6,
),
),
'entity_type' => 'profile2',
Expand All @@ -200,7 +200,7 @@ function alma_field_default_field_instances() {
'size' => 12,
),
'type' => 'text_textfield',
'weight' => 8,
'weight' => 9,
),
);

Expand All @@ -215,7 +215,7 @@ function alma_field_default_field_instances() {
'label' => 'hidden',
'settings' => array(),
'type' => 'hidden',
'weight' => 10,
'weight' => 11,
),
),
'entity_type' => 'profile2',
Expand All @@ -230,7 +230,7 @@ function alma_field_default_field_instances() {
'module' => 'virtual_field',
'settings' => array(),
'type' => 'hidden',
'weight' => 10,
'weight' => 12,
),
);

Expand Down Expand Up @@ -277,7 +277,7 @@ function alma_field_default_field_instances() {
'module' => 'list',
'settings' => array(),
'type' => 'list_default',
'weight' => 6,
'weight' => 7,
),
),
'entity_type' => 'profile2',
Expand Down Expand Up @@ -313,7 +313,7 @@ function alma_field_default_field_instances() {
'multiple_to' => '',
),
'type' => 'date_default',
'weight' => 7,
'weight' => 8,
),
),
'entity_type' => 'profile2',
Expand Down Expand Up @@ -345,6 +345,70 @@ function alma_field_default_field_instances() {
),
);

// Exported field_instance: 'profile2-provider_alma-field_alma_sms'
$field_instances['profile2-provider_alma-field_alma_sms'] = array(
'bundle' => 'provider_alma',
'default_value' => NULL,
'deleted' => 0,
'description' => '',
'display' => array(
'default' => array(
'label' => 'inline',
'module' => 'text',
'settings' => array(),
'type' => 'text_default',
'weight' => 5,
),
),
'entity_type' => 'profile2',
'field_name' => 'field_alma_sms',
'label' => 'SMS',
'required' => 0,
'settings' => array(
'text_processing' => 0,
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 1,
'module' => 'text',
'settings' => array(
'size' => 60,
),
'type' => 'text_textfield',
'weight' => 8,
),
);

// Exported field_instance: 'profile2-provider_alma-field_alma_sms_id'
$field_instances['profile2-provider_alma-field_alma_sms_id'] = array(
'bundle' => 'provider_alma',
'default_value' => NULL,
'deleted' => 0,
'description' => '',
'display' => array(
'default' => array(
'label' => 'hidden',
'settings' => array(),
'type' => 'hidden',
'weight' => 12,
),
),
'entity_type' => 'profile2',
'field_name' => 'field_alma_sms_id',
'label' => 'SMS id',
'required' => 0,
'settings' => array(
'text_processing' => 0,
'user_register_form' => FALSE,
),
'widget' => array(
'module' => 'virtual_field',
'settings' => array(),
'type' => 'hidden',
'weight' => 11,
),
);

// Exported field_instance: 'profile2-provider_alma-field_alma_street_name'
$field_instances['profile2-provider_alma-field_alma_street_name'] = array(
'bundle' => 'provider_alma',
Expand Down Expand Up @@ -388,6 +452,8 @@ function alma_field_default_field_instances() {
t('Postal code');
t('Preferred branch');
t('Reservation pause');
t('SMS');
t('SMS id');
t('Set your reservations on pause.');
t('Street name');
t('The e-mail address is not made public and will only be used if you wish to receive certain news or notifications by e-mail.');
Expand Down
7 changes: 5 additions & 2 deletions alma.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name = Alma
description = Implementation of Axiell’s Alma API for DDELibra.
core = 7.x
package = Providers
php = 5.2.4
project = alma
dependencies[] = date
dependencies[] = ding_provider
Expand All @@ -16,7 +15,7 @@ dependencies[] = options
dependencies[] = profile2
dependencies[] = text
dependencies[] = virtual_field
features[features_api][] = api:1
features[features_api][] = api:2
features[field_base][] = field_alma_absent_id
features[field_base][] = field_alma_city
features[field_base][] = field_alma_full_name
Expand All @@ -27,6 +26,8 @@ features[field_base][] = field_alma_phone_id
features[field_base][] = field_alma_postal_code
features[field_base][] = field_alma_preferred_branch
features[field_base][] = field_alma_reservation_pause
features[field_base][] = field_alma_sms
features[field_base][] = field_alma_sms_id
features[field_base][] = field_alma_street_name
features[field_instance][] = profile2-provider_alma-field_alma_absent_id
features[field_instance][] = profile2-provider_alma-field_alma_city
Expand All @@ -38,6 +39,8 @@ features[field_instance][] = profile2-provider_alma-field_alma_phone_id
features[field_instance][] = profile2-provider_alma-field_alma_postal_code
features[field_instance][] = profile2-provider_alma-field_alma_preferred_branch
features[field_instance][] = profile2-provider_alma-field_alma_reservation_pause
features[field_instance][] = profile2-provider_alma-field_alma_sms
features[field_instance][] = profile2-provider_alma-field_alma_sms_id
features[field_instance][] = profile2-provider_alma-field_alma_street_name
features[profile2_type][] = provider_alma
files[] = alma.module
Expand Down
80 changes: 74 additions & 6 deletions alma.module
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,22 @@ function alma_profile2_presave($entity) {
}
}

// SMS number.
$value = $wrapper->field_alma_sms->value();
if (!is_null($wrapper_original->field_alma_sms->value())) {
// Update sms phone number.
$value = is_null($value) ? 'DELETE' : $value;
if ($value != $wrapper_original->field_alma_sms->value()) {
$changes['sms'] = $value;

// Get sms id.
$changes['sms_id'] = $wrapper->field_alma_sms_id->value();
}
}
elseif (!is_null($value) && is_null($wrapper_original->field_alma_sms->value())) {
$changes['sms'] = $value;
}

// Mobile phone.
$value = $wrapper->field_alma_mobile_phone->value();
if (!is_null($wrapper_original->field_alma_mobile_phone->value())) {
Expand Down Expand Up @@ -400,7 +416,7 @@ function alma_update_provider($changes, $entity) {
else {
// Update mobile.
try {
$res = alma_client_invoke('change_phone_number', $creds['name'], $creds['pass'], $changes['phone_id'], $changes['mobile']);
$res = alma_client_invoke('change_phone_number', $creds['name'], $creds['pass'], $changes['phone_id'], $changes['mobile'], FALSE);
}
catch (Exception $exception) {
watchdog_exception('Alma provider', $exception);
Expand All @@ -415,7 +431,7 @@ function alma_update_provider($changes, $entity) {
elseif (isset($changes['mobile'])) {
// Add mobile.
try {
$res = alma_client_invoke('add_phone_number', $creds['name'], $creds['pass'], $changes['mobile']);
$res = alma_client_invoke('add_phone_number', $creds['name'], $creds['pass'], $changes['mobile'], FALSE);
}
catch (Exception $exception) {
watchdog_exception('Alma provider', $exception);
Expand All @@ -426,6 +442,51 @@ function alma_update_provider($changes, $entity) {
}
}

// Mobile phone; add, change, delete.
if (isset($changes['sms_id'])) {
if ($changes['sms'] == 'DELETE') {
// Delete mobile.
try {
$res = alma_client_invoke('remove_phone_number', $creds['name'], $creds['pass'], $changes['sms_id']);
}
catch (Exception $exception) {
watchdog_exception('Alma provider', $exception);
}

if (empty($res)) {
$error_message .= t('sms not deleted');
drupal_set_message($error_message, 'warning');
}
}
else {
// Update mobile.
try {
$res = alma_client_invoke('change_phone_number', $creds['name'], $creds['pass'], $changes['sms_id'], $changes['sms']);
}
catch (Exception $exception) {
watchdog_exception('Alma provider', $exception);
}

if (!$res) {
$error_message .= t('sms not updated');
drupal_set_message($error_message, 'warning');
}
}
}
elseif (isset($changes['sms'])) {
// Add mobile.
try {
$res = alma_client_invoke('add_phone_number', $creds['name'], $creds['pass'], $changes['sms']);
}
catch (Exception $exception) {
watchdog_exception('Alma provider', $exception);
}
if (!$res) {
$error_message .= t('sms not added');
drupal_set_message($error_message, 'warning');
}
}

// Update reservation pause (absentPeriod).
if (!empty($changes['absent_id']) &&
!empty($changes['reservation_pause_start']) &&
Expand Down Expand Up @@ -625,10 +686,17 @@ function alma_profile2_load($entities) {
// Preferred_branch.
$wrapper->field_alma_preferred_branch->set($patron->branch);

// Mobile; also here alma supports multiple phones - again we pick the
// first.
$wrapper->field_alma_mobile_phone->set(isset($patron->mobiles[0]['phone']) ? $patron->mobiles[0]['phone'] : '');
$wrapper->field_alma_phone_id->set(isset($patron->mobiles[0]['id']) ? $patron->mobiles[0]['id'] : NULL);
// Mobile (SMS and telephone).
foreach ($patron->mobiles as $mobile) {
if ($mobile['sms']) {
$wrapper->field_alma_sms->set(isset($mobile['phone']) ? $mobile['phone'] : '');
$wrapper->field_alma_sms_id->set(isset($mobile['id']) ? $mobile['id'] : NULL);
}
else {
$wrapper->field_alma_mobile_phone->set(isset($mobile['phone']) ? $mobile['phone'] : '');
$wrapper->field_alma_phone_id->set(isset($mobile['id']) ? $mobile['id'] : NULL);
}
}

// Mail address.
$wrapper->field_alma_mail->set($patron->email);
Expand Down

0 comments on commit c24d9f9

Please sign in to comment.