From 8164f7c24c35e41446fbf71f9823a363fdc8f8e4 Mon Sep 17 00:00:00 2001 From: Rune Schjellerup Philosof Date: Thu, 4 Oct 2012 11:44:20 +0200 Subject: [PATCH 001/158] Revert "right parameter name" and "extract debt_ids from params" This is an undocumented API change. Moreover, it was a faulty implementation. It should have been debt_ids instead of order_ids... This reverts commit 5d4dc109dde97f644b5f91ab458f5444f3696e71. This reverts commit 7cf109c6f6f0a3fbc3500e248ddb4e515e3e09b4. Conflicts: includes/alma.debt.inc --- includes/alma.debt.inc | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/includes/alma.debt.inc b/includes/alma.debt.inc index c45f65f..609e5e3 100644 --- a/includes/alma.debt.inc +++ b/includes/alma.debt.inc @@ -36,18 +36,9 @@ function alma_debt_list($account) { * @param mixed $order_id * Order ID of the payment transaction, to be recorded in the backend system. */ -function alma_debt_payment_received($amount, $params = array(), $order_id = NULL) { +function alma_debt_payment_received($amount, $debt_ids = array(), $order_id = NULL) { // TODO: We should probably check that $amount adds up to the debts // we're going to mark paid, since Alma doesn't. - if( !empty($params['order_ids']) ) { - $debt_ids = $params['debt_ids']; - } - elseif( !empty($params['debts']) ) { - $debt_ids = array_keys($params['debts']) ; - } - else { - $debt_ids = array(); - } return alma_client_invoke('add_payment', implode(',', $debt_ids), $order_id); } From 4199bb29b14ecb0b1ad15571efa85652ca4faa74 Mon Sep 17 00:00:00 2001 From: Rune Schjellerup Philosof Date: Fri, 5 Oct 2012 14:28:11 +0200 Subject: [PATCH 002/158] Revert "updated holdings information to show department and collection if set" This reverts commit 94934af90725a95bb0876fd1721e22ef706a325b. --- includes/alma.availability.inc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index 8546153..1ef1bb5 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -28,7 +28,12 @@ function alma_availability_holdings($provider_ids) { $result[$alma_id] = $holding; - $result[$alma_id]['html'] = _alma_get_holdings($details, $holding['is_periodical']); + if($holding['is_periodical']){ + $result[$alma_id]['html'] = _alma_get_holdings($details, TRUE); + } + else{ + $result[$alma_id]['html'] = _alma_get_holdings($details, FALSE); + } } } return $result; @@ -118,7 +123,7 @@ function _alma_set_holdings_periodical($res){ * @params $h; holding information for a given material * @return html-table */ -function _alma_set_table_html($h) { +function _alma_set_table_html(&$h) { // set a classname for styling the table $variables['attributes']= array('class'=>array(drupal_html_class('availability_holdings_table'))); @@ -149,15 +154,6 @@ function _alma_set_rows($h) { foreach ($h as $key => $data) { $row = array(); $row['placement'] = $org['branch'][$data['branch_id']]; - - if(!empty($data['department_id'])){ - $row['placement'] = $row['placement'] .' → '. $org['department'][$data['department_id']]; - } - - if(!empty($data['collection_id'])){ - $row['placement'] = $row['placement'] .' → '. $org['collection'][$data['collection_id']]; - } - $row['copies'] = (int) $data['total_count']; $copies_total += $row['copies']; $row['home'] = (int) $data['available_count']; From 589813330b5d8c95467b2b3479b226779f64f9d5 Mon Sep 17 00:00:00 2001 From: Rune Schjellerup Philosof Date: Fri, 5 Oct 2012 14:34:21 +0200 Subject: [PATCH 003/158] Revert "Shows detailed holding information according to openRuth" It doesn't work, periodicals and holdings in general are broken by this. To make it work additional commits need to be cherry-picking to ding_availability. However, the html generating part doesn't belong in this module. This reverts commit 1919aa338fa516b51c261b0fca9813deb52c44ae. Conflicts: includes/alma.availability.inc --- alma.module | 3 + includes/alma.availability.inc | 287 +++++++++------------------- lib/AlmaClient/AlmaClient.class.php | 2 +- 3 files changed, 95 insertions(+), 197 deletions(-) diff --git a/alma.module b/alma.module index c163a92..806f1bf 100644 --- a/alma.module +++ b/alma.module @@ -174,6 +174,7 @@ function alma_client_invoke($method) { $args = func_get_args(); array_shift($args); // Lose the method. $client = alma_client(); + try { $result = call_user_func_array(array($client, $method), $args); } @@ -181,8 +182,10 @@ function alma_client_invoke($method) { watchdog('alma', '@method error: “@message”', array('@method' => $method, '@message' => $e->getMessage()), WATCHDOG_ERROR); throw $e; } + return $result; } + /** * Get the complete organisation info from Alma. * diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index 1ef1bb5..36c9f25 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -1,15 +1,14 @@ $record) { $holding = array( @@ -17,214 +16,110 @@ function alma_availability_holdings($provider_ids) { 'available' => ($record['available_count'] > 0), 'reservable' => $record['show_reservation_button'], 'show_reservation_button' => $record['show_reservation_button'], - 'holdings' => array(), - 'holdings_available' => array(), 'reserved_count' => (int) $record['reservation_count'], - 'total_count' => _alma_count_total($record['holdings'], $record['media_class'] == 'periodical'), 'deferred_period' => FALSE, - 'issues' => array(), - 'is_periodical' => ($record['media_class'] == 'periodical'), + + 'is_periodical' => ($record['media_class'] == 'periodical'), ); - - $result[$alma_id] = $holding; - - if($holding['is_periodical']){ - $result[$alma_id]['html'] = _alma_get_holdings($details, TRUE); - } - else{ - $result[$alma_id]['html'] = _alma_get_holdings($details, FALSE); - } - } - } - return $result; - -} -/** - * @param type $holdings; array containing holding informations - * @param type $is_periodical; Boolean that indicates whether the shown record is a periodical or not - * @return sum of all total_count in $holdings - */ -function _alma_count_total($holdings, $is_periodical) { - $total = 0; - if ($is_periodical) { - foreach ($holdings as $year => $issues) { - foreach ($issues as $issue) { - foreach ($issue as $holding) { - $total += $holding['total_count']; + $total = $total_reservable = 0; + + // START periodicals + if( $holding['is_periodical'] ) { + $parts = array(); + $holding['holdings'] = array(); + foreach( $record['holdings'] as $volume => $issues ) { + foreach($issues as $issue_no => $holds){ + $issue = array(); + $issue['branches'] = array(); + foreach( $holds as $key => $branch_holding) { + + if( !in_array( $branch_holding['branch_id'], $issue['branches'] ) ) { + $issue['branches'][] = $branch_holding['branch_id']; + } + + $issue['local_id'] = $branch_holding['reservable']; + $issue['reservable'] = (($branch_holding['status'] == 'availableForLoan') && + ((int) $branch_holding['total_count'] - (int) $branch_holding['reference_count'])); + $issues_array[$volume][$issue_no] = $issue; + + if (in_array($branch_holding['collection_id'], array('karens', 'karens-'))) { + $holding['deferred_period'] = TRUE; + } + + $parts = array(); + $total += (int) $branch_holding['total_count']; + // Reservable is total items minus reference (which cannot be + // loaned). + $reservable = (int) $branch_holding['total_count'] - (int) $branch_holding['reference_count']; + $total_reservable += $reservable; + foreach ($holding_parts as $part) { + if (!empty($branch_holding[$part . '_id'])) { + $parts[] = $org[$part][$branch_holding[$part . '_id']]; + } + } + + if (!empty($branch_holding['shelf_mark'])) { + // Shelf mark might have leading >, strip any and replace the rest + // with the proper arrow. + $parts[] = strtr(trim($branch_holding['shelf_mark'], " >\n\t"), array('>' => '→')); + } + + $parts = array_filter($parts); + + if ($parts && $branch_holding['total_count'] > $branch_holding['checked_out_count']) { + $branch_string = join(' → ', $parts); + $holding['holdings_available'][] = $branch_string; + if( !in_array($branch_string,$holding['holdings']) ) { + $holding['holdings'][] = $branch_string; + } + } } } } - } - else { - foreach ($holdings as $holding) { - $total += $holding['total_count']; + if( is_array($holding['holdings']) ) { + asort($holding['holdings']); } - } - return $total; -} + $holding['issues'] = $issues_array; + } // END periodicals -/** - * @param type $res; returned array from alma_client class - * @param type $is_periodical; Boolean that indicates whether the shown record is a periodical or not - * @return html to be shown. Returns FALSE if no data is received from alma_client class - */ -function _alma_get_holdings($res, $is_periodical = FALSE) { - if(isset($res['records'])) { - if($is_periodical){ - return _alma_set_holdings_periodical($res); - } - else { - return _alma_set_holdings($res); - } - } - else { - return FALSE; - } -} + else { + foreach ($record['holdings'] as $branch_holding) { + if (in_array($branch_holding['collection_id'], array('karens', 'karens-'))) { + $holding['deferred_period'] = TRUE; + } - /** - * set holdings for all kinds of material except periodicals - * @param array $res - * @return array $result; - */ -function _alma_set_holdings($res) { - $holdings = array(); - foreach ($res['records'] as $alma_id => $records) { - foreach ($records['holdings'] as $holding) { - $holdings[] = $holding; - } - } - - $result = _alma_set_table_html($holdings); - return $result; -} + $parts = array(); + $total += (int) $branch_holding['total_count']; + // Reservable is total items minus reference (which cannot be + // loaned). + $reservable = (int) $branch_holding['total_count'] - (int) $branch_holding['reference_count']; + $total_reservable += $reservable; + foreach ($holding_parts as $part) { + if (!empty($branch_holding[$part . '_id'])) { + $parts[] = $org[$part][$branch_holding[$part . '_id']]; + } + } - /** - * set holdings if material is periodical only - * @param array $res - * @return array $result - */ -function _alma_set_holdings_periodical($res){ - $holdings = array(); - foreach ($res['records'] as $alma_id => $records) { - foreach ($records['holdings'] as $holding => $issue_year) { - foreach ($issue_year as $key) { - $holdings[] = $key[0]; + if (!empty($branch_holding['shelf_mark'])) { + // Shelf mark might have leading >, strip any and replace the rest + // with the proper arrow. + $parts[] = strtr(trim($branch_holding['shelf_mark'], " >\n\t"), array('>' => '→')); } - } - } - - $result = _alma_set_table_html($holdings); - return $result; -} - /** - * Make the html-table - * @params $h; holding information for a given material - * @return html-table - */ -function _alma_set_table_html(&$h) { - // set a classname for styling the table - $variables['attributes']= - array('class'=>array(drupal_html_class('availability_holdings_table'))); - // set table header - $variables['header'] = - array('placement'=>t('Placement'), 'copies'=>t('Copies'), 'Home'=>t('At home'),'reservations'=>t('Reservations')); - // set table rows - $variables['rows'] = _alma_set_rows($h); - // theme the table - // @TODO; move this to ding_availability ?? - $html = theme('table',$variables ); - - return $html; -} - /** - * set rows in table for given holdings - * @param $h; holding information for a given material - * @return array; - */ -function _alma_set_rows($h) { - $rows = array(); - $org = alma_get_organisation(); - - $copies_total = 0; - $home_total = 0; - $reservations_total = 0; - foreach ($h as $key => $data) { - $row = array(); - $row['placement'] = $org['branch'][$data['branch_id']]; - $row['copies'] = (int) $data['total_count']; - $copies_total += $row['copies']; - $row['home'] = (int) $data['available_count']; - $home_total += $row['home']; - $row['reservations'] = (int) $data['ordered_count']; - $reservations_total += $row['reservations']; - $rows[] = $row; - } - - if(count($rows) >= 1){ - $rows = _clean_up_rows($rows); - } - //Adding last row - totals - $row = array(); - $row['data']['Library'] = t('Total'); - $row['data']['Copies'] = $copies_total; - $row['data']['Home'] = $home_total; - $row['data']['Reservations'] = $reservations_total; - $row['class'] = array(drupal_html_class('availability_holdings_last_row')); - $rows[] = $row; - return $rows; -} + $parts = array_filter($parts); - /** - * if the same placement exists several times collect them in one line - * @param array - * @return array; - */ -function _clean_up_rows($_rows) { - $rows = array(); - $placements = array(); - - foreach ($_rows as $row) { - $currkey = $row['placement']; - if(!in_array($currkey, $placements)){ - $placements[] = $currkey; - $placementsarr = _get_placements_with_key($_rows, $currkey); - $this_row = _sum_placement($placementsarr); - $rows[] = $this_row; + if ($parts && $branch_holding['total_count'] > $branch_holding['checked_out_count']) { + $holding['holdings'][] = join(' → ', $parts); + } } - } - return $rows; -} + } - /** - * collect materials with the same placement - * @param array $_rows - * @param String $currkey - * @return array $rows; - */ -function _get_placements_with_key($_rows, $currkey){ - $rows = array(); - foreach ($_rows as $key) { - if($key['placement'] == $currkey){ - $rows[] = $key; + $holding['reservable_count'] = $total_reservable; + $holding['total_count'] = $total; + $result[$alma_id] = $holding; } } - return $rows; -} - /** - * sum material for same placement in one row - * @param $placementsarr; array with all instances of the same placement - ie. 'Hovedbiblioteket' - * @return array; $row - */ -function _sum_placement($placementsarr){ - $row = $placementsarr[0]; - for($i = 1; $i < count($placementsarr);$i++){ - $next_row = $placementsarr[$i]; - $row['copies'] += $next_row['copies']; - $row['home'] += $next_row['home']; - $row['reservations'] += $next_row['reservations']; - } - return $row; + + return $result; } diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index b6f77bd..c8d6755 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -656,6 +656,7 @@ public function catalogue_record_detail($alma_ids) { 'request_status' => $doc->getElementsByTagName('status')->item(0)->getAttribute('value'), 'records' => array(), ); + foreach ($doc->getElementsByTagName('detailCatalogueRecord') as $elem) { $record = AlmaClient::process_catalogue_record_details($elem); $data['records'][$record['alma_id']] = $record; @@ -776,7 +777,6 @@ private static function process_catalogue_record_holdings($elem) { ); } - return $holdings; } From 1f197734f2597b316bad5c217ed07656e46492c1 Mon Sep 17 00:00:00 2001 From: Rune Schjellerup Philosof Date: Tue, 6 Nov 2012 13:55:17 +0100 Subject: [PATCH 004/158] Actually clear the cache when alma_user_clear_cache is called --- includes/alma.user.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/alma.user.inc b/includes/alma.user.inc index 304a3b6..8482648 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -70,7 +70,7 @@ function alma_user_profile_form_validate($form, $form_state) { function alma_user_clear_cache($creds=NULL) { - $status = alma_get_patron(); + $status = alma_get_patron($creds, TRUE); } From f64e8ea87917648c7fbd2e49e8e46df742554100 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 14 Nov 2012 12:51:50 +0100 Subject: [PATCH 005/158] Updated codeing style to match Drupal --- alma.install | 18 +- alma.module | 314 ++++++++++++++-------------- includes/alma.availability.inc | 142 ++++++------- includes/alma.debt.inc | 9 +- includes/alma.reservation.inc | 59 +++--- includes/alma.user.inc | 41 ++-- lib/AlmaClient/AlmaClient.class.php | 31 +-- 7 files changed, 308 insertions(+), 306 deletions(-) diff --git a/alma.install b/alma.install index 9f768c4..c7f3647 100644 --- a/alma.install +++ b/alma.install @@ -3,20 +3,12 @@ // Installation and update hooks for Openruth. /** - * Implements hook_update_N. - * update system table set alma weight=10 - * to ensure form_alter hooks are called AFTER ding_user and ding_provider + * Update system table set alma weight=10 to ensure form_alter hooks are called + * AFTER ding_user and ding_provider */ - - function alma_update_7001() { $num_upd = db_update('system') - ->fields(array( - 'weight'=>10, - )) - ->condition('name','alma','=') - ->execute(); - - echo $num_upd; - return t('system weight for alma updated to 10'); + ->fields(array('weight' => 10)) + ->condition('name', 'alma', '=') + ->execute(); } diff --git a/alma.module b/alma.module index 806f1bf..62899bd 100644 --- a/alma.module +++ b/alma.module @@ -10,20 +10,20 @@ define('ALMA_AUTH_BLOCKED', '4e5531951f55ab8f6895684999c69c2'); /** * Get list of pickup branches. */ -function alma_reservation_pickup_branches($account=null) { +function alma_reservation_pickup_branches($account = NULL) { // Throw exception if we're not logged in. ?? WHY this method needs no credentials // ding_user_get_creds($account); // return alma_client_invoke('get_reservation_branches'); - // cache alma pickup branches - they are not likely to change + // Cache alma pickup branches - they are not likely to change static $alma_pickup_branches; if (!isset($alma_pickup_branches) ) { - if ( $cache = cache_get('alma_pickup_branches') ) { - $alma_pickup_branches = unserialize($cache->data); + if ($cache = cache_get('alma_pickup_branches')) { + $alma_pickup_branches = $cache->data; } else { $alma_pickup_branches = alma_client_invoke('get_reservation_branches'); - cache_set( 'alma_pickup_branches', serialize($alma_pickup_branches),'cache'); + cache_set( 'alma_pickup_branches', $alma_pickup_branches, 'cache'); } } return $alma_pickup_branches; @@ -88,6 +88,8 @@ function alma_ding_provider() { * This is a regular form callback. */ function alma_settings_form() { + $form = array(); + $form['alma'] = array( '#type' => 'fieldset', '#title' => t('Alma service settings'), @@ -146,7 +148,6 @@ function alma_client() { // page load. static $client; if (!isset($client)) { - $path = drupal_get_path('module', 'alma'); try { $client = new AlmaClient(variable_get('alma_base_url', '')); } @@ -229,13 +230,13 @@ function alma_get_organisation($reset = FALSE) { } /** - * Implements hook_user_view + * Implements hook_user_view(). */ function alma_user_view($account, $view_mode, $langcode) { try{ $creds = ding_user_get_creds($account); } - catch(DingProviderAuthException $e){ + catch (DingProviderAuthException $e) { return NULL; } if (($userInfo = _alma_user_info($creds)) && isset($userInfo)) { @@ -258,9 +259,10 @@ function alma_user_view($account, $view_mode, $langcode) { $account->content['address'] = array( '#type' => 'item', '#title' => t('Address'), - '#markup' => '

' . join('
',$address_parts) . '

', + '#markup' => '

' . join('
', $address_parts) . '

', ); }; + // @todo: add provider specific fields alma_set_profile2_fields($account); } @@ -287,17 +289,20 @@ function _alma_user_info($creds = NULL) { return $info; } +/** + * Implements hook_profile2_fields(). + */ function alma_set_profile2_fields($account) { - if( !module_exists('profile2') ) { + if (!module_exists('profile2')) { return; } $profile2 = profile2_load_by_user($account, 'provider_alma'); - if( empty($profile2) ) { + if (empty($profile2)) { return; } - // wrapper for profile2-fields + // Wrapper for profile2-fields. $account->content['profile2'] = array( '#type' => 'item', '#title' => t('My library'), @@ -305,109 +310,110 @@ function alma_set_profile2_fields($account) { '#suffix' => '', ); - // set preferred branch - if( $pref_branch = alma_get_preferred_branch( $profile2 ) ) { + // Set preferred branch. + if ($pref_branch = alma_get_preferred_branch($profile2)) { $account->content['profile2']['preferred_branch'] = array( '#type' => 'item', '#title' => t('Pickup branch'), - '#markup' => ''.$pref_branch.'', + '#markup' => '' . $pref_branch . '', ); } - // set interest period - if( $interest_period = alma_get_interest_period($profile2) ) { + // Set interest period. + if ($interest_period = alma_get_interest_period($profile2)) { $account->content['profile2']['interest_period'] = array( '#type' => 'item', '#title' => t('Interest period'), - '#markup' => ''.$interest_period['value'].'', + '#markup' => '' . $interest_period['value'] . '', ); } - // set mobile phone - if( $mob = alma_get_mobile_phone($profile2) ) { + // Set mobile phone. + if ($mob = alma_get_mobile_phone($profile2)) { $account->content['profile2']['mobile'] = array( '#type' => 'item', '#title' => t('Mobile phone'), - '#markup' => ''.$mob.'', + '#markup' => '' . $mob . '', ); } - // set reservation pause - if( $reservation_pause = alma_get_reservation_pause( $profile2 ) ) { - //wrapper for reservation pause - $account->content['profile2']['reservation_pause'] = array( - '#type' => 'item', - '#title' => t('Reservation pause'), - '#prefix' => '
', - '#suffix' => '
', - ); - - $account->content['profile2']['reservation_pause']['start'] = array( - '#type' => 'item', - '#title' => t('Start'), - '#markup' => ''.str_replace('T00:00:00','',$reservation_pause['start']).'', - ); - - $account->content['profile2']['reservation_pause']['stop'] = array( - '#type' => 'item', - '#title' => t('Stop'), - '#markup' => ''.str_replace('T00:00:00','',$reservation_pause['stop']).'', - ); + // Set reservation pause. + if ($reservation_pause = alma_get_reservation_pause($profile2)) { + // Wrapper for reservation pause. + $account->content['profile2']['reservation_pause'] = array( + '#type' => 'item', + '#title' => t('Reservation pause'), + '#prefix' => '
', + '#suffix' => '
', + ); + + $account->content['profile2']['reservation_pause']['start'] = array( + '#type' => 'item', + '#title' => t('Start'), + '#markup' => '' . str_replace('T00:00:00', '', $reservation_pause['start']) . '', + ); + + $account->content['profile2']['reservation_pause']['stop'] = array( + '#type' => 'item', + '#title' => t('Stop'), + '#markup' => '' . str_replace('T00:00:00', '', $reservation_pause['stop']) . '', + ); } } -function alma_get_mobile_phone( $profile2 ) { +function alma_get_mobile_phone($profile2) { $langs = field_language('profile2', $profile2); - if( empty($profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']] ) ) { - return false; + if (empty($profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']])) { + return FALSE; } - $mob = - isset($profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']) ? + $mob = isset($profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']) ? $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'] : FALSE; return $mob; } -function alma_get_reservation_pause($profile2){ - // get field languages +function alma_get_reservation_pause($profile2) { + // Get field languages $langs = field_language('profile2', $profile2); - if( empty($profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']] ) ) { - return false; + if (empty($profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']])) { + return FALSE; } + $res_pause = array(); $res_pause['start'] = $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']; $res_pause['stop'] = $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']; - if( strlen($res_pause['start']) < 2 || strlen($res_pause['stop']) < 2 ) { - return false; + if (drupal_strlen($res_pause['start']) < 2 || drupal_strlen($res_pause['stop']) < 2) { + return FALSE; } return $res_pause; } -function alma_get_interest_period( $profile2 ) { - // get field languages +function alma_get_interest_period($profile2) { + // Get field languages. $langs = field_language('profile2', $profile2); - // get field-info to retrieve values for select list + + // Get field-info to retrieve values for select list. $field_info = field_info_field('field_alma_interest_period'); $interest_period = FALSE; $int_values = isset( $field_info['settings']['allowed_values'] ) ? $field_info['settings']['allowed_values']: FALSE; - if( $int_values ) { + if ($int_values) { $int_period = $profile2->field_alma_interest_period[$langs['field_alma_interest_period']][0]['value']; - $interest_period = isset($int_values[$int_period]) ? array('key'=>$int_period,'value'=>$int_values[$int_period]) : FALSE; + $interest_period = isset($int_values[$int_period]) ? array('key' => $int_period, 'value' => $int_values[$int_period]) : FALSE; } return $interest_period; } function alma_get_preferred_branch( $profile2 ) { - // get field languages + // Get field languages. $langs = field_language('profile2', $profile2); - //get preferred branch + // Get preferred branch. $pref_branch = isset($profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']) ? $profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']:''; @@ -421,98 +427,95 @@ function alma_get_preferred_branch( $profile2 ) { /** * Implements hook_profile2_presave(). * - * Sends changes to Alma + * Sends changes to Alma. */ function alma_profile2_presave($profile2) { - if( !$profile2->type == 'provider_alma' ) { + if (!$profile2->type == 'provider_alma') { return; } - // do not presave when initializing - // @see alma.user/alma_user_profile_init - if( isset($profile2->alma_init) ) { + // Do not presave when initializing. + // @see alma_user_profile_init() + if (isset($profile2->alma_init)) { return; } - // providerfields: field_alma_preferred_branch, field_alma_interest_period, field_alma_reservation_pause; field_alma_mobile_phone + + // Provider fields: field_alma_preferred_branch, field_alma_interest_period, field_alma_reservation_pause; field_alma_mobile_phone. $langs = field_language('profile2', $profile2); - // reservation pause - if( !empty( $profile2->original->field_alma_reservation_pause ) ) { - $start = - isset($profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']) ? - $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value'] : ''; - $start = str_replace('T00:00:00','',$start); + // Reservation pause + if (!empty($profile2->original->field_alma_reservation_pause)) { + $start = isset($profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']) ? + $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value'] : ''; + $start = str_replace('T00:00:00', '', $start); - $stop = - isset($profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']) ? - $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2'] : ''; - $stop = str_replace('T00:00:00','',$stop); + $stop = isset($profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']) ? + $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2'] : ''; + $stop = str_replace('T00:00:00', '', $stop); $org_start = $profile2->original->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']; - $org_start = str_replace('T00:00:00','',$org_start); + $org_start = str_replace('T00:00:00', '', $org_start); $org_stop = $profile2->original->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']; - $org_stop = str_replace('T00:00:00','',$org_stop); + $org_stop = str_replace('T00:00:00', '', $org_stop); - if( $start != $org_start || $stop != $org_stop ) { + if ($start != $org_start || $stop != $org_stop) { $changes['reservation_pause_start'] = $start; $changes['reservation_pause_stop'] = $stop; $changes['absent_id'] = $profile2->field_absent_id[$langs['field_absent_id']][0]['value']; } - } - - // alma_preferred_branch (patronBranch) - if( !empty( $profile2->original->field_alma_preferred_branch ) ) { - $org_branch = $profile2->original->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']; - $new_branch = $profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']; - - if( $org_branch != $new_branch ) { - $changes['preferred_branch'] = $new_branch; - } - } - - //change or remove - if( !empty($profile2->original->field_alma_mobile_phone ) ) { - $org_phone = $profile2->original->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']; - $new_phone = - !empty( $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']) ? - $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'] : - 'DELETE'; - if( $org_phone != $new_phone ) { - $changes['mobile'] = $new_phone; - $changes['phone_id'] = $profile2->field_alma_phone_id[$langs['field_alma_phone_id']][0]['value']; - } - } - // add - elseif( isset( $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'] ) && - !isset( $profile2->original->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'] )) { - $changes['mobile'] = $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']; } + // Alma_preferred_branch (patronBranch). + if (!empty($profile2->original->field_alma_preferred_branch)) { + $org_branch = $profile2->original->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']; + $new_branch = $profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']; + + if ($org_branch != $new_branch) { + $changes['preferred_branch'] = $new_branch; + } + } + + // Change or remove. + if (!empty($profile2->original->field_alma_mobile_phone)) { + $org_phone = $profile2->original->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']; + $new_phone = !empty( $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']) ? + $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'] : + 'DELETE'; + if ($org_phone != $new_phone) { + $changes['mobile'] = $new_phone; + $changes['phone_id'] = $profile2->field_alma_phone_id[$langs['field_alma_phone_id']][0]['value']; + } + } + // Add. + elseif (isset( $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']) && + !isset( $profile2->original->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'] )) { + $changes['mobile'] = $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']; + } - // Interest period ? apparently not an alma parameter.. @todo; check if Interest period should be saved on provider - // update provider - if( isset($changes) ) { - alma_update_provider( $changes,$profile2 ); - } + // Interest period ? apparently not an alma parameter.. @todo; check if Interest period should be saved on provider + // Update provider + if (isset($changes)) { + alma_update_provider($changes, $profile2); + } } function alma_update_provider( $changes, $profile2 ) { - $error_message = t('Error communicating with library system. '); + $error_message = t('Error communicating with library system.'); try { $creds = ding_user_get_creds($profile2); } - catch (Exception $e){ - // rethrow ?? + catch (Exception $e) { + // Re-throw ?? throw $e; } - // mobile phone; add, change, delete + // Mobile phone; add, change, delete. if (isset($changes['phone_id'])) { if ($changes['mobile'] == 'DELETE') { - //delete mobile + // Delete mobile. try { $res = alma_client_invoke('remove_phone_number', $creds['name'], $creds['pass'], $changes['phone_id']); } @@ -522,73 +525,76 @@ function alma_update_provider( $changes, $profile2 ) { if (!$res) { $error_message .= t('mobile not deleted'); - drupal_set_message($error_message,'warning'); + drupal_set_message($error_message, 'warning'); } } else { - //update mobile - try { - $res = alma_client_invoke('change_phone_number', $creds['name'], $creds['pass'], $changes['phone_id'], $changes['mobile']); - } - catch (Exception $e) { - watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); - } - if (!$res) { - $error_message .= t('mobile not updated'); - drupal_set_message($error_message,'warning'); + // Update mobile. + try { + $res = alma_client_invoke('change_phone_number', $creds['name'], $creds['pass'], $changes['phone_id'], $changes['mobile']); + } + catch (Exception $e) { + watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); + } + + if (!$res) { + $error_message .= t('mobile not updated'); + drupal_set_message($error_message, 'warning'); } } } - elseif (isset($changes['mobile'])){ - // add mobile + elseif (isset($changes['mobile'])) { + // Add mobile. try { $res = alma_client_invoke('add_phone_number', $creds['name'], $creds['pass'], $changes['mobile'] ); } - catch (Exception $e){ + catch (Exception $e) { watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); } + if (!$res) { $error_message .= t('mobile not added'); - drupal_set_message($error_message,'warning'); + drupal_set_message($error_message, 'warning'); } } - // update reservation pause (absentPeriod) + // Update reservation pause (absentPeriod). if (!empty( $changes['absent_id']) && !empty($changes['reservation_pause_start']) && !empty( $changes['reservation_pause_stop'])) { try { - $res = alma_client_invoke('change_absent_period',$creds['name'], $creds['pass'], $changes['absent_id'], $changes['reservation_pause_start'],$changes['reservation_pause_stop'] ); + $res = alma_client_invoke('change_absent_period', $creds['name'], $creds['pass'], $changes['absent_id'], $changes['reservation_pause_start'], $changes['reservation_pause_stop']); } - catch(Exception $e){ + catch (Exception $e) { watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); } - if( !$res ) { + + if (!$res) { $error_message .= t('reservation pause not updated'); - drupal_set_message($error_message,'warning'); + drupal_set_message($error_message, 'warning'); } } - // add reservation pause - elseif (!empty($changes['reservation_pause_start']) && - !empty($changes['reservation_pause_stop'])) { + // Add reservation pause. + elseif (!empty($changes['reservation_pause_start']) && !empty($changes['reservation_pause_stop'])) { try { - $res = alma_client_invoke('add_absent_period',$creds['name'], $creds['pass'], $changes['reservation_pause_start'],$changes['reservation_pause_stop']); + $res = alma_client_invoke('add_absent_period', $creds['name'], $creds['pass'], $changes['reservation_pause_start'], $changes['reservation_pause_stop']); } - catch (Exception $e){ + catch (Exception $e) { watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); } + if (!$res) { $error_message .= t('reservation pause not added'); - drupal_set_message($error_message,'warning'); + drupal_set_message($error_message, 'warning'); } } - // delete reservation pause - elseif (!empty( $changes['absent_id'])) { + // Delete reservation pause. + elseif (!empty($changes['absent_id'])) { try { $res = alma_client_invoke('remove_absent_period', $creds['name'], $creds['pass'], $changes['absent_id']); } - catch (Exception $e){ + catch (Exception $e) { watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); } @@ -600,21 +606,21 @@ function alma_update_provider( $changes, $profile2 ) { }*/ } - // update preferred branch (patronBranch) + // Update preferred branch (patronBranch). if (!empty($changes['preferred_branch'])) { try { $res = alma_client_invoke( 'change_patron_preferences' , $creds['name'], $creds['pass'], $changes['preferred_branch']); } - catch(Exception $e){ + catch (Exception $e) { watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); } if (!$res) { $error_message .= t('pickup branch not saved'); - drupal_set_message($error_message,'warning'); + drupal_set_message($error_message, 'warning'); } } - // refresh patron + // Refresh patron. alma_get_patron($creds, TRUE); } @@ -648,13 +654,13 @@ function alma_get_patron($creds = NULL, $reset = FALSE, $as_array = FALSE) { 'mobiles' => isset($info['phones']) ? $info['phones'] : '', 'branch' => $info['preferences']['patron_branch'], 'branchName' => $organisation['branch'][$info['preferences']['patron_branch']], - 'absentPeriods'=>isset($info['absent_periods']) ? $info['absent_periods'] : '', + 'absentPeriods' => isset($info['absent_periods']) ? $info['absent_periods'] : '', ); } - if( $as_array ) { + + if ($as_array) { return $patron; } - return (object) $patron; + return (object)$patron; } - diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index 36c9f25..5323574 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -1,4 +1,5 @@ $record['show_reservation_button'], 'reserved_count' => (int) $record['reservation_count'], 'deferred_period' => FALSE, - - 'is_periodical' => ($record['media_class'] == 'periodical'), + 'is_periodical' => ($record['media_class'] == 'periodical'), ); $total = $total_reservable = 0; // START periodicals - if( $holding['is_periodical'] ) { - $parts = array(); - $holding['holdings'] = array(); - foreach( $record['holdings'] as $volume => $issues ) { - foreach($issues as $issue_no => $holds){ - $issue = array(); - $issue['branches'] = array(); - foreach( $holds as $key => $branch_holding) { - - if( !in_array( $branch_holding['branch_id'], $issue['branches'] ) ) { - $issue['branches'][] = $branch_holding['branch_id']; + if ($holding['is_periodical']) { + $parts = array(); + $holding['holdings'] = array(); + foreach ($record['holdings'] as $volume => $issues) { + foreach ($issues as $issue_no => $holds) { + $issue = array(); + $issue['branches'] = array(); + foreach ($holds as $key => $branch_holding) { + if (!in_array($branch_holding['branch_id'], $issue['branches'])) { + $issue['branches'][] = $branch_holding['branch_id']; + } + + $issue['local_id'] = $branch_holding['reservable']; + $issue['reservable'] = (($branch_holding['status'] == 'availableForLoan') && ((int)$branch_holding['total_count'] - (int)$branch_holding['reference_count'])); + $issues_array[$volume][$issue_no] = $issue; + + if (in_array($branch_holding['collection_id'], array('karens', 'karens-'))) { + $holding['deferred_period'] = TRUE; + } + + $parts = array(); + $total += (int) $branch_holding['total_count']; + // Reservable is total items minus reference (which cannot be + // loaned). + $reservable = (int) $branch_holding['total_count'] - (int) $branch_holding['reference_count']; + $total_reservable += $reservable; + + foreach ($holding_parts as $part) { + if (!empty($branch_holding[$part . '_id'])) { + $parts[] = $org[$part][$branch_holding[$part . '_id']]; + } + } + + if (!empty($branch_holding['shelf_mark'])) { + // Shelf mark might have leading >, strip any and replace the rest + // with the proper arrow. + $parts[] = strtr(trim($branch_holding['shelf_mark'], " >\n\t"), array('>' => '→')); + } + + $parts = array_filter($parts); + + if ($parts && $branch_holding['total_count'] > $branch_holding['checked_out_count']) { + $branch_string = join(' → ', $parts); + $holding['holdings_available'][] = $branch_string; + + if (!in_array($branch_string, $holding['holdings'])) { + $holding['holdings'][] = $branch_string; + } + } + } } + } - $issue['local_id'] = $branch_holding['reservable']; - $issue['reservable'] = (($branch_holding['status'] == 'availableForLoan') && - ((int) $branch_holding['total_count'] - (int) $branch_holding['reference_count'])); - $issues_array[$volume][$issue_no] = $issue; - + if (is_array($holding['holdings'])) { + asort($holding['holdings']); + } + $holding['issues'] = $issues_array; + } // END periodicals + else { + foreach ($record['holdings'] as $branch_holding) { if (in_array($branch_holding['collection_id'], array('karens', 'karens-'))) { - $holding['deferred_period'] = TRUE; + $holding['deferred_period'] = TRUE; } $parts = array(); - $total += (int) $branch_holding['total_count']; + $total += (int)$branch_holding['total_count']; + // Reservable is total items minus reference (which cannot be // loaned). - $reservable = (int) $branch_holding['total_count'] - (int) $branch_holding['reference_count']; + $reservable = (int)$branch_holding['total_count'] - (int) $branch_holding['reference_count']; $total_reservable += $reservable; + foreach ($holding_parts as $part) { - if (!empty($branch_holding[$part . '_id'])) { - $parts[] = $org[$part][$branch_holding[$part . '_id']]; - } + if (!empty($branch_holding[$part . '_id'])) { + $parts[] = $org[$part][$branch_holding[$part . '_id']]; + } } if (!empty($branch_holding['shelf_mark'])) { - // Shelf mark might have leading >, strip any and replace the rest - // with the proper arrow. - $parts[] = strtr(trim($branch_holding['shelf_mark'], " >\n\t"), array('>' => '→')); + // Shelf mark might have leading >, strip any and replace the rest + // with the proper arrow. + $parts[] = strtr(trim($branch_holding['shelf_mark'], " >\n\t"), array('>' => '→')); } $parts = array_filter($parts); if ($parts && $branch_holding['total_count'] > $branch_holding['checked_out_count']) { - $branch_string = join(' → ', $parts); - $holding['holdings_available'][] = $branch_string; - if( !in_array($branch_string,$holding['holdings']) ) { - $holding['holdings'][] = $branch_string; - } + $holding['holdings'][] = join(' → ', $parts); } } } - } - if( is_array($holding['holdings']) ) { - asort($holding['holdings']); - } - $holding['issues'] = $issues_array; - } // END periodicals - - else { - foreach ($record['holdings'] as $branch_holding) { - if (in_array($branch_holding['collection_id'], array('karens', 'karens-'))) { - $holding['deferred_period'] = TRUE; - } - - $parts = array(); - $total += (int) $branch_holding['total_count']; - // Reservable is total items minus reference (which cannot be - // loaned). - $reservable = (int) $branch_holding['total_count'] - (int) $branch_holding['reference_count']; - $total_reservable += $reservable; - foreach ($holding_parts as $part) { - if (!empty($branch_holding[$part . '_id'])) { - $parts[] = $org[$part][$branch_holding[$part . '_id']]; - } - } - - if (!empty($branch_holding['shelf_mark'])) { - // Shelf mark might have leading >, strip any and replace the rest - // with the proper arrow. - $parts[] = strtr(trim($branch_holding['shelf_mark'], " >\n\t"), array('>' => '→')); - } - - $parts = array_filter($parts); - - if ($parts && $branch_holding['total_count'] > $branch_holding['checked_out_count']) { - $holding['holdings'][] = join(' → ', $parts); - } - } - } $holding['reservable_count'] = $total_reservable; $holding['total_count'] = $total; diff --git a/includes/alma.debt.inc b/includes/alma.debt.inc index 609e5e3..d4e874f 100644 --- a/includes/alma.debt.inc +++ b/includes/alma.debt.inc @@ -14,15 +14,14 @@ */ function alma_debt_list($account) { $data = alma_debt_get_debts($account); - $debts = array(); // Create DingProviderDebt instances from Alma's list. foreach ($data['debts'] as $debt) { - $debtObj = new DingProviderDebt($debt['id'], $debt); - - $debts[$debt['id']] = $debtObj; + $debt_object = new DingProviderDebt($debt['id'], $debt); + $debts[$debt['id']] = $debt_object; } + return $debts; } @@ -47,6 +46,6 @@ function alma_debt_payment_received($amount, $debt_ids = array(), $order_id = NU */ function alma_debt_get_debts($account, $reset = FALSE) { $creds = ding_user_get_creds($account); - + return alma_client_invoke('get_debts', $creds['name'], $creds['pass']); } diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 1692f31..27dbcca 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -17,7 +17,7 @@ function alma_reservation_options($type, $account, $reservables) { if (!module_exists('ding_reservation')) { throw new Exception('Alma reservation options requires ding_reservation.'); - } + } $form = array(); $profile = ding_user_provider_profile($account); @@ -25,14 +25,14 @@ function alma_reservation_options($type, $account, $reservables) { $branches = alma_reservation_pickup_branches($account); // @todo; use local branches from issue - some migth not be available in all branches - if(ding_user_is_provider_user($account)) { + if (ding_user_is_provider_user($account)) { $preferred_branch = $profile->alma_preferred_branch[field_language('profile2', $profile, 'alma_preferred_branch')][0]['value']; } else { $preferred_branch = NULL; } - - $form += ding_reservation_default_options_branch($type, 'alma_preferred_branch',$preferred_branch, $branches); + + $form += ding_reservation_default_options_branch($type, 'alma_preferred_branch', $preferred_branch, $branches); return $form; } @@ -42,7 +42,6 @@ function alma_reservation_options($type, $account, $reservables) { * Validate reservations options. */ function alma_reservation_options_validate($type, $account, $reservables, $values) { - $result = array(); $profile = ding_user_provider_profile($account); $field_language = field_language('profile2', $profile); $profile_branch = $profile->alma_preferred_branch[$field_language['alma_preferred_branch']][0]['value']; @@ -120,39 +119,39 @@ function alma_reservation_list($account) { /** * Create a reservation for a given account. */ -function alma_reservation_create($account, $id, $branch, $expiry=null) { +function alma_reservation_create($account, $id, $branch, $expiry = NULL) { $creds = ding_user_get_creds($account); + // Check if the users has this reservation and throw exception. - //if (alma_reservation_exists($creds, $id)) { - if( alma_reservation_exists($account, $id) ){ + if (alma_reservation_exists($account, $id)) { throw new DingProviderReservationExists(); } - $profile2 = profile2_load_by_user($account,'provider_alma'); - if( !empty($profile2) ) { - // interest period - if( !isset($expiry) ) { - // get interest period from profile2 + $profile2 = profile2_load_by_user($account, 'provider_alma'); + if (!empty($profile2)) { + // Interest period. + if (!isset($expiry)) { + // Get interest period from profile2. $interest_period = alma_get_interest_period($profile2); - if( $interest_period ){ - $expiry = REQUEST_TIME + ($interest_period['key'] * 24 * 60 * 60 ); - } - } - if( !isset($expiry) ) { + if ($interest_period) { + $expiry = REQUEST_TIME + ($interest_period['key'] * 24 * 60 * 60 ); + } + } + if (!isset($expiry)) { $expiry = REQUEST_TIME + DING_RESERVATION_DEFAULT_INTEREST_PERIOD; } // preferred branch - if( empty($branch) ) { + if (empty($branch)) { $pref_branch = alma_get_preferred_branch($profile2); - if( $pref_branch ){ - $branches = alma_reservation_pickup_branches(); - foreach($branches as $key => $val){ - if( $val == $pref_branch ) { - $branch = $key; - break; - } - } + if ($pref_branch) { + $branches = alma_reservation_pickup_branches(); + foreach ($branches as $key => $val) { + if ($val == $pref_branch) { + $branch = $key; + break; + } + } } } } @@ -195,7 +194,7 @@ function alma_reservation_create($account, $id, $branch, $expiry=null) { function alma_reservation_update($account, $ids, $options) { $creds = ding_user_get_creds($account); $reservations = alma_reservation_get_reservations($account); - foreach($ids as $id) { + foreach ($ids as $id) { if (isset($reservations[$id])) { $expiry_date = !empty($options['expiry']) ? alma_reservation_format_date($options['expiry']) : $reservations[$id]['valid_to']; $pickup_branch = !empty($options['alma_preferred_branch']) ? $options['alma_preferred_branch'] : $reservations[$id]['pickup_branch']; @@ -219,9 +218,9 @@ function alma_reservation_update($account, $ids, $options) { function alma_reservation_delete($account, $id) { $creds = ding_user_get_creds($account); $reservations = alma_reservation_get_reservations($account); - + alma_reservation_clear_cache(); - if( isset($reservations[$id]) ) { + if (isset($reservations[$id])) { return alma_client_invoke('remove_reservation', $creds['name'], $creds['pass'], $reservations[$id]); } } diff --git a/includes/alma.user.inc b/includes/alma.user.inc index 8482648..348b486 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -22,7 +22,7 @@ function alma_user_authenticate($uid, $pass) { // @todo Check block status. // Set creds. - $return['creds'] = array ( + $return['creds'] = array( 'name' => $uid, 'pass' => $pass, ); @@ -70,7 +70,7 @@ function alma_user_profile_form_validate($form, $form_state) { function alma_user_clear_cache($creds=NULL) { - $status = alma_get_patron($creds, TRUE); + alma_get_patron($creds, TRUE); } @@ -78,16 +78,16 @@ function alma_user_clear_cache($creds=NULL) { * Update profile2 with values from alma patron */ -function alma_user_profile_init( $profile2, $auth_res ){ +function alma_user_profile_init($profile2, $auth_res) { $creds = ding_user_get_creds($profile2); $patron = alma_get_patron($creds); - // reservation pause (absentPeriod) - // apparently alma supports multiple absentPeriods, but for now we handle one only (the first found) + // Reservation pause (absentPeriod). + // pparently alma supports multiple absentPeriods, but for now we handle one only (the first found). // @todo - check if it's correct to handle the first only $langs = field_language('profile2', $profile2); - // reservation pause - if( isset($patron->absentPeriods[0]['from_date']) && isset($patron->absentPeriods[0]['to_date'] ) ) { + // Reservation pause. + if (isset($patron->absentPeriods[0]['from_date']) && isset($patron->absentPeriods[0]['to_date'])) { $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value'] = $patron->absentPeriods[0]['from_date']; $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2'] = $patron->absentPeriods[0]['to_date']; $profile2->field_absent_id[$langs['field_absent_id']][0]['value'] = $patron->absentPeriods[0]['id']; @@ -97,15 +97,15 @@ function alma_user_profile_init( $profile2, $auth_res ){ $profile2->field_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2'] = ' '; } - // preferred_branch + // Preferred_branch. $profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value'] = $patron->branch; - //mobile; also here alma supports multiple phones - again we pick the first + // Mobile; also here alma supports multiple phones - again we pick the first $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'] = isset($patron->mobiles[0]['phone']) ? $patron->mobiles[0]['phone'] : ''; - $profile2->field_alma_phone_id[$langs['field_alma_phone_id']][0]['value'] = isset($patron->mobiles[0]['id']) ? $patron->mobiles[0]['id'] : null; + $profile2->field_alma_phone_id[$langs['field_alma_phone_id']][0]['value'] = isset($patron->mobiles[0]['id']) ? $patron->mobiles[0]['id'] : NULL; //$profile2->field_alma_phone_id[$langs['field_alma_phone_id']][0]['value'] = isset() .. etc - // handle init parameter in alma.module/alma_profile2_presave + // Handle init parameter in alma.module/alma_profile2_presave. $profile2->alma_init = TRUE; $profile2->save(); unset($profile2->alma_init); @@ -119,24 +119,25 @@ function alma_user_profile_init( $profile2, $auth_res ){ function alma_user_account_update($account, $changes) { $creds = ding_user_get_creds($account); - if( isset($changes['mail']) ) { - // add email - if( empty( $account->mail ) && !empty($changes['mail'] ) ) { - $res = alma_client_invoke('add_email_address', $creds['name'], $creds['pass'], $changes['mail']); + if (isset($changes['mail'])) { + // Add email. + if (empty( $account->mail ) && !empty($changes['mail'])) { + $res = alma_client_invoke('add_email_address', $creds['name'], $creds['pass'], $changes['mail']); } - // change email - elseif( isset( $account->mail ) && !empty($changes['mail'] ) ){ - $res = alma_client_invoke('change_email_address', $creds['name'], $creds['pass'], $account->mail, $changes['mail']); + // Change mail. + elseif (isset($account->mail) && !empty($changes['mail'])) { + $res = alma_client_invoke('change_email_address', $creds['name'], $creds['pass'], $account->mail, $changes['mail']); } } - // change password + // Change password. if (isset($changes['pass'])) { $res = alma_client_invoke('change_pin', $creds['name'], $creds['pass'], $changes['pass']); - if( $res ) { + if ($res) { // @see ding_user.module/ding_user_user_presave // Set new password. $creds['pass'] = $changes['pass']; + // Update creds. $result['creds'] = $creds; return $result; diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index c8d6755..14e1d66 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -60,9 +60,9 @@ public function request($method, $params = array(), $check_status = TRUE) { // For use with a non-Drupal-system, we should have a way to swap // logging and logging preferences out. if (variable_get('alma_enable_logging', FALSE)) { - $seconds = floatval(($stopTime[1]+$stopTime[0]) - ($startTime[1]+$startTime[0])); - - // Filter params to avoid logging sensitive data. + $seconds = floatval(($stopTime[1]+$stopTime[0]) - ($startTime[1]+$startTime[0])); + + // Filter params to avoid logging sensitive data. // This can be disabled by setting alma_logging_filter_params = 0. There is no UI for setting this variable // It is intended for settings.php in development environments only. $params = (variable_get('alma_logging_filter_params', 1)) ? self::filter_request_params($params) : $params; @@ -82,7 +82,7 @@ public function request($method, $params = array(), $check_status = TRUE) { } else { $message = $doc->getElementsByTagName('status')->item(0)->getAttribute('key'); - switch($message) { + switch ($message) { case '': case 'borrCardNotFound': throw new AlmaClientBorrCardNotFound('Invalid borrower credentials'); @@ -110,7 +110,7 @@ public function request($method, $params = array(), $check_status = TRUE) { */ private static function filter_request_params($params) { // Scramble sensitive information - $sensitive = array('borrCard', 'pinCode','pinCodeChange', 'address', 'emailAddress'); + $sensitive = array('borrCard', 'pinCode', 'pinCodeChange', 'address', 'emailAddress'); $log_params = array(); foreach ($params as $key => $value) { @@ -118,7 +118,7 @@ private static function filter_request_params($params) { // Replace the value with a scrambled version generated using md5() and // the static salt. This way all requests generated by the same page // load can be grouped - $value = substr(md5($value.self::$salt), 0, strlen($value)); + $value = drupal_substr(md5($value . self::$salt), 0, drupal_strlen($value)); } $log_params[$key] = $value; } @@ -391,7 +391,7 @@ private static function loan_sort($a, $b) { * Get patron's debts. */ public function get_debts($borr_card, $pin_code) { - + $doc = $this->request('patron/debts', array('borrCard' => $borr_card, 'pinCode' => $pin_code)); $data = array( @@ -402,7 +402,7 @@ public function get_debts($borr_card, $pin_code) { if ($debts_attr = $doc->getElementsByTagName('debts')->item(0)) { $data['total_formatted'] = $debts_attr->getAttribute('totalDebtAmountFormatted'); } - + foreach ($doc->getElementsByTagName('debt') as $item) { $id = $item->getAttribute('debtId'); $data['debts'][$id] = array( @@ -519,7 +519,7 @@ public function renew_loan($borr_card, $pin_code, $loan_ids) { ); $doc = $this->request('patron/loans/renew', $params); - + //Built return array as specified by Ding loan provider. //See ding_provider_example_loan_renew_loans(). $reservations = array(); @@ -533,18 +533,21 @@ public function renew_loan($borr_card, $pin_code, $loan_ids) { //Even if this is not the case any error in the current renewal is irrelevant //as the loan has previously been renewed so don't report it as such if ($message == 'isRenewedToday' || $renewable == 'yes') { - $reservations[$id] = TRUE; - } elseif ($message == 'maxNofRenewals') { + $reservations[$id] = TRUE; + } + elseif ($message == 'maxNofRenewals') { $reservations[$id] = t('Maximum number of renewals reached'); - } elseif ($message == 'copyIsReserved') { + } + elseif ($message == 'copyIsReserved') { $reservations[$id] = t('The material is reserved by another loaner'); - } else { + } + else { $reservations[$id] = t('Unable to renew material'); } } } } - + return $reservations; } From 05a9dfe3c81927e92a1ed2dd040d4ec0c3fae54c Mon Sep 17 00:00:00 2001 From: Arni Date: Mon, 10 Dec 2012 11:55:09 +0100 Subject: [PATCH 006/158] Fixes notice when there is no reservation pause in Alma --- includes/alma.user.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/alma.user.inc b/includes/alma.user.inc index 348b486..18c5eca 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -53,7 +53,6 @@ function alma_user_authenticate($uid, $pass) { 'country' => $res['addresses'][0]['country'], ); } - return $return; } @@ -87,7 +86,7 @@ function alma_user_profile_init($profile2, $auth_res) { // @todo - check if it's correct to handle the first only $langs = field_language('profile2', $profile2); // Reservation pause. - if (isset($patron->absentPeriods[0]['from_date']) && isset($patron->absentPeriods[0]['to_date'])) { + if (is_array($patron) && isset($patron->absentPeriods[0]['from_date']) && isset($patron->absentPeriods[0]['to_date'])) { $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value'] = $patron->absentPeriods[0]['from_date']; $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2'] = $patron->absentPeriods[0]['to_date']; $profile2->field_absent_id[$langs['field_absent_id']][0]['value'] = $patron->absentPeriods[0]['id']; From 5f5607f7b225999e0272772f734c001bddbdec81 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 4 Jan 2013 14:53:54 +0100 Subject: [PATCH 007/158] Added ssl_version to alma https requests --- lib/AlmaClient/AlmaClient.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index 14e1d66..bda5bdb 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -55,7 +55,7 @@ public function request($method, $params = array(), $check_status = TRUE) { $startTime = explode(' ', microtime()); // For use with a non-Drupal-system, we should have a way to swap // the HTTP client out. - $request = drupal_http_request(url($this->base_url . $method, array('query' => $params))); + $request = drupal_http_request(url($this->base_url . $method, array('query' => $params)), array('ssl_version' => 'sslv3')); $stopTime = explode(' ', microtime()); // For use with a non-Drupal-system, we should have a way to swap // logging and logging preferences out. From 3f79ea32d762e7eb4b80a88475f9758f59789fac Mon Sep 17 00:00:00 2001 From: yusuf amer Date: Fri, 18 Jan 2013 10:14:12 +0100 Subject: [PATCH 008/158] Added alma_availability_items function to get more availability information. --- includes/alma.availability.inc | 12 ++++++++++++ lib/AlmaClient/AlmaClient.class.php | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index 5323574..3f92ee5 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -1,5 +1,17 @@ request('catalogue/availability', array('catalogueRecordKey' => $alma_ids)); foreach ($doc->getElementsByTagName('catalogueRecord') as $record) { - $data[$record->getAttribute('id')] = ($record->getAttribute('isAvailable') == 'yes') ? TRUE : FALSE; + $data[$record->getAttribute('id')] = array( + 'reservable' => ($record->getAttribute('isReservable') == 'yes') ? TRUE : FALSE, + 'available' => ($record->getAttribute('isAvailable') == 'yes') ? TRUE : FALSE, + ); } return $data; } From df11c61dc95137554460d40afdd674590b131c16 Mon Sep 17 00:00:00 2001 From: yusuf amer Date: Fri, 18 Jan 2013 10:50:15 +0100 Subject: [PATCH 009/158] isReservable from alma is "true" or "false" not "yes" or "no" --- lib/AlmaClient/AlmaClient.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index a908331..62bd502 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -791,7 +791,7 @@ public function get_availability($alma_ids) { $doc = $this->request('catalogue/availability', array('catalogueRecordKey' => $alma_ids)); foreach ($doc->getElementsByTagName('catalogueRecord') as $record) { $data[$record->getAttribute('id')] = array( - 'reservable' => ($record->getAttribute('isReservable') == 'yes') ? TRUE : FALSE, + 'reservable' => ($record->getAttribute('isReservable') == 'true') ? TRUE : FALSE, 'available' => ($record->getAttribute('isAvailable') == 'yes') ? TRUE : FALSE, ); } From 68f18ddb2dbbb2de2a7e0255224efa59a5bf0e1f Mon Sep 17 00:00:00 2001 From: wiredloose Date: Thu, 31 Jan 2013 13:35:01 +0100 Subject: [PATCH 010/158] adding flag for displaying if the record is an internet resource --- includes/alma.availability.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index 5323574..c08497c 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -20,6 +20,7 @@ function alma_availability_holdings($provider_ids) { 'reserved_count' => (int) $record['reservation_count'], 'deferred_period' => FALSE, 'is_periodical' => ($record['media_class'] == 'periodical'), + 'is_internet' => ($record['media_class'] == 'internet'), ); $total = $total_reservable = 0; From 3a60ba15b820883e7f41dd51aee65589628d67ee Mon Sep 17 00:00:00 2001 From: yusuf amer Date: Mon, 4 Feb 2013 15:55:34 +0100 Subject: [PATCH 011/158] Added title to alma_availability_holdings for remote loans. --- includes/alma.availability.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index 5323574..d4d02b2 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -14,6 +14,7 @@ function alma_availability_holdings($provider_ids) { foreach ($details['records'] as $alma_id => $record) { $holding = array( 'local_id' => $alma_id, + 'title' => $record['titles'][0], 'available' => ($record['available_count'] > 0), 'reservable' => $record['show_reservation_button'], 'show_reservation_button' => $record['show_reservation_button'], From eb26e2e182bbc1a49daa05c02a4943ca043e935e Mon Sep 17 00:00:00 2001 From: yusuf amer Date: Tue, 5 Feb 2013 12:55:20 +0100 Subject: [PATCH 012/158] Fixed preferred branch default selection on reservation pop up. --- includes/alma.reservation.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 27dbcca..5ac35b9 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -26,7 +26,7 @@ function alma_reservation_options($type, $account, $reservables) { // @todo; use local branches from issue - some migth not be available in all branches if (ding_user_is_provider_user($account)) { - $preferred_branch = $profile->alma_preferred_branch[field_language('profile2', $profile, 'alma_preferred_branch')][0]['value']; + $preferred_branch = $profile->field_alma_preferred_branch[field_language('profile2', $profile, 'field_alma_preferred_branch')][0]['value']; } else { $preferred_branch = NULL; From 471e3afb0b7a7e1571f963c2e50b048ec4c24263 Mon Sep 17 00:00:00 2001 From: wiredloose Date: Mon, 11 Feb 2013 13:10:31 +0100 Subject: [PATCH 013/158] fixing validation and submit handlers for reservation options following the field name change to 'preferred branch' --- includes/alma.reservation.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 5ac35b9..4e0ccc8 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -44,7 +44,7 @@ function alma_reservation_options($type, $account, $reservables) { function alma_reservation_options_validate($type, $account, $reservables, $values) { $profile = ding_user_provider_profile($account); $field_language = field_language('profile2', $profile); - $profile_branch = $profile->alma_preferred_branch[$field_language['alma_preferred_branch']][0]['value']; + $profile_branch = $profile->field_alma_preferred_branch[$field_language['field_alma_preferred_branch']][0]['value']; return ding_reservation_default_options_branch_validate($type, 'alma_preferred_branch', $profile_branch, $values); } @@ -54,10 +54,10 @@ function alma_reservation_options_validate($type, $account, $reservables, $value function alma_reservation_options_submit($type, $account, $reservables, $values) { $profile = ding_user_provider_profile($account); $field_language = field_language('profile2', $profile); - $profile_branch = $profile->alma_preferred_branch[$field_language['alma_preferred_branch']][0]['value']; + $profile_branch = $profile->field_alma_preferred_branch[$field_language['field_alma_preferred_branch']][0]['value']; $update = ding_reservation_default_options_branch_submit($type, 'alma_preferred_branch', $profile_branch, $values); if (!empty($update['alma_preferred_branch'])) { - $profile->alma_preferred_branch[$field_language['alma_preferred_branch']][0]['value'] = $update['alma_preferred_branch']; + $profile->field_alma_preferred_branch[$field_language['field_alma_preferred_branch']][0]['value'] = $update['alma_preferred_branch']; $profile->save(); } } From 82ce51088f18395b81d042e66479aecd096e74bf Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 19 Mar 2013 10:39:20 +0100 Subject: [PATCH 014/158] Marge alma changes in from artesis --- alma.features.field.inc | 26 +- alma.features.inc | 22 ++ alma.info | 3 +- alma.make | 9 - alma.module | 255 ++++++++++------ includes/alma.availability.inc | 437 ++++++++++++++++++++++------ includes/alma.loan.inc | 3 +- includes/alma.reservation.inc | 56 +++- includes/alma.user.inc | 14 +- lib/AlmaClient/AlmaClient.class.php | 47 ++- 10 files changed, 616 insertions(+), 256 deletions(-) create mode 100644 alma.features.inc delete mode 100644 alma.make diff --git a/alma.features.field.inc b/alma.features.field.inc index 27dcaa0..aef39a9 100644 --- a/alma.features.field.inc +++ b/alma.features.field.inc @@ -89,10 +89,10 @@ function alma_field_default_fields() { 'module' => 'list', 'settings' => array( 'allowed_values' => array( - 30 => '1 month', - 60 => '2 months', - 90 => '3 months', - 180 => '6 months', + 30 => t('1 month'), + 60 => t('2 months'), + 90 => t('3 months'), + 180 => t('6 months'), ), 'allowed_values_function' => '', 'profile2_private' => 0, @@ -114,7 +114,7 @@ function alma_field_default_fields() { 'label' => 'above', 'module' => 'list', 'settings' => array(), - 'type' => 'list_default', + 'type' => 'hidden', 'weight' => '1', ), ), @@ -174,13 +174,13 @@ function alma_field_default_fields() { 'label' => 'above', 'module' => 'text', 'settings' => array(), - 'type' => 'text_default', + 'type' => 'hidden', 'weight' => '3', ), ), 'entity_type' => 'profile2', 'field_name' => 'field_alma_mobile_phone', - 'label' => 'Mobile phone', + 'label' => 'Phone', 'required' => 0, 'settings' => array( 'text_processing' => '0', @@ -291,13 +291,13 @@ function alma_field_default_fields() { 'label' => 'above', 'module' => 'list', 'settings' => array(), - 'type' => 'list_default', + 'type' => 'hidden', 'weight' => '0', ), ), 'entity_type' => 'profile2', 'field_name' => 'field_alma_preferred_branch', - 'label' => 'Alma preferred branch', + 'label' => 'Preferred branch', 'required' => 0, 'settings' => array( 'user_register_form' => FALSE, @@ -356,7 +356,7 @@ function alma_field_default_fields() { 'multiple_number' => '', 'multiple_to' => '', ), - 'type' => 'date_default', + 'type' => 'hidden', 'weight' => '2', ), ), @@ -377,7 +377,7 @@ function alma_field_default_fields() { 'settings' => array( 'display_all_day' => 0, 'increment' => '15', - 'input_format' => 'Y-m-d H:i:s', + 'input_format' => 'd/m/Y', 'input_format_custom' => '', 'label_position' => 'above', 'repeat_collapsed' => 0, @@ -393,9 +393,9 @@ function alma_field_default_fields() { // Translatables // Included for use with string extractors like potx. t('Absent id'); - t('Alma preferred branch'); + t('Preferred branch'); t('Interest period'); - t('Mobile phone'); + t('Phone'); t('Reservation pause'); t('Set your reservations on pause.'); t('phone id'); diff --git a/alma.features.inc b/alma.features.inc new file mode 100644 index 0000000..ce135e7 --- /dev/null +++ b/alma.features.inc @@ -0,0 +1,22 @@ +data; + $alma_pickup_branches = unserialize($cache->data); } else { $alma_pickup_branches = alma_client_invoke('get_reservation_branches'); - cache_set( 'alma_pickup_branches', $alma_pickup_branches, 'cache'); + cache_set('alma_pickup_branches', serialize($alma_pickup_branches), 'cache'); } } return $alma_pickup_branches; } +/** + * Get a list of allowed interest periods. + */ +function alma_get_interest_periods() { + $field_info = field_info_field('field_alma_interest_period'); + $interest_periods = isset($field_info['settings']['allowed_values']) ? $field_info['settings']['allowed_values'] : FALSE; + + return $interest_periods; +} + /** * Implements hook_requirements(). */ @@ -104,6 +114,13 @@ function alma_settings_form() { '#default_value' => variable_get('alma_base_url', ''), ); + $form['alma']['alma_enable_reservation_deletion'] = array( + '#type' => 'checkbox', + '#title' => t('Enable reservation deletion'), + '#default_value' => variable_get('alma_enable_reservation_deletion', FALSE), + '#description' => t('Allow users to delete their reservations as well as ready for pickup ones.'), + ); + $form['alma']['alma_enable_logging'] = array( '#type' => 'checkbox', '#title' => t('Enable logging'), @@ -125,19 +142,28 @@ function alma_form_user_profile_form_alter(&$form, &$form_state) { return; } + global $user; + $profile2 = profile2_load_by_user($user, 'provider_alma'); + // attach profile2 form to user_profile_form. + // profile2 form could be shown by editing people->permissions->profile2, but profile2 adds a tab and we don't want that. + if (ding_user_is_provider_user($user) && $profile2) { + $form_state['profiles'] = array('provider_alma' => $profile2); + profile2_attach_form($form, $form_state); + } + // change size and length of pincode $form['account']['pincode']['#size'] = 32; $form['account']['pincode']['#maxlength'] = 32; + // Hide mobile ID and absent period ID fields + // since they are not relevant for end users. + $form['profile_provider_alma']['field_absent_id']['#access'] = FALSE; + $form['profile_provider_alma']['field_alma_phone_id']['#access'] = FALSE; + // @todo; WHAT are the rules for alma pincode // HOW do we validate - - // custom validator ?? maybe pincode validator ?? - // $form['#validate'][] = 'alma_profile_form_validate'; } - - /** * Return a fully instantiated AlmaClient instance. */ @@ -214,7 +240,7 @@ function alma_get_organisation($reset = FALSE) { 'location' => alma_client_invoke('get_locations'), 'sublocation' => alma_client_invoke('get_sublocations'), 'collection' => alma_client_invoke('get_collections'), - 'reservation' => alma_reservation_pickup_branches(),//alma_client_invoke('get_reservation_branches'), + 'reservation' => alma_reservation_pickup_branches(), //alma_client_invoke('get_reservation_branches'), ); // Cache output for 24 hours if we got all the data correctly. @@ -233,13 +259,14 @@ function alma_get_organisation($reset = FALSE) { * Implements hook_user_view(). */ function alma_user_view($account, $view_mode, $langcode) { - try{ + try { $creds = ding_user_get_creds($account); } catch (DingProviderAuthException $e) { return NULL; } - if (($userInfo = _alma_user_info($creds)) && isset($userInfo)) { + + if (($userInfo = _alma_user_info($creds)) && isset($userInfo)) { foreach ($userInfo as $key => $prop) { $data[$key] = isset($prop) ? $prop : ''; } @@ -248,20 +275,21 @@ function alma_user_view($account, $view_mode, $langcode) { '#type' => 'item', '#title' => t('Name'), '#markup' => $data['firstname'], + '#weight' => -1, ); - $address_parts = array($data['address']); - if (!empty($data['postal']) || !empty($data['city'])) { - $address_parts[] = join('
', array_filter(array($data['postal'], $data['city']))); + if (!empty($data['address']) || !empty($data['postal']) || !empty($data['city'])) { + $address_parts = array(); + $address_parts[] = join('
', array_filter(array($data['address'], $data['postal'], $data['city']))); + // @todo: really, there should be a template for this. + $account->content['address'] = array( + '#type' => 'item', + '#title' => t('Address'), + '#markup' => '

' . $data['address'] . '
' . $data['postal'] . ' ' . $data['city'] . '

', + '#weight' => 0, + ); } - - // @todo: really, there should be a template for this. - $account->content['address'] = array( - '#type' => 'item', - '#title' => t('Address'), - '#markup' => '

' . join('
', $address_parts) . '

', - ); - }; + } // @todo: add provider specific fields alma_set_profile2_fields($account); @@ -305,7 +333,6 @@ function alma_set_profile2_fields($account) { // Wrapper for profile2-fields. $account->content['profile2'] = array( '#type' => 'item', - '#title' => t('My library'), '#prefix' => '
', '#suffix' => '
', ); @@ -340,9 +367,14 @@ function alma_set_profile2_fields($account) { // Set reservation pause. if ($reservation_pause = alma_get_reservation_pause($profile2)) { // Wrapper for reservation pause. + $start = str_replace('T00:00:00', '', $reservation_pause['start']); + $start = format_date(strtotime($start), 'custom', 'd/m/Y'); + $stop = str_replace('T00:00:00', '', $reservation_pause['stop']); + $stop = format_date(strtotime($stop), 'custom', 'd/m/Y'); + $account->content['profile2']['reservation_pause'] = array( '#type' => 'item', - '#title' => t('Reservation pause'), + '#title' => '

' . t('Reservation pause') . '

', '#prefix' => '
', '#suffix' => '
', ); @@ -350,13 +382,13 @@ function alma_set_profile2_fields($account) { $account->content['profile2']['reservation_pause']['start'] = array( '#type' => 'item', '#title' => t('Start'), - '#markup' => '' . str_replace('T00:00:00', '', $reservation_pause['start']) . '', + '#markup' => '' . $start . '', ); $account->content['profile2']['reservation_pause']['stop'] = array( '#type' => 'item', '#title' => t('Stop'), - '#markup' => '' . str_replace('T00:00:00', '', $reservation_pause['stop']) . '', + '#markup' => '' . $stop . '', ); } } @@ -368,10 +400,11 @@ function alma_get_mobile_phone($profile2) { return FALSE; } - $mob = isset($profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']) ? - $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'] : FALSE; + if (isset($profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'])) { + return $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']; + } - return $mob; + return FALSE; } function alma_get_reservation_pause($profile2) { @@ -401,7 +434,7 @@ function alma_get_interest_period($profile2) { $field_info = field_info_field('field_alma_interest_period'); $interest_period = FALSE; - $int_values = isset( $field_info['settings']['allowed_values'] ) ? $field_info['settings']['allowed_values']: FALSE; + $int_values = isset($field_info['settings']['allowed_values']) ? $field_info['settings']['allowed_values'] : FALSE; if ($int_values) { $int_period = $profile2->field_alma_interest_period[$langs['field_alma_interest_period']][0]['value']; $interest_period = isset($int_values[$int_period]) ? array('key' => $int_period, 'value' => $int_values[$int_period]) : FALSE; @@ -409,14 +442,14 @@ function alma_get_interest_period($profile2) { return $interest_period; } -function alma_get_preferred_branch( $profile2 ) { +function alma_get_preferred_branch($profile2) { // Get field languages. $langs = field_language('profile2', $profile2); // Get preferred branch. $pref_branch = isset($profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']) ? - $profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']:''; + $profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value'] : ''; $branches = alma_reservation_pickup_branches(); $pref = isset($branches[$pref_branch]) ? $branches[$pref_branch] : FALSE; @@ -433,65 +466,76 @@ function alma_profile2_presave($profile2) { if (!$profile2->type == 'provider_alma') { return; } - // Do not presave when initializing. - // @see alma_user_profile_init() + + // Do not presave when initializing + // @see alma.user/alma_user_profile_init if (isset($profile2->alma_init)) { return; } - // Provider fields: field_alma_preferred_branch, field_alma_interest_period, field_alma_reservation_pause; field_alma_mobile_phone. + // Provider fields: field_alma_preferred_branch, field_alma_interest_period, field_alma_reservation_pause; field_alma_mobile_phone $langs = field_language('profile2', $profile2); // Reservation pause - if (!empty($profile2->original->field_alma_reservation_pause)) { - $start = isset($profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']) ? - $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value'] : ''; - $start = str_replace('T00:00:00', '', $start); - - $stop = isset($profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']) ? - $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2'] : ''; - $stop = str_replace('T00:00:00', '', $stop); - - $org_start = $profile2->original->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']; - $org_start = str_replace('T00:00:00', '', $org_start); - - $org_stop = $profile2->original->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']; - $org_stop = str_replace('T00:00:00', '', $org_stop); - - if ($start != $org_start || $stop != $org_stop) { - $changes['reservation_pause_start'] = $start; - $changes['reservation_pause_stop'] = $stop; - $changes['absent_id'] = $profile2->field_absent_id[$langs['field_absent_id']][0]['value']; - } - } - - // Alma_preferred_branch (patronBranch). + $start = empty($profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']) + ? '' : $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']; + $start = str_replace('T00:00:00', '', $start); + $stop = empty($profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']) + ? '' : $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']; + $stop = str_replace('T00:00:00', '', $stop); + + $org_start = empty($profile2->original->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']) + ? '' : $profile2->original->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']; + $org_start = str_replace('T00:00:00', '', $org_start); + $org_stop = empty($profile2->original->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']) + ? '' : $profile2->original->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']; + $org_stop = str_replace('T00:00:00', '', $org_stop); + + if ($start != $org_start || $stop != $org_stop) { + $changes['reservation_pause_start'] = $start; + $changes['reservation_pause_stop'] = $stop; + $changes['absent_id'] = empty($profile2->field_absent_id[$langs['field_absent_id']][0]['value']) ? + '' : $profile2->field_absent_id[$langs['field_absent_id']][0]['value']; + } + + // alma_preferred_branch (patronBranch) if (!empty($profile2->original->field_alma_preferred_branch)) { $org_branch = $profile2->original->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']; $new_branch = $profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']; - if ($org_branch != $new_branch) { $changes['preferred_branch'] = $new_branch; } } - // Change or remove. + // Mobile phone + // If present - update. if (!empty($profile2->original->field_alma_mobile_phone)) { $org_phone = $profile2->original->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']; - $new_phone = !empty( $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']) ? - $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'] : - 'DELETE'; + $new_phone = empty($profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']) + ? 'DELETE' : $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']; if ($org_phone != $new_phone) { $changes['mobile'] = $new_phone; $changes['phone_id'] = $profile2->field_alma_phone_id[$langs['field_alma_phone_id']][0]['value']; } } - // Add. - elseif (isset( $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']) && - !isset( $profile2->original->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'] )) { + // If not - add new one. + elseif (!empty($profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']) + && empty($profile2->original->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'])) { $changes['mobile'] = $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']; } + // Alma_preferred_branch (patronBranch). + if (!empty($profile2->original->field_alma_preferred_branch)) { + $org_branch = $profile2->original->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']; + $new_branch = $profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']; + } + + // Interest period ? apparently not an alma parameter.. @todo; check if Interest period should be saved on provider + + // Update provider + if (isset($changes)) { + alma_update_provider($changes, $profile2); + } // Interest period ? apparently not an alma parameter.. @todo; check if Interest period should be saved on provider @@ -501,8 +545,8 @@ function alma_profile2_presave($profile2) { } } -function alma_update_provider( $changes, $profile2 ) { - $error_message = t('Error communicating with library system.'); +function alma_update_provider($changes, $profile2) { + $error_message = t('Error communicating with library system. '); try { $creds = ding_user_get_creds($profile2); @@ -523,8 +567,8 @@ function alma_update_provider( $changes, $profile2 ) { watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); } - if (!$res) { - $error_message .= t('mobile not deleted'); + if (empty($res)) { + $error_message .= t('phone not deleted'); drupal_set_message($error_message, 'warning'); } } @@ -546,12 +590,11 @@ function alma_update_provider( $changes, $profile2 ) { 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']); } catch (Exception $e) { watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); } - if (!$res) { $error_message .= t('mobile not added'); drupal_set_message($error_message, 'warning'); @@ -569,22 +612,20 @@ function alma_update_provider( $changes, $profile2 ) { catch (Exception $e) { watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); } - - if (!$res) { + if (empty($res)) { $error_message .= t('reservation pause not updated'); drupal_set_message($error_message, 'warning'); } } - // Add reservation pause. - elseif (!empty($changes['reservation_pause_start']) && !empty($changes['reservation_pause_stop'])) { + // Add reservation pause + elseif (!empty($changes['reservation_pause_start']) && !empty($changes['reservation_pause_stop'])) { try { $res = alma_client_invoke('add_absent_period', $creds['name'], $creds['pass'], $changes['reservation_pause_start'], $changes['reservation_pause_stop']); } catch (Exception $e) { watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); } - - if (!$res) { + if (empty($res)) { $error_message .= t('reservation pause not added'); drupal_set_message($error_message, 'warning'); } @@ -600,28 +641,31 @@ function alma_update_provider( $changes, $profile2 ) { // this one actually deletes the reservation pause, but returns an error ?? // for now disable messages...@todo; fix it. - /* if( !$res ) { - $error_message .= t('reservation pause not deleted'); - drupal_set_message($error_message,'warning'); - }*/ + /* if(!$res) { + $error_message .= t('reservation pause not deleted'); + drupal_set_message($error_message,'warning'); + } */ } // Update preferred branch (patronBranch). if (!empty($changes['preferred_branch'])) { try { - $res = alma_client_invoke( 'change_patron_preferences' , $creds['name'], $creds['pass'], $changes['preferred_branch']); + $res = alma_client_invoke('change_patron_preferences', $creds['name'], $creds['pass'], $changes['preferred_branch']); } catch (Exception $e) { watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); } - if (!$res) { + if (empty($res)) { $error_message .= t('pickup branch not saved'); drupal_set_message($error_message, 'warning'); } } - // Refresh patron. - alma_get_patron($creds, TRUE); + // Refresh patron and update profile field IDs from response. + $info = alma_client_invoke('get_patron_info', $creds['name'], $creds['pass'], TRUE); + $langs = field_language('profile2', $profile2); + $profile2->field_alma_phone_id[$langs['field_alma_phone_id']][0]['value'] = empty($info['phones'][0]['id']) ? NULL : $info['phones'][0]['id']; + $profile2->field_absent_id[$langs['field_absent_id']][0]['value'] = empty($info['absent_periods'][0]['id']) ? NULL : $info['absent_periods'][0]['id']; } /** @@ -657,10 +701,47 @@ function alma_get_patron($creds = NULL, $reset = FALSE, $as_array = FALSE) { 'absentPeriods' => isset($info['absent_periods']) ? $info['absent_periods'] : '', ); } - if ($as_array) { return $patron; } return (object)$patron; } + +/** + * Replace entity for the reservation in the case object in not in Ting anymore. + * + * @param $item + * Provider reservation object. + * @return + * Ting entity object, filled with data from provider service. + */ +function alma_replace_entity($item) { + $faust_number = explode(':', $item->ding_entity_id); + $faust_number = $faust_number[1]; + $alma_object = alma_client_invoke('catalogue_record_detail', $faust_number); + + if ($alma_object['request_status'] == 'ok' && isset($alma_object['records'][$faust_number])) { + $source = $alma_object['records'][$faust_number]; + $pseudo_ting_object = new TingEntity(); + $pseudo_ting_object->localId = $faust_number; + $pseudo_ting_object->ding_entity_id = $item->ding_entity_id; + $pseudo_ting_object->reply = new TingClientObject(); + $pseudo_ting_object->reply->record['dc:title']['dkdcplus:full'] = array($source['titles'][0]); + $pseudo_ting_object->reply->record['dc:type']['dkdcplus:BibDK-Type'] = array($source['media_class']); + // @todo + // Author from provider. + $pseudo_ting_object->reply->record['dc:creator']['dkdcplus:aut'] = array(''); + $pseudo_ting_object->reply->record['dc:date'][''] = array($source['publication_year']); + $pseudo_ting_object->ting_title = array(LANGUAGE_NONE => array(array('id' => $item->ding_entity_id))); + $pseudo_ting_object->ting_type = array(LANGUAGE_NONE => array(array('id' => $item->ding_entity_id))); + $pseudo_ting_object->ting_author = array(LANGUAGE_NONE => array(array('id' => $item->ding_entity_id))); + $pseudo_ting_object->ting_cover = array(LANGUAGE_NONE => array(array('local_id' => $faust_number))); + $pseudo_ting_object->ding_entity_type = 'ding_entity'; + $pseudo_ting_object->provider_id = $faust_number; + + return $pseudo_ting_object; + } + + return FALSE; +} diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index c08497c..6a06ab9 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -5,11 +5,9 @@ */ function alma_availability_holdings($provider_ids) { $ids = join(',', $provider_ids); - - $holding_parts = array('branch', 'department', 'location', 'sublocation', 'collection'); $details = alma_client_invoke('catalogue_record_detail', $ids); - $org = alma_get_organisation(); $result = array(); + if ($details && isset($details['records'])) { foreach ($details['records'] as $alma_id => $record) { $holding = array( @@ -17,112 +15,357 @@ function alma_availability_holdings($provider_ids) { 'available' => ($record['available_count'] > 0), 'reservable' => $record['show_reservation_button'], 'show_reservation_button' => $record['show_reservation_button'], + 'holdings' => $record['holdings'], + 'holdings_available' => array(), 'reserved_count' => (int) $record['reservation_count'], 'deferred_period' => FALSE, + 'issues' => _alma_populate_issues($record['holdings']), 'is_periodical' => ($record['media_class'] == 'periodical'), 'is_internet' => ($record['media_class'] == 'internet'), ); - $total = $total_reservable = 0; - - // START periodicals - if ($holding['is_periodical']) { - $parts = array(); - $holding['holdings'] = array(); - foreach ($record['holdings'] as $volume => $issues) { - foreach ($issues as $issue_no => $holds) { - $issue = array(); - $issue['branches'] = array(); - foreach ($holds as $key => $branch_holding) { - if (!in_array($branch_holding['branch_id'], $issue['branches'])) { - $issue['branches'][] = $branch_holding['branch_id']; - } - - $issue['local_id'] = $branch_holding['reservable']; - $issue['reservable'] = (($branch_holding['status'] == 'availableForLoan') && ((int)$branch_holding['total_count'] - (int)$branch_holding['reference_count'])); - $issues_array[$volume][$issue_no] = $issue; - - if (in_array($branch_holding['collection_id'], array('karens', 'karens-'))) { - $holding['deferred_period'] = TRUE; - } - - $parts = array(); - $total += (int) $branch_holding['total_count']; - // Reservable is total items minus reference (which cannot be - // loaned). - $reservable = (int) $branch_holding['total_count'] - (int) $branch_holding['reference_count']; - $total_reservable += $reservable; - - foreach ($holding_parts as $part) { - if (!empty($branch_holding[$part . '_id'])) { - $parts[] = $org[$part][$branch_holding[$part . '_id']]; - } - } - - if (!empty($branch_holding['shelf_mark'])) { - // Shelf mark might have leading >, strip any and replace the rest - // with the proper arrow. - $parts[] = strtr(trim($branch_holding['shelf_mark'], " >\n\t"), array('>' => '→')); - } - - $parts = array_filter($parts); - - if ($parts && $branch_holding['total_count'] > $branch_holding['checked_out_count']) { - $branch_string = join(' → ', $parts); - $holding['holdings_available'][] = $branch_string; - - if (!in_array($branch_string, $holding['holdings'])) { - $holding['holdings'][] = $branch_string; - } - } - } - } + $result[$alma_id] = $holding; + + $result[$alma_id]['html'] = _alma_get_holdings($details, $holding['is_periodical']); + } + } + return $result; + +} + +/** + * @param type $res; returned array from alma_client class + * @param type $is_periodical; Boolean that indicates whether the shown record is a periodical or not + * @return html to be shown. Returns FALSE if no data is received from alma_client class + */ +function _alma_get_holdings($res, $is_periodical = FALSE) { + if (isset($res['records'])) { + if ($is_periodical) { + return _alma_set_holdings_periodical($res); + } + else { + return _alma_set_holdings($res); + } + } + else { + return FALSE; + } +} + +/** + * set holdings for all kinds of material except periodicals + * @param array $res + * @return array $result; + */ +function _alma_set_holdings($res) { + $holdings = array(); + $reservation_count = 0; + foreach ($res['records'] as $alma_id => $records) { + $reservation_count += (int) $records['reservation_count']; + foreach ($records['holdings'] as $holding) { + $holdings[] = $holding; + } + } + + $result = _alma_set_table_html($holdings, $reservation_count); + return $result; +} + +/** + * set holdings if material is periodical only + * @param array $res + * @return array $result + */ +function _alma_set_holdings_periodical($res) { + $holdings = array(); + $reservation_count = 0; + foreach ($res['records'] as $alma_id => $records) { + $reservation_count += (int) $records['reservation_count']; + foreach ($records['holdings'] as $holding => $issue_year) { + foreach ($issue_year as $key) { + $holdings[] = $key[0]; + } + } + } + + $result = _alma_set_table_html($holdings, $reservation_count); + return $result; +} +/** + * Make the html-table + * @params $h; holding information for a given material + * @return html-table + */ +function _alma_set_table_html($h, $r_count) { + // Set a classname for styling the table. + $variables['attributes'] = array( + 'class' => array( + drupal_html_class('availability_holdings_table') + ), + ); + + // Set table header. + $variables['header'] = array( + 'placement' => t('Placement'), + 'copies' => t('Copies'), + 'home' => t('At home'), + 'not_for_loan' => t('Not for loan'), + 'checked_out' => t('Checked out'), + ); + + // Set table rows. + $variables['rows'] = _alma_set_rows($h); + + // Set last row with reservation count. + $row = array(); + $row['data']['Library'] = t('Reservations'); + $row['data']['Copies'] = array('data' => $r_count, 'colspan' => 4); + $variables['rows'][] = $row; + + // Theme the table. + $html = theme('table', $variables); + + return $html; +} + +/** + * set rows in table for given holdings + * @param $h; holding information for a given material + * @return array; + */ +function _alma_set_rows($h) { + $rows = array(); + $org = alma_get_organisation(); + + $copies_total = 0; + $home_total = 0; + $not_for_loan_total = 0; + $checked_out_total = 0; + + foreach ($h as $key => $data) { + $row = array(); + + if (!empty($data['branch_id'])) { + $row['placement'][] = $org['branch'][$data['branch_id']]; + } + + if (!empty($data['department_id'])) { + $row['placement'][] = $org['department'][$data['department_id']]; + } + + if (!empty($data['location_id'])) { + $row['placement'][] = $org['location'][$data['location_id']]; + } + + if (!empty($data['sublocation_id'])) { + $row['placement'][] = $org['sublocation'][$data['sublocation_id']]; + } + + if (!empty($data['shelf_mark'])) { + $row['placement'][] = $data['shelf_mark']; + } + + $row['placement'] = implode(' > ', $row['placement']); + + $row['copies'] = isset($data['total_count']) ? (int)$data['total_count'] : 0; + $copies_total += $row['copies']; + + $row['home'] = isset($data['available_count']) ? (int)$data['available_count'] : 0; + $home_total += $row['home']; + + $row['not_for_loan'] = isset($data['reference_count']) ? (int)$data['reference_count'] : 0; + $not_for_loan_total += $row['not_for_loan']; + + $row['checked_out'] = isset($data['checked_out_count']) ? (int)$data['checked_out_count'] : 0; + $checked_out_total += $row['checked_out']; + + $rows[] = $row; + } + + if (count($rows) >= 1) { + $rows = _clean_up_rows($rows); + } + // Adding row - totals + $row = array(); + $row['data']['Library'] = t('Total'); + $row['data']['Copies'] = $copies_total; + $row['data']['Home'] = $home_total; + $row['data']['Not for loan'] = $not_for_loan_total; + $row['data']['Checked out'] = $checked_out_total; + $row['class'] = array(drupal_html_class('availability_holdings_last_row')); + $rows[] = $row; + + return $rows; +} + +/** + * if the same placement exists several times collect them in one line + * @param array + * @return array; + */ +function _clean_up_rows($_rows) { + $rows = array(); + $placements = array(); + + foreach ($_rows as $row) { + $currkey = $row['placement']; + if (!in_array($currkey, $placements)) { + $placements[] = $currkey; + $placementsarr = _get_placements_with_key($_rows, $currkey); + $this_row = _sum_placement($placementsarr); + $rows[] = $this_row; + } + } + return $rows; +} + +/** + * collect materials with the same placement + * @param array $_rows + * @param String $currkey + * @return array $rows; + */ +function _get_placements_with_key($_rows, $currkey) { + $rows = array(); + foreach ($_rows as $key) { + if ($key['placement'] == $currkey) { + $rows[] = $key; + } + } + return $rows; +} +/** + * sum material for same placement in one row + * @param $placementsarr; array with all instances of the same placement - ie. 'Hovedbiblioteket' + * @return array; $row + */ +function _sum_placement($placementsarr) { + $row = $placementsarr[0]; + for ($i = 1; $i < count($placementsarr); $i++) { + $next_row = $placementsarr[$i]; + $row['copies'] += $next_row['copies']; + $row['home'] += $next_row['home']; + $row['not_for_loan'] += $next_row['not_for_loan']; + $row['checked_out'] += $next_row['checked_out']; + } + return $row; +} + +/** + * Fill in the issues data, useful for periodical availability. + * + * This method takes into consideration the repeating placements, + * and aggregates them, suming the numeric data. + * + * @param $input + * Holdings data, as returned from the web-servce. + * @return + * An array, with the following keys: + * - Issue year. + * - Issue number. + * - local_id: Periodical identifier. + * - provider: Provider identifier, 'alma' here. + * - placement: Item placement info. + * - location: Actual location string. + * - ordered_count + * - checked_out_count + * - reference_count + * - total_count + * - available_count + * - reservable + */ +function _alma_populate_issues($input) { + $org = alma_get_organisation(); + $output = array(); + $placement = array(); + $prev_hash = ''; + + // Numeric info about the issue. + $ordered_count = 0; + $checked_out_count = 0; + $reference_count = 0; + $total_count = 0; + $available_count = 0; + + $i = -1; + // Loop through volumes. + foreach ($input as $year => $volume) { + // Loop through issues. + foreach ($volume as $key => $issues) { + $ordered_count = 0; + $checked_out_count = 0; + $reference_count = 0; + $total_count = 0; + $available_count = 0; + $output[$year][$key]['local_id'] = $issues[0]['reservable']; + $output[$year][$key]['provider'] = 'alma'; + $i = 0; + // Loop though placements. + foreach ($issues as $copy) { + $placement = array(); + $branch_id = !empty($copy['branch_id']) ? $copy['branch_id'] : ''; + $department_id = !empty($copy['department_id']) ? $copy['department_id'] : ''; + $location_id = !empty($copy['location_id']) ? $copy['location_id'] : ''; + $sublocation_id = !empty($copy['sublocation_id']) ? $copy['sublocation_id'] : ''; + $shelf_mark = !empty($copy['shelf_mark']) ? $copy['shelf_mark'] : ''; + + if (!empty($branch_id)) { + $placement[] = $org['branch'][$branch_id]; } - if (is_array($holding['holdings'])) { - asort($holding['holdings']); + if (!empty($department_id)) { + $placement[] = $org['department'][$department_id]; } - $holding['issues'] = $issues_array; - } // END periodicals - else { - foreach ($record['holdings'] as $branch_holding) { - if (in_array($branch_holding['collection_id'], array('karens', 'karens-'))) { - $holding['deferred_period'] = TRUE; - } - - $parts = array(); - $total += (int)$branch_holding['total_count']; - - // Reservable is total items minus reference (which cannot be - // loaned). - $reservable = (int)$branch_holding['total_count'] - (int) $branch_holding['reference_count']; - $total_reservable += $reservable; - - foreach ($holding_parts as $part) { - if (!empty($branch_holding[$part . '_id'])) { - $parts[] = $org[$part][$branch_holding[$part . '_id']]; - } - } - - if (!empty($branch_holding['shelf_mark'])) { - // Shelf mark might have leading >, strip any and replace the rest - // with the proper arrow. - $parts[] = strtr(trim($branch_holding['shelf_mark'], " >\n\t"), array('>' => '→')); - } - - $parts = array_filter($parts); - - if ($parts && $branch_holding['total_count'] > $branch_holding['checked_out_count']) { - $holding['holdings'][] = join(' → ', $parts); - } + + if (!empty($location_id)) { + $placement[] = $org['location'][$location_id]; } - } - $holding['reservable_count'] = $total_reservable; - $holding['total_count'] = $total; - $result[$alma_id] = $holding; + if (!empty($sublocation_id)) { + $placement[] = $org['sublocation'][$sublocation_id]; + } + + if (!empty($shelf_mark)) { + $placement[] = $shelf_mark; + } + + $placement_string = implode(' > ', $placement); + + // A hash value, used for recognizing differences in placement. + $hash = md5($branch_id . $department_id . $location_id . $sublocation_id . $shelf_mark); + + // Whether it's a new placement, start a new count and increment the + // row counter. + if ($hash !== $prev_hash) { + $prev_hash = $hash; + $ordered_count = 0; + $checked_out_count = 0; + $reference_count = 0; + $total_count = 0; + $available_count = 0; + $i++; + } + + // The numeric data keeps summing each other, until + // we get a new placement. + $ordered_count += $copy['ordered_count']; + $checked_out_count += $copy['checked_out_count']; + $reference_count += $copy['reference_count']; + $total_count += $copy['total_count']; + $available_count += $copy['available_count']; + + $output[$year][$key]['placement'][$i] = array( + 'location' => $placement_string, + 'ordered_count' => $ordered_count, + 'checked_out_count' => $checked_out_count, + 'reference_count' => $reference_count, + 'total_count' => $total_count, + 'available_count' => $available_count, + 'reservable' => ($copy['status'] === 'availableForLoan') ? TRUE : FALSE, + ); + } } } - return $result; + return $output; } diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index c5a0179..7b11aeb 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -18,7 +18,8 @@ function alma_loan_list($account) { try { // Get all loans form alma for the user account given. $loans = alma_client_invoke('get_loans', $creds['name'], $creds['pass']); - } catch (Exception $e) { + } + catch (Exception $e) { throw new DingProviderLoanUserError($e->getMessage()); } diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 4e0ccc8..d1f5ed2 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -22,17 +22,21 @@ function alma_reservation_options($type, $account, $reservables) { $form = array(); $profile = ding_user_provider_profile($account); - $branches = alma_reservation_pickup_branches($account); + $branches = alma_reservation_pickup_branches($account); + $periods = alma_get_interest_periods(); // @todo; use local branches from issue - some migth not be available in all branches if (ding_user_is_provider_user($account)) { $preferred_branch = $profile->field_alma_preferred_branch[field_language('profile2', $profile, 'field_alma_preferred_branch')][0]['value']; + $interest_period = $profile->field_alma_interest_period[field_language('profile2', $profile, 'field_alma_interest_period')][0]['value']; } else { $preferred_branch = NULL; + $interest_period = NULL; } $form += ding_reservation_default_options_branch($type, 'alma_preferred_branch', $preferred_branch, $branches); + $form += ding_reservation_interest_period_selector($type, 'alma_interest_period', $interest_period, $periods); return $form; } @@ -45,7 +49,20 @@ function alma_reservation_options_validate($type, $account, $reservables, $value $profile = ding_user_provider_profile($account); $field_language = field_language('profile2', $profile); $profile_branch = $profile->field_alma_preferred_branch[$field_language['field_alma_preferred_branch']][0]['value']; - return ding_reservation_default_options_branch_validate($type, 'alma_preferred_branch', $profile_branch, $values); + $interest_period = $profile->field_alma_interest_period[$field_language['field_alma_interest_period']][0]['value']; + // Perform a check to whether a show specific select dropdown. + // Returning NULL means to skip this check, therefore to reserve instantly. + if (!empty($profile_branch) && !empty($interest_period) && $type == 'create') { + return array( + 'alma_preferred_branch' => $profile_branch, + 'alma_interest_period' => $interest_period, + ); + } + else { + $branch_valid = ding_reservation_default_options_branch_validate($type, 'alma_preferred_branch', $profile_branch, $values); + $period_valid = ding_reservation_default_options_interest_period_validate($type, 'alma_interest_period', $interest_period, $values); + return array_merge($branch_valid, $period_valid); + } } /** @@ -98,6 +115,7 @@ function alma_reservation_list($account) { 'expiry' => $reservation['valid_to'], 'queue_number' => $reservation['queue_number'], 'ready_for_pickup' => 1, + 'notes' => isset($reservation['notes']) ? $reservation['notes'] : '', )); } else { @@ -109,6 +127,7 @@ function alma_reservation_list($account) { 'expiry' => $reservation['valid_to'], 'queue_number' => $reservation['queue_number'], 'ready_for_pickup' => 0, + 'notes' => isset($reservation['notes']) ? $reservation['notes'] : '', )); } } @@ -116,7 +135,7 @@ function alma_reservation_list($account) { return $result; } - /** +/** * Create a reservation for a given account. */ function alma_reservation_create($account, $id, $branch, $expiry = NULL) { @@ -129,12 +148,12 @@ function alma_reservation_create($account, $id, $branch, $expiry = NULL) { $profile2 = profile2_load_by_user($account, 'provider_alma'); if (!empty($profile2)) { - // Interest period. + // interest period if (!isset($expiry)) { - // Get interest period from profile2. + // get interest period from profile2 $interest_period = alma_get_interest_period($profile2); if ($interest_period) { - $expiry = REQUEST_TIME + ($interest_period['key'] * 24 * 60 * 60 ); + $expiry = REQUEST_TIME + ($interest_period['key'] * 24 * 60 * 60); } } if (!isset($expiry)) { @@ -180,6 +199,7 @@ function alma_reservation_create($account, $id, $branch, $expiry = NULL) { // Reset session cache alma_reservation_clear_cache(); return array( + 'branch' => $branch, 'queue_number' => $result, ); } @@ -194,9 +214,12 @@ function alma_reservation_create($account, $id, $branch, $expiry = NULL) { function alma_reservation_update($account, $ids, $options) { $creds = ding_user_get_creds($account); $reservations = alma_reservation_get_reservations($account); + $updated = FALSE; + + // Processing IDs. If at least one is updated, return true. foreach ($ids as $id) { if (isset($reservations[$id])) { - $expiry_date = !empty($options['expiry']) ? alma_reservation_format_date($options['expiry']) : $reservations[$id]['valid_to']; + $expiry_date = !empty($options['alma_interest_period']) ? alma_reservation_format_date(strtotime($reservations[$id]['valid_from']) + $options['alma_interest_period'] * 86400) : $reservations[$id]['valid_to']; $pickup_branch = !empty($options['alma_preferred_branch']) ? $options['alma_preferred_branch'] : $reservations[$id]['pickup_branch']; $changes = array( 'valid_to' => $expiry_date, @@ -204,12 +227,16 @@ function alma_reservation_update($account, $ids, $options) { ); // Alma do not return a status. alma_client_invoke('change_reservation', $creds['name'], $creds['pass'], $reservations[$id], $changes); + $updated = TRUE; } + } + + // Clear cache after all reservations have been updated. + if ($updated) { alma_reservation_clear_cache(); - return TRUE; } - return FALSE; + return $updated; } /** @@ -220,8 +247,8 @@ function alma_reservation_delete($account, $id) { $reservations = alma_reservation_get_reservations($account); alma_reservation_clear_cache(); - if (isset($reservations[$id])) { - return alma_client_invoke('remove_reservation', $creds['name'], $creds['pass'], $reservations[$id]); + if (isset($reservations[(string)$id])) { + return alma_client_invoke('remove_reservation', $creds['name'], $creds['pass'], $reservations[(string)$id]); } } @@ -234,8 +261,9 @@ function alma_reservation_delete($account, $id) { function alma_reservation_branch_name($branch_id) { // Get library organistation from alma. $organisation = alma_get_organisation(); - if (isset($organisation['branch'][$branch_id])) { - return $organisation['branch'][$branch_id]; + $branch = (is_array($branch_id) && isset($branch_id['alma_preferred_branch'])) ? $branch_id['alma_preferred_branch'] : $branch_id; + if (isset($organisation['branch'][$branch])) { + return $organisation['branch'][$branch]; } return NULL; } @@ -260,7 +288,7 @@ function alma_reservation_clear_cache() { } function alma_reservation_exists($account, $item_id) { - $reservations = alma_reservation_get_reservations( $account ); + $reservations = alma_reservation_get_reservations($account); foreach ($reservations as $res) { if ($res['record_id'] == $item_id) { return TRUE; diff --git a/includes/alma.user.inc b/includes/alma.user.inc index 18c5eca..c2f07ce 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -67,16 +67,13 @@ function alma_user_profile_form_validate($form, $form_state) { } - -function alma_user_clear_cache($creds=NULL) { - alma_get_patron($creds, TRUE); +function alma_user_clear_cache($creds = NULL) { + alma_get_patron($creds); } - /** * Update profile2 with values from alma patron */ - function alma_user_profile_init($profile2, $auth_res) { $creds = ding_user_get_creds($profile2); $patron = alma_get_patron($creds); @@ -119,11 +116,11 @@ function alma_user_account_update($account, $changes) { $creds = ding_user_get_creds($account); if (isset($changes['mail'])) { - // Add email. - if (empty( $account->mail ) && !empty($changes['mail'])) { + // Add email + if (empty($account->mail) && !empty($changes['mail'])) { $res = alma_client_invoke('add_email_address', $creds['name'], $creds['pass'], $changes['mail']); } - // Change mail. + // Change email elseif (isset($account->mail) && !empty($changes['mail'])) { $res = alma_client_invoke('change_email_address', $creds['name'], $creds['pass'], $account->mail, $changes['mail']); } @@ -138,6 +135,7 @@ function alma_user_account_update($account, $changes) { $creds['pass'] = $changes['pass']; // Update creds. + $result = array(); $result['creds'] = $creds; return $result; } diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index bda5bdb..9ad4626 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -60,7 +60,7 @@ public function request($method, $params = array(), $check_status = TRUE) { // For use with a non-Drupal-system, we should have a way to swap // logging and logging preferences out. if (variable_get('alma_enable_logging', FALSE)) { - $seconds = floatval(($stopTime[1]+$stopTime[0]) - ($startTime[1]+$startTime[0])); + $seconds = floatval(($stopTime[1] + $stopTime[0]) - ($startTime[1] + $startTime[0])); // Filter params to avoid logging sensitive data. // This can be disabled by setting alma_logging_filter_params = 0. There is no UI for setting this variable @@ -109,21 +109,21 @@ public function request($method, $params = array(), $check_status = TRUE) { * An array of filtered request information */ private static function filter_request_params($params) { - // Scramble sensitive information - $sensitive = array('borrCard', 'pinCode', 'pinCodeChange', 'address', 'emailAddress'); - - $log_params = array(); - foreach ($params as $key => $value) { - if (in_array($key, $sensitive)) { - // Replace the value with a scrambled version generated using md5() and - // the static salt. This way all requests generated by the same page - // load can be grouped - $value = drupal_substr(md5($value . self::$salt), 0, drupal_strlen($value)); - } - $log_params[$key] = $value; + // Scramble sensitive information + $sensitive = array('borrCard', 'pinCode', 'pinCodeChange', 'address', 'emailAddress'); + + $log_params = array(); + foreach ($params as $key => $value) { + if (in_array($key, $sensitive)) { + // Replace the value with a scrambled version generated using md5() and + // the static salt. This way all requests generated by the same page + // load can be grouped + $value = substr(md5($value . self::$salt), 0, strlen($value)); } + $log_params[$key] = $value; + } - return $log_params; + return $log_params; } /** @@ -428,7 +428,7 @@ public function add_reservation($borr_card, $pin_code, $reservation) { 'borrCard' => $borr_card, 'pinCode' => $pin_code, 'reservable' => $reservation['id'], - 'reservationPickUpBranch' => $reservation['pickup_branch'], + 'reservationPickUpBranch' => $reservation['pickup_branch']['alma_preferred_branch'], 'reservationValidFrom' => $reservation['valid_from'], 'reservationValidTo' => $reservation['valid_to'], ); @@ -447,7 +447,7 @@ public function add_reservation($borr_card, $pin_code, $reservation) { $doc = $this->request('patron/reservations/add', $params); $res_status = $doc->getElementsByTagName('reservationStatus')->item(0)->getAttribute('value'); $res_message = $doc->getElementsByTagName('reservationStatus')->item(0)->getAttribute('key'); - $queue_number = (int)$doc->getElementsByTagName('reservation')->item(0)->getAttribute('queueNo'); + $queue_number = (int) $doc->getElementsByTagName('reservation')->item(0)->getAttribute('queueNo'); // Return error code when patron is blocked. if ($res_message == 'reservationPatronBlocked') { @@ -962,21 +962,16 @@ public function remove_message_service($borr_card, $pin_code, $method, $type) { * Define exceptions for different error conditions inside the Alma client. */ -class AlmaClientInvalidURLError extends Exception { -} +class AlmaClientInvalidURLError extends Exception { } -class AlmaClientHTTPError extends Exception { -} +class AlmaClientHTTPError extends Exception { } -class AlmaClientCommunicationError extends Exception { -} +class AlmaClientCommunicationError extends Exception { } -class AlmaClientBorrCardNotFound extends Exception { -} +class AlmaClientBorrCardNotFound extends Exception { } -class AlmaClientReservationNotFound extends Exception { -} +class AlmaClientReservationNotFound extends Exception { } From 96070aa7aa98a4253f33771661933edf90f7c0d5 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 19 Mar 2013 11:09:38 +0100 Subject: [PATCH 015/158] Removed unneeded unserialize im caching --- alma.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alma.module b/alma.module index 6a6a4b2..6b11e7f 100644 --- a/alma.module +++ b/alma.module @@ -19,11 +19,11 @@ function alma_reservation_pickup_branches($account = NULL) { static $alma_pickup_branches; if (!isset($alma_pickup_branches)) { if ($cache = cache_get('alma_pickup_branches')) { - $alma_pickup_branches = unserialize($cache->data); + $alma_pickup_branches = $cache->data; } else { $alma_pickup_branches = alma_client_invoke('get_reservation_branches'); - cache_set('alma_pickup_branches', serialize($alma_pickup_branches), 'cache'); + cache_set('alma_pickup_branches', $alma_pickup_branches, 'cache'); } } return $alma_pickup_branches; From a02152bf2bc249c528a87ad6b027939bcd62a0c7 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 19 Mar 2013 14:45:21 +0100 Subject: [PATCH 016/158] Fixed index error that made PHP go down in alma availability --- includes/alma.availability.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index 6a06ab9..e2267ec 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -297,7 +297,7 @@ function _alma_populate_issues($input) { $reference_count = 0; $total_count = 0; $available_count = 0; - $output[$year][$key]['local_id'] = $issues[0]['reservable']; + $output[$year][$key]['local_id'] = isset($issues[0]['reservable']) ? $issues[0]['reservable'] : ''; $output[$year][$key]['provider'] = 'alma'; $i = 0; // Loop though placements. From 9978ad7ce7d14cd014ec67a45242edb5296d330c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 21 Mar 2013 21:20:11 +0100 Subject: [PATCH 017/158] Removed un-used holdings index (holdings_available) --- includes/alma.availability.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index e2267ec..3eb5c08 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -16,7 +16,6 @@ function alma_availability_holdings($provider_ids) { 'reservable' => $record['show_reservation_button'], 'show_reservation_button' => $record['show_reservation_button'], 'holdings' => $record['holdings'], - 'holdings_available' => array(), 'reserved_count' => (int) $record['reservation_count'], 'deferred_period' => FALSE, 'issues' => _alma_populate_issues($record['holdings']), From 5f43b66db7c23b3777bad71b8ff133b2dea66a7e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 22 Mar 2013 16:49:44 +0100 Subject: [PATCH 018/158] Added missing properties to alma reservarions --- includes/alma.reservation.inc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index d1f5ed2..60285f6 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -109,6 +109,7 @@ function alma_reservation_list($account) { 'order_id' => $reservation['id'], 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $reservation['record_id'], 'pickup_branch_id' => $reservation['pickup_branch'], + 'order_arrived' => NULL, 'pickup_order_id' => $reservation['pickup_number'], 'pickup_date' => $reservation['pickup_expire_date'], 'created' => $reservation['create_date'], @@ -123,6 +124,8 @@ function alma_reservation_list($account) { 'order_id' => $reservation['id'], 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $reservation['record_id'], 'pickup_branch_id' => $reservation['pickup_branch'], + 'order_arrived' => NULL, + 'pickup_order_id' => NULL, 'created' => $reservation['create_date'], 'expiry' => $reservation['valid_to'], 'queue_number' => $reservation['queue_number'], From d6fc7b205c970f84e705e136da91a43949624661 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 22 Mar 2013 18:15:26 +0100 Subject: [PATCH 019/158] Clean up alma presave function and profile2 value handling --- alma.module | 107 +++++++++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 48 deletions(-) diff --git a/alma.module b/alma.module index 6b11e7f..6144d99 100644 --- a/alma.module +++ b/alma.module @@ -265,7 +265,7 @@ function alma_user_view($account, $view_mode, $langcode) { catch (DingProviderAuthException $e) { return NULL; } - + if (($userInfo = _alma_user_info($creds)) && isset($userInfo)) { foreach ($userInfo as $key => $prop) { $data[$key] = isset($prop) ? $prop : ''; @@ -473,79 +473,68 @@ function alma_profile2_presave($profile2) { return; } - // Provider fields: field_alma_preferred_branch, field_alma_interest_period, field_alma_reservation_pause; field_alma_mobile_phone - $langs = field_language('profile2', $profile2); + $changes = array(); // Reservation pause - $start = empty($profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']) - ? '' : $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']; + $value = alma_get_profile2_value($profile2, 'field_alma_reservation_pause', 'value'); + $start = is_null($value['new']) ? '' : $value['new']; $start = str_replace('T00:00:00', '', $start); - $stop = empty($profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']) - ? '' : $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']; - $stop = str_replace('T00:00:00', '', $stop); - $org_start = empty($profile2->original->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']) - ? '' : $profile2->original->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']; + $org_start = is_null($value['old']) ? '' : $value['old']; $org_start = str_replace('T00:00:00', '', $org_start); - $org_stop = empty($profile2->original->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']) - ? '' : $profile2->original->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']; + + $value = alma_get_profile2_value($profile2, 'field_alma_reservation_pause', 'value2'); + $stop = is_null($value['new']) ? '' : $value['new']; + $stop = str_replace('T00:00:00', '', $stop); + + $org_stop = is_null($value['old']) ? '' : $value['old']; $org_stop = str_replace('T00:00:00', '', $org_stop); if ($start != $org_start || $stop != $org_stop) { $changes['reservation_pause_start'] = $start; $changes['reservation_pause_stop'] = $stop; - $changes['absent_id'] = empty($profile2->field_absent_id[$langs['field_absent_id']][0]['value']) ? - '' : $profile2->field_absent_id[$langs['field_absent_id']][0]['value']; - } - // alma_preferred_branch (patronBranch) - if (!empty($profile2->original->field_alma_preferred_branch)) { - $org_branch = $profile2->original->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']; - $new_branch = $profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']; - if ($org_branch != $new_branch) { - $changes['preferred_branch'] = $new_branch; - } + // Set absent id. + $value = alma_get_profile2_value($profile2, 'field_absent_id'); + $changes['absent_id'] = is_null($value['new']) ? '' : $value['new']; } - // Mobile phone - // If present - update. - if (!empty($profile2->original->field_alma_mobile_phone)) { - $org_phone = $profile2->original->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']; - $new_phone = empty($profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']) - ? 'DELETE' : $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']; - if ($org_phone != $new_phone) { - $changes['mobile'] = $new_phone; - $changes['phone_id'] = $profile2->field_alma_phone_id[$langs['field_alma_phone_id']][0]['value']; + // Get preferred branch (patronBranch) + $value = alma_get_profile2_value($profile2, 'field_alma_preferred_branch'); + if (!is_null($value['new'])) { + if ($value['old'] != $value['new']) { + $changes['preferred_branch'] = $value['new']; } } - // If not - add new one. - elseif (!empty($profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']) - && empty($profile2->original->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'])) { - $changes['mobile'] = $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']; - } - // Alma_preferred_branch (patronBranch). - if (!empty($profile2->original->field_alma_preferred_branch)) { - $org_branch = $profile2->original->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']; - $new_branch = $profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']; - } - - // Interest period ? apparently not an alma parameter.. @todo; check if Interest period should be saved on provider + /** + * Mobile phone. + */ + $value = alma_get_profile2_value($profile2, 'field_alma_mobile_phone'); + if (!is_null($value['old'])) { + // Update mobile phone number. + $value['new'] = is_null($value['new']) ? 'DELETE' : $value['new']; + if ($value['old'] != $value['new']) { + $changes['mobile'] = $value['new']; - // Update provider - if (isset($changes)) { - alma_update_provider($changes, $profile2); + // Get phone id. + $phone_id = field_get_items('profile2', $profile2, 'field_alma_phone_id'); + $changes['phone_id'] = $phone_id[0]['value']; + } + } + else if (!is_null($value['new']) && is_null($value['old'])) { + $changes['mobile'] = $value['new']; } // Interest period ? apparently not an alma parameter.. @todo; check if Interest period should be saved on provider // Update provider - if (isset($changes)) { + if (!empty($changes)) { alma_update_provider($changes, $profile2); } } -function alma_update_provider($changes, $profile2) { +function alma_update_provider($changes, &$profile2) { $error_message = t('Error communicating with library system. '); try { @@ -745,3 +734,25 @@ function alma_replace_entity($item) { return FALSE; } + +/** + * Helper function to get profile2 values. + * + * @param type $profile2 + * The profile2 profile object. + * @param string $fieldname + * Field name to get values from. + * @param string $field_index + * The name of the field index. + * @return array + * An array with a "new" and "old" index with the values. + */ +function alma_get_profile2_value($profile2, $fieldname, $field_index = 'value') { + $previous_value = field_get_items('profile2', $profile2->original, $fieldname); + $current_value = field_get_items('profile2', $profile2, $fieldname); + + return array( + 'old' => isset($previous_value[0][$field_index]) ? $previous_value[0][$field_index] : NULL, + 'new' => isset($current_value[0][$field_index]) ? $current_value[0][$field_index] : NULL, + ); +} \ No newline at end of file From d15600933570e2e5f788b337eb157c9bdd6d96ff Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 10 Apr 2013 10:19:53 +0200 Subject: [PATCH 020/158] Fixed login error on new users --- alma.info | 4 +++- alma.module | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/alma.info b/alma.info index 44b9500..6e93767 100644 --- a/alma.info +++ b/alma.info @@ -4,6 +4,7 @@ dependencies[] = "ding_provider" dependencies[] = "features" dependencies[] = "list" description = "Implementation of Axiell’s Alma API for DDELibra." + features[field][] = "profile2-provider_alma-field_absent_id" features[field][] = "profile2-provider_alma-field_alma_interest_period" features[field][] = "profile2-provider_alma-field_alma_mobile_phone" @@ -11,6 +12,7 @@ features[field][] = "profile2-provider_alma-field_alma_phone_id" features[field][] = "profile2-provider_alma-field_alma_preferred_branch" features[field][] = "profile2-provider_alma-field_alma_reservation_pause" features['profile2_type'][] = "provider_alma" + files[] = "alma.module" files[] = "includes/alma.availability.inc" files[] = "includes/alma.debt.inc" @@ -18,7 +20,7 @@ files[] = "includes/alma.reservation.inc" files[] = "includes/alma.user.inc" files[] = "lib/AlmaClient/AlmaClient.class.php" name = "Alma" -package = "Ding!" +package = "Providers" php = "5.2.4" project = "alma" version = "7.x-1.9.5" diff --git a/alma.module b/alma.module index 6144d99..aa2321b 100644 --- a/alma.module +++ b/alma.module @@ -748,11 +748,16 @@ function alma_replace_entity($item) { * An array with a "new" and "old" index with the values. */ function alma_get_profile2_value($profile2, $fieldname, $field_index = 'value') { - $previous_value = field_get_items('profile2', $profile2->original, $fieldname); + $previous_value = array(); + if (isset($profile2->original)) { + $previous_value = field_get_items('profile2', $profile2->original, $fieldname); + } $current_value = field_get_items('profile2', $profile2, $fieldname); return array( 'old' => isset($previous_value[0][$field_index]) ? $previous_value[0][$field_index] : NULL, 'new' => isset($current_value[0][$field_index]) ? $current_value[0][$field_index] : NULL, ); -} \ No newline at end of file +} + +include_once('alma.features.inc'); \ No newline at end of file From 29af8750fc218fe64653c04054c07217b416735e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 10 Apr 2013 10:38:01 +0200 Subject: [PATCH 021/158] Added full name and address fields. Change field_absent_id to field_alma_absent_id to matcht the other fields. --- alma.features.field.inc | 306 +++++++++++++++++++++++++++++++++++++--- alma.features.inc | 22 +-- alma.info | 55 ++++---- alma.module | 6 +- includes/alma.user.inc | 2 +- 5 files changed, 321 insertions(+), 70 deletions(-) diff --git a/alma.features.field.inc b/alma.features.field.inc index aef39a9..973dae9 100644 --- a/alma.features.field.inc +++ b/alma.features.field.inc @@ -10,14 +10,14 @@ function alma_field_default_fields() { $fields = array(); - // Exported field: 'profile2-provider_alma-field_absent_id' - $fields['profile2-provider_alma-field_absent_id'] = array( + // Exported field: 'profile2-provider_alma-field_alma_absent_id'. + $fields['profile2-provider_alma-field_alma_absent_id'] = array( 'field_config' => array( 'active' => '1', 'cardinality' => '1', 'deleted' => '0', 'entity_types' => array(), - 'field_name' => 'field_absent_id', + 'field_name' => 'field_alma_absent_id', 'foreign keys' => array( 'format' => array( 'columns' => array( @@ -31,6 +31,7 @@ function alma_field_default_fields() { 0 => 'format', ), ), + 'locked' => '0', 'module' => 'text', 'settings' => array( 'max_length' => '255', @@ -53,7 +54,7 @@ function alma_field_default_fields() { ), ), 'entity_type' => 'profile2', - 'field_name' => 'field_absent_id', + 'field_name' => 'field_alma_absent_id', 'label' => 'Absent id', 'required' => 0, 'settings' => array( @@ -67,12 +68,140 @@ function alma_field_default_fields() { 'size' => '60', ), 'type' => 'text_textfield', - 'weight' => '4', + 'weight' => '7', ), ), ); - // Exported field: 'profile2-provider_alma-field_alma_interest_period' + // Exported field: 'profile2-provider_alma-field_alma_city'. + $fields['profile2-provider_alma-field_alma_city'] = array( + 'field_config' => array( + 'active' => '1', + 'cardinality' => '1', + 'deleted' => '0', + 'entity_types' => array(), + 'field_name' => 'field_alma_city', + '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, + ), + 'translatable' => '0', + 'type' => 'text', + ), + 'field_instance' => array( + 'bundle' => 'provider_alma', + 'default_value' => NULL, + 'deleted' => '0', + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 9, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_city', + 'label' => 'City', + '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' => '3', + ), + ), + ); + + // Exported field: 'profile2-provider_alma-field_alma_full_name'. + $fields['profile2-provider_alma-field_alma_full_name'] = array( + 'field_config' => array( + 'active' => '1', + 'cardinality' => '1', + 'deleted' => '0', + 'entity_types' => array(), + 'field_name' => 'field_alma_full_name', + '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, + ), + 'translatable' => '0', + 'type' => 'text', + ), + 'field_instance' => array( + 'bundle' => 'provider_alma', + 'default_value' => NULL, + 'deleted' => '0', + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 6, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_full_name', + 'label' => 'Full name', + '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' => '0', + ), + ), + ); + + // Exported field: 'profile2-provider_alma-field_alma_interest_period'. $fields['profile2-provider_alma-field_alma_interest_period'] = array( 'field_config' => array( 'active' => '1', @@ -86,13 +215,14 @@ function alma_field_default_fields() { 0 => 'value', ), ), + 'locked' => '0', 'module' => 'list', 'settings' => array( 'allowed_values' => array( - 30 => t('1 month'), - 60 => t('2 months'), - 90 => t('3 months'), - 180 => t('6 months'), + 30 => '1 måned', + 60 => '2 months', + 90 => '3 months', + 180 => '6 months', ), 'allowed_values_function' => '', 'profile2_private' => 0, @@ -130,12 +260,12 @@ function alma_field_default_fields() { 'module' => 'options', 'settings' => array(), 'type' => 'options_select', - 'weight' => '2', + 'weight' => '5', ), ), ); - // Exported field: 'profile2-provider_alma-field_alma_mobile_phone' + // Exported field: 'profile2-provider_alma-field_alma_mobile_phone'. $fields['profile2-provider_alma-field_alma_mobile_phone'] = array( 'field_config' => array( 'active' => '1', @@ -156,6 +286,7 @@ function alma_field_default_fields() { 0 => 'format', ), ), + 'locked' => '0', 'module' => 'text', 'settings' => array( 'max_length' => '16', @@ -193,12 +324,12 @@ function alma_field_default_fields() { 'size' => '12', ), 'type' => 'text_textfield', - 'weight' => '5', + 'weight' => '8', ), ), ); - // Exported field: 'profile2-provider_alma-field_alma_phone_id' + // Exported field: 'profile2-provider_alma-field_alma_phone_id'. $fields['profile2-provider_alma-field_alma_phone_id'] = array( 'field_config' => array( 'active' => '1', @@ -219,6 +350,7 @@ function alma_field_default_fields() { 0 => 'format', ), ), + 'locked' => '0', 'module' => 'text', 'settings' => array( 'max_length' => '255', @@ -253,12 +385,76 @@ function alma_field_default_fields() { 'size' => 60, ), 'type' => 'text_textfield', - 'weight' => '6', + 'weight' => '9', + ), + ), + ); + + // Exported field: 'profile2-provider_alma-field_alma_postal_code'. + $fields['profile2-provider_alma-field_alma_postal_code'] = array( + 'field_config' => array( + 'active' => '1', + 'cardinality' => '1', + 'deleted' => '0', + 'entity_types' => array(), + 'field_name' => 'field_alma_postal_code', + '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, + ), + 'translatable' => '0', + 'type' => 'text', + ), + 'field_instance' => array( + 'bundle' => 'provider_alma', + 'default_value' => NULL, + 'deleted' => '0', + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 8, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_postal_code', + 'label' => 'Postal code', + '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' => '2', ), ), ); - // Exported field: 'profile2-provider_alma-field_alma_preferred_branch' + // Exported field: 'profile2-provider_alma-field_alma_preferred_branch'. $fields['profile2-provider_alma-field_alma_preferred_branch'] = array( 'field_config' => array( 'active' => '1', @@ -272,6 +468,7 @@ function alma_field_default_fields() { 0 => 'value', ), ), + 'locked' => '0', 'module' => 'list', 'settings' => array( 'allowed_values' => array(), @@ -307,12 +504,12 @@ function alma_field_default_fields() { 'module' => 'options', 'settings' => array(), 'type' => 'options_select', - 'weight' => '1', + 'weight' => '4', ), ), ); - // Exported field: 'profile2-provider_alma-field_alma_reservation_pause' + // Exported field: 'profile2-provider_alma-field_alma_reservation_pause'. $fields['profile2-provider_alma-field_alma_reservation_pause'] = array( 'field_config' => array( 'active' => '1', @@ -322,6 +519,7 @@ function alma_field_default_fields() { 'field_name' => 'field_alma_reservation_pause', 'foreign keys' => array(), 'indexes' => array(), + 'locked' => '0', 'module' => 'date', 'settings' => array( 'granularity' => array( @@ -385,7 +583,71 @@ function alma_field_default_fields() { 'year_range' => '-3:+3', ), 'type' => 'date_popup', - 'weight' => '3', + 'weight' => '6', + ), + ), + ); + + // Exported field: 'profile2-provider_alma-field_alma_street_name'. + $fields['profile2-provider_alma-field_alma_street_name'] = array( + 'field_config' => array( + 'active' => '1', + 'cardinality' => '1', + 'deleted' => '0', + 'entity_types' => array(), + 'field_name' => 'field_alma_street_name', + '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, + ), + 'translatable' => '0', + 'type' => 'text', + ), + 'field_instance' => array( + 'bundle' => 'provider_alma', + 'default_value' => NULL, + 'deleted' => '0', + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 7, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_street_name', + 'label' => 'Street name', + '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' => '1', ), ), ); @@ -393,11 +655,15 @@ function alma_field_default_fields() { // Translatables // Included for use with string extractors like potx. t('Absent id'); - t('Preferred branch'); + t('City'); + t('Full name'); t('Interest period'); t('Phone'); + t('Postal code'); + t('Preferred branch'); t('Reservation pause'); t('Set your reservations on pause.'); + t('Street name'); t('phone id'); return $fields; diff --git a/alma.features.inc b/alma.features.inc index ce135e7..db032d8 100644 --- a/alma.features.inc +++ b/alma.features.inc @@ -1,22 +1,4 @@ field_alma_phone_id[$langs['field_alma_phone_id']][0]['value'] = empty($info['phones'][0]['id']) ? NULL : $info['phones'][0]['id']; - $profile2->field_absent_id[$langs['field_absent_id']][0]['value'] = empty($info['absent_periods'][0]['id']) ? NULL : $info['absent_periods'][0]['id']; + $profile2->field_alma_absent_id[$langs['field_alma_absent_id']][0]['value'] = empty($info['absent_periods'][0]['id']) ? NULL : $info['absent_periods'][0]['id']; } /** diff --git a/includes/alma.user.inc b/includes/alma.user.inc index c2f07ce..483956e 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -86,7 +86,7 @@ function alma_user_profile_init($profile2, $auth_res) { if (is_array($patron) && isset($patron->absentPeriods[0]['from_date']) && isset($patron->absentPeriods[0]['to_date'])) { $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value'] = $patron->absentPeriods[0]['from_date']; $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2'] = $patron->absentPeriods[0]['to_date']; - $profile2->field_absent_id[$langs['field_absent_id']][0]['value'] = $patron->absentPeriods[0]['id']; + $profile2->field_alma_absent_id[$langs['field_alma_absent_id']][0]['value'] = $patron->absentPeriods[0]['id']; } else { $profile2->field_reservation_pause[$langs['field_alma_reservation_pause']][0]['value'] = ' '; From ce2d6286ca11d4381d066c43facdd628410f9769 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 10 Apr 2013 10:41:05 +0200 Subject: [PATCH 022/158] Removed deprecated features.inc file --- alma.features.inc | 4 ---- alma.module | 4 +--- 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 alma.features.inc diff --git a/alma.features.inc b/alma.features.inc deleted file mode 100644 index db032d8..0000000 --- a/alma.features.inc +++ /dev/null @@ -1,4 +0,0 @@ - isset($previous_value[0][$field_index]) ? $previous_value[0][$field_index] : NULL, 'new' => isset($current_value[0][$field_index]) ? $current_value[0][$field_index] : NULL, ); -} - -include_once('alma.features.inc'); \ No newline at end of file +} \ No newline at end of file From 0e6bc076dd3d6a008b6cf0e8ee695cfa79dc7bb3 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 10 Apr 2013 13:06:35 +0200 Subject: [PATCH 023/158] Converted profile2 fields into virtual field, so personal data is not stored in the DB --- alma.features.field.inc | 94 ++++++++++++++++++++++++++++++++++++++++- alma.install | 13 ++++++ 2 files changed, 105 insertions(+), 2 deletions(-) diff --git a/alma.features.field.inc b/alma.features.field.inc index 973dae9..bc6dead 100644 --- a/alma.features.field.inc +++ b/alma.features.field.inc @@ -37,6 +37,15 @@ function alma_field_default_fields() { 'max_length' => '255', 'profile2_private' => 0, ), + 'storage' => array( + 'active' => '1', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), + 'virtual_field' => array( + 'entity_types' => array('profile2'), + ), 'translatable' => '0', 'type' => 'text', ), @@ -100,6 +109,15 @@ function alma_field_default_fields() { 'max_length' => '255', 'profile2_private' => 0, ), + 'storage' => array( + 'active' => '1', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), + 'virtual_field' => array( + 'entity_types' => array('profile2'), + ), 'translatable' => '0', 'type' => 'text', ), @@ -164,6 +182,15 @@ function alma_field_default_fields() { 'max_length' => '255', 'profile2_private' => 0, ), + 'storage' => array( + 'active' => '1', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), + 'virtual_field' => array( + 'entity_types' => array('profile2'), + ), 'translatable' => '0', 'type' => 'text', ), @@ -227,6 +254,15 @@ function alma_field_default_fields() { 'allowed_values_function' => '', 'profile2_private' => 0, ), + 'storage' => array( + 'active' => '1', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), + 'virtual_field' => array( + 'entity_types' => array('profile2'), + ), 'translatable' => '0', 'type' => 'list_text', ), @@ -292,6 +328,15 @@ function alma_field_default_fields() { 'max_length' => '16', 'profile2_private' => 0, ), + 'storage' => array( + 'active' => '1', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), + 'virtual_field' => array( + 'entity_types' => array('profile2'), + ), 'translatable' => '0', 'type' => 'text', ), @@ -355,6 +400,15 @@ function alma_field_default_fields() { 'settings' => array( 'max_length' => '255', ), + 'storage' => array( + 'active' => '1', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), + 'virtual_field' => array( + 'entity_types' => array('profile2'), + ), 'translatable' => '0', 'type' => 'text', ), @@ -373,7 +427,7 @@ function alma_field_default_fields() { ), 'entity_type' => 'profile2', 'field_name' => 'field_alma_phone_id', - 'label' => 'phone id', + 'label' => 'Phone id', 'required' => FALSE, 'settings' => array( 'text_processing' => 0, @@ -417,6 +471,15 @@ function alma_field_default_fields() { 'max_length' => '255', 'profile2_private' => 0, ), + 'storage' => array( + 'active' => '1', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), + 'virtual_field' => array( + 'entity_types' => array('profile2'), + ), 'translatable' => '0', 'type' => 'text', ), @@ -475,6 +538,15 @@ function alma_field_default_fields() { 'allowed_values_function' => 'alma_reservation_pickup_branches', 'profile2_private' => 0, ), + 'storage' => array( + 'active' => '1', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), + 'virtual_field' => array( + 'entity_types' => array('profile2'), + ), 'translatable' => '0', 'type' => 'list_text', ), @@ -536,6 +608,15 @@ function alma_field_default_fields() { 'todate' => 'required', 'tz_handling' => 'none', ), + 'storage' => array( + 'active' => '1', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), + 'virtual_field' => array( + 'entity_types' => array('profile2'), + ), 'translatable' => '0', 'type' => 'date', ), @@ -615,6 +696,15 @@ function alma_field_default_fields() { 'max_length' => '255', 'profile2_private' => 0, ), + 'storage' => array( + 'active' => '1', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), + 'virtual_field' => array( + 'entity_types' => array('profile2'), + ), 'translatable' => '0', 'type' => 'text', ), @@ -664,7 +754,7 @@ function alma_field_default_fields() { t('Reservation pause'); t('Set your reservations on pause.'); t('Street name'); - t('phone id'); + t('Phone id'); return $fields; } diff --git a/alma.install b/alma.install index c7f3647..1850afe 100644 --- a/alma.install +++ b/alma.install @@ -12,3 +12,16 @@ function alma_update_7001() { ->condition('name', 'alma', '=') ->execute(); } + +/** + * Convert field storage to virtual field. + */ +function alma_update_7002() { + return db_update('field_config') + ->fields(array( + 'storage_type' => 'virtual_field', + 'storage_module' => 'virtual_field', + )) + ->condition('field_name', '%alma%', 'LIKE') + ->execute(); +} From 9cc247119387ce2eb25c8a9983b3d20fec7e095f Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 10 Apr 2013 17:01:36 +0200 Subject: [PATCH 024/158] * Remove form alters, hook_profile_init and clean out the main part of the module with entity_metadata_wrapper's * Updated alma fields to use virtual fields and fixed the side effect to this. * Using hook_profile2_load() to dynamic load content when needed (replaces the alters). --- alma.module | 424 +++++++++------------------------- includes/alma.reservation.inc | 17 +- includes/alma.user.inc | 36 --- 3 files changed, 119 insertions(+), 358 deletions(-) diff --git a/alma.module b/alma.module index 2f4f589..d2948ce 100644 --- a/alma.module +++ b/alma.module @@ -131,39 +131,6 @@ function alma_settings_form() { return system_settings_form($form); } -/** - * Implements hook_form_FORM_ID_alter(). - * pjo notes: user_profile_form - * Add in pincode validation. - */ -function alma_form_user_profile_form_alter(&$form, &$form_state) { - // Ensure that we're dealing with a provider user. - if (!ding_user_is_provider_user($form_state['user'])) { - return; - } - - global $user; - $profile2 = profile2_load_by_user($user, 'provider_alma'); - // attach profile2 form to user_profile_form. - // profile2 form could be shown by editing people->permissions->profile2, but profile2 adds a tab and we don't want that. - if (ding_user_is_provider_user($user) && $profile2) { - $form_state['profiles'] = array('provider_alma' => $profile2); - profile2_attach_form($form, $form_state); - } - - // change size and length of pincode - $form['account']['pincode']['#size'] = 32; - $form['account']['pincode']['#maxlength'] = 32; - - // Hide mobile ID and absent period ID fields - // since they are not relevant for end users. - $form['profile_provider_alma']['field_alma_absent_id']['#access'] = FALSE; - $form['profile_provider_alma']['field_alma_phone_id']['#access'] = FALSE; - - // @todo; WHAT are the rules for alma pincode - // HOW do we validate -} - /** * Return a fully instantiated AlmaClient instance. */ @@ -255,46 +222,6 @@ function alma_get_organisation($reset = FALSE) { return $organisation; } -/** - * Implements hook_user_view(). - */ -function alma_user_view($account, $view_mode, $langcode) { - try { - $creds = ding_user_get_creds($account); - } - catch (DingProviderAuthException $e) { - return NULL; - } - - if (($userInfo = _alma_user_info($creds)) && isset($userInfo)) { - foreach ($userInfo as $key => $prop) { - $data[$key] = isset($prop) ? $prop : ''; - } - - $account->content['name'] = array( - '#type' => 'item', - '#title' => t('Name'), - '#markup' => $data['firstname'], - '#weight' => -1, - ); - - if (!empty($data['address']) || !empty($data['postal']) || !empty($data['city'])) { - $address_parts = array(); - $address_parts[] = join('
', array_filter(array($data['address'], $data['postal'], $data['city']))); - // @todo: really, there should be a template for this. - $account->content['address'] = array( - '#type' => 'item', - '#title' => t('Address'), - '#markup' => '

' . $data['address'] . '
' . $data['postal'] . ' ' . $data['city'] . '

', - '#weight' => 0, - ); - } - } - - // @todo: add provider specific fields - alma_set_profile2_fields($account); -} - /** * Callback function to get OpenRuth user information */ @@ -317,224 +244,77 @@ function _alma_user_info($creds = NULL) { return $info; } -/** - * Implements hook_profile2_fields(). - */ -function alma_set_profile2_fields($account) { - if (!module_exists('profile2')) { - return; - } - - $profile2 = profile2_load_by_user($account, 'provider_alma'); - if (empty($profile2)) { - return; - } - - // Wrapper for profile2-fields. - $account->content['profile2'] = array( - '#type' => 'item', - '#prefix' => '
', - '#suffix' => '
', - ); - - // Set preferred branch. - if ($pref_branch = alma_get_preferred_branch($profile2)) { - $account->content['profile2']['preferred_branch'] = array( - '#type' => 'item', - '#title' => t('Pickup branch'), - '#markup' => '' . $pref_branch . '', - ); - } - - // Set interest period. - if ($interest_period = alma_get_interest_period($profile2)) { - $account->content['profile2']['interest_period'] = array( - '#type' => 'item', - '#title' => t('Interest period'), - '#markup' => '' . $interest_period['value'] . '', - ); - } - - // Set mobile phone. - if ($mob = alma_get_mobile_phone($profile2)) { - $account->content['profile2']['mobile'] = array( - '#type' => 'item', - '#title' => t('Mobile phone'), - '#markup' => '' . $mob . '', - ); - } - - // Set reservation pause. - if ($reservation_pause = alma_get_reservation_pause($profile2)) { - // Wrapper for reservation pause. - $start = str_replace('T00:00:00', '', $reservation_pause['start']); - $start = format_date(strtotime($start), 'custom', 'd/m/Y'); - $stop = str_replace('T00:00:00', '', $reservation_pause['stop']); - $stop = format_date(strtotime($stop), 'custom', 'd/m/Y'); - - $account->content['profile2']['reservation_pause'] = array( - '#type' => 'item', - '#title' => '

' . t('Reservation pause') . '

', - '#prefix' => '
', - '#suffix' => '
', - ); - - $account->content['profile2']['reservation_pause']['start'] = array( - '#type' => 'item', - '#title' => t('Start'), - '#markup' => '' . $start . '', - ); - - $account->content['profile2']['reservation_pause']['stop'] = array( - '#type' => 'item', - '#title' => t('Stop'), - '#markup' => '' . $stop . '', - ); - } -} - -function alma_get_mobile_phone($profile2) { - $langs = field_language('profile2', $profile2); - - if (empty($profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']])) { - return FALSE; - } - - if (isset($profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'])) { - return $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value']; - } - - return FALSE; -} - -function alma_get_reservation_pause($profile2) { - // Get field languages - $langs = field_language('profile2', $profile2); - - if (empty($profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']])) { - return FALSE; - } - - $res_pause = array(); - $res_pause['start'] = $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value']; - $res_pause['stop'] = $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2']; - - if (drupal_strlen($res_pause['start']) < 2 || drupal_strlen($res_pause['stop']) < 2) { - return FALSE; - } - - return $res_pause; -} - -function alma_get_interest_period($profile2) { - // Get field languages. - $langs = field_language('profile2', $profile2); - - // Get field-info to retrieve values for select list. - $field_info = field_info_field('field_alma_interest_period'); - - $interest_period = FALSE; - $int_values = isset($field_info['settings']['allowed_values']) ? $field_info['settings']['allowed_values'] : FALSE; - if ($int_values) { - $int_period = $profile2->field_alma_interest_period[$langs['field_alma_interest_period']][0]['value']; - $interest_period = isset($int_values[$int_period]) ? array('key' => $int_period, 'value' => $int_values[$int_period]) : FALSE; - } - return $interest_period; -} - -function alma_get_preferred_branch($profile2) { - // Get field languages. - $langs = field_language('profile2', $profile2); - - // Get preferred branch. - $pref_branch = - isset($profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value']) ? - $profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value'] : ''; - - $branches = alma_reservation_pickup_branches(); - $pref = isset($branches[$pref_branch]) ? $branches[$pref_branch] : FALSE; - - return $pref; -} - /** * Implements hook_profile2_presave(). * - * Sends changes to Alma. + * Updates changes add to the profile when its saved. */ -function alma_profile2_presave($profile2) { - if (!$profile2->type == 'provider_alma') { - return; - } - - // Do not presave when initializing - // @see alma.user/alma_user_profile_init - if (isset($profile2->alma_init)) { - return; - } - - $changes = array(); - - // Reservation pause - $value = alma_get_profile2_value($profile2, 'field_alma_reservation_pause', 'value'); - $start = is_null($value['new']) ? '' : $value['new']; - $start = str_replace('T00:00:00', '', $start); - - $org_start = is_null($value['old']) ? '' : $value['old']; - $org_start = str_replace('T00:00:00', '', $org_start); - - $value = alma_get_profile2_value($profile2, 'field_alma_reservation_pause', 'value2'); - $stop = is_null($value['new']) ? '' : $value['new']; - $stop = str_replace('T00:00:00', '', $stop); - - $org_stop = is_null($value['old']) ? '' : $value['old']; - $org_stop = str_replace('T00:00:00', '', $org_stop); - - if ($start != $org_start || $stop != $org_stop) { - $changes['reservation_pause_start'] = $start; - $changes['reservation_pause_stop'] = $stop; - - // Set absent id. - $value = alma_get_profile2_value($profile2, 'field_alma_absent_id'); - $changes['absent_id'] = is_null($value['new']) ? '' : $value['new']; - } +function alma_profile2_presave($entity) { + if ($entity->type == 'provider_alma') { + $changes = array(); + + // Use a metadata wrapper to access the data. + $wrapper_original = entity_metadata_wrapper('profile2', $entity->original); + $wrapper = entity_metadata_wrapper('profile2', $entity); + + // Reservation pause + $value = $wrapper->field_alma_reservation_pause->value(); + $start = is_null($value['value']) ? '' : $value['value']; + $start = str_replace('T00:00:00', '', $start); + $stop = is_null($value['value2']) ? '' : $value['value2']; + $stop = str_replace('T00:00:00', '', $stop); + + $value = $wrapper_original->field_alma_reservation_pause->value(); + $org_start = is_null($value['value']) ? '' : $value['value']; + $org_start = str_replace('T00:00:00', '', $org_start); + $org_stop = is_null($value['value2']) ? '' : $value['value2']; + $org_stop = str_replace('T00:00:00', '', $org_stop); + + if ($start != $org_start || $stop != $org_stop) { + $changes['reservation_pause_start'] = $start; + $changes['reservation_pause_stop'] = $stop; + + // Set absent id. + $wrapper->field_alma_absent_id->value(); + $changes['absent_id'] = is_null($value) ? '' : $value; + } - // Get preferred branch (patronBranch) - $value = alma_get_profile2_value($profile2, 'field_alma_preferred_branch'); - if (!is_null($value['new'])) { - if ($value['old'] != $value['new']) { - $changes['preferred_branch'] = $value['new']; + // Get preferred branch (patronBranch) + $value = $wrapper->field_alma_preferred_branch->value(); + if (!is_null($value)) { + if ($value != $wrapper_original->field_alma_preferred_branch->value()) { + $changes['preferred_branch'] = $value; + } } - } - /** - * Mobile phone. - */ - $value = alma_get_profile2_value($profile2, 'field_alma_mobile_phone'); - if (!is_null($value['old'])) { - // Update mobile phone number. - $value['new'] = is_null($value['new']) ? 'DELETE' : $value['new']; - if ($value['old'] != $value['new']) { - $changes['mobile'] = $value['new']; - - // Get phone id. - $phone_id = field_get_items('profile2', $profile2, 'field_alma_phone_id'); - $changes['phone_id'] = $phone_id[0]['value']; + /** + * Mobile phone. + */ + $value = $wrapper->field_alma_mobile_phone->value(); + if (!is_null($wrapper_original->field_alma_mobile_phone->value())) { + // Update mobile phone number. + $value = is_null($value) ? 'DELETE' : $value; + if ($value != $wrapper_original->field_alma_mobile_phone->value()) { + $changes['mobile'] = $value; + + // Get phone id. + $changes['phone_id'] = $wrapper->field_alma_phone_id->value(); + } + } + else if (!is_null($value) && is_null($wrapper_original->field_alma_mobile_phone->value())) { + $changes['mobile'] = $value; } - } - else if (!is_null($value['new']) && is_null($value['old'])) { - $changes['mobile'] = $value['new']; - } - // Interest period ? apparently not an alma parameter.. @todo; check if Interest period should be saved on provider + // Interest period ? apparently not an alma parameter.. @todo; check if Interest period should be saved on provider - // Update provider - if (!empty($changes)) { - alma_update_provider($changes, $profile2); + // Update provider + if (!empty($changes)) { + alma_update_provider($changes, $entity); + } } } -function alma_update_provider($changes, &$profile2) { +function alma_update_provider($changes, $profile2) { $error_message = t('Error communicating with library system. '); try { @@ -627,13 +407,6 @@ function alma_update_provider($changes, &$profile2) { catch (Exception $e) { watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); } - - // this one actually deletes the reservation pause, but returns an error ?? - // for now disable messages...@todo; fix it. - /* if(!$res) { - $error_message .= t('reservation pause not deleted'); - drupal_set_message($error_message,'warning'); - } */ } // Update preferred branch (patronBranch). @@ -649,12 +422,6 @@ function alma_update_provider($changes, &$profile2) { drupal_set_message($error_message, 'warning'); } } - - // Refresh patron and update profile field IDs from response. - $info = alma_client_invoke('get_patron_info', $creds['name'], $creds['pass'], TRUE); - $langs = field_language('profile2', $profile2); - $profile2->field_alma_phone_id[$langs['field_alma_phone_id']][0]['value'] = empty($info['phones'][0]['id']) ? NULL : $info['phones'][0]['id']; - $profile2->field_alma_absent_id[$langs['field_alma_absent_id']][0]['value'] = empty($info['absent_periods'][0]['id']) ? NULL : $info['absent_periods'][0]['id']; } /** @@ -736,26 +503,63 @@ function alma_replace_entity($item) { } /** - * Helper function to get profile2 values. + * Implements hook_profile2_load(). + * + * When every a profile2 profile is load this hook it called and as we are using + * virtual fields the content has to be field in from Alma just in time. So this + * seams to be the right place and at the same time ensure that the information + * is not stored locally. * - * @param type $profile2 - * The profile2 profile object. - * @param string $fieldname - * Field name to get values from. - * @param string $field_index - * The name of the field index. - * @return array - * An array with a "new" and "old" index with the values. */ -function alma_get_profile2_value($profile2, $fieldname, $field_index = 'value') { - $previous_value = array(); - if (isset($profile2->original)) { - $previous_value = field_get_items('profile2', $profile2->original, $fieldname); - } - $current_value = field_get_items('profile2', $profile2, $fieldname); +function alma_profile2_load($entities) { + foreach ($entities as $id => &$entity) { + if ($entity->type == 'provider_alma') { + + // User static cache to ensure that alma is not asked more than once. + $patron = &drupal_static(__FUNCTION__); + if (!isset($patron)) { + // Get information from alma about the current user. + global $user; + $creds = ding_user_get_creds($user); + $patron = alma_get_patron($creds); + } - return array( - 'old' => isset($previous_value[0][$field_index]) ? $previous_value[0][$field_index] : NULL, - 'new' => isset($current_value[0][$field_index]) ? $current_value[0][$field_index] : NULL, - ); + // Use a metadata wrapper to access the data. + $wrapper = entity_metadata_wrapper('profile2', $entity); + + // Reservation pause. + $wrapper->field_alma_reservation_pause->set(array( + 'value' => '', + 'value2' => '', + )); + if (isset($patron->absentPeriods[0]['from_date']) && isset($patron->absentPeriods[0]['to_date'])) { + $wrapper->field_alma_reservation_pause->set(array( + 'value' => $patron->absentPeriods[0]['from_date'], + 'value2' => $patron->absentPeriods[0]['to_date'], + )); + $wrapper->field_alma_absent_id->set($patron->absentPeriods[0]['id']); + } + + // Full name. + $wrapper->field_alma_full_name->set($patron->name); + + // Set full address. + $wrapper->field_alma_street_name->set($patron->address); + $wrapper->field_alma_postal_code->set($patron->postal); + $wrapper->field_alma_city->set($patron->city); + + // 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); + + // Interest periode. + $wrapper->field_alma_interest_period->set('180'); // WHERE IS IT STORED. + /** + * @TODO: Should mail be moved into the profile ? It would resolve all issue with the same email for diff users. + */ + } + } } \ No newline at end of file diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 60285f6..6dbe36d 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -151,10 +151,12 @@ function alma_reservation_create($account, $id, $branch, $expiry = NULL) { $profile2 = profile2_load_by_user($account, 'provider_alma'); if (!empty($profile2)) { + $wrapper = entity_metadata_wrapper('profile2', $entity); // interest period if (!isset($expiry)) { - // get interest period from profile2 - $interest_period = alma_get_interest_period($profile2); + + // Use a metadata wrapper to access the data. + $interest_period = $wrapper->field_alma_interest_period->value(); if ($interest_period) { $expiry = REQUEST_TIME + ($interest_period['key'] * 24 * 60 * 60); } @@ -165,16 +167,7 @@ function alma_reservation_create($account, $id, $branch, $expiry = NULL) { // preferred branch if (empty($branch)) { - $pref_branch = alma_get_preferred_branch($profile2); - if ($pref_branch) { - $branches = alma_reservation_pickup_branches(); - foreach ($branches as $key => $val) { - if ($val == $pref_branch) { - $branch = $key; - break; - } - } - } + $branch = $wrapper->field_alma_preferred_branch->value(); } } diff --git a/includes/alma.user.inc b/includes/alma.user.inc index 483956e..b59e321 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -71,42 +71,6 @@ function alma_user_clear_cache($creds = NULL) { alma_get_patron($creds); } -/** - * Update profile2 with values from alma patron - */ -function alma_user_profile_init($profile2, $auth_res) { - $creds = ding_user_get_creds($profile2); - $patron = alma_get_patron($creds); - - // Reservation pause (absentPeriod). - // pparently alma supports multiple absentPeriods, but for now we handle one only (the first found). - // @todo - check if it's correct to handle the first only - $langs = field_language('profile2', $profile2); - // Reservation pause. - if (is_array($patron) && isset($patron->absentPeriods[0]['from_date']) && isset($patron->absentPeriods[0]['to_date'])) { - $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value'] = $patron->absentPeriods[0]['from_date']; - $profile2->field_alma_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2'] = $patron->absentPeriods[0]['to_date']; - $profile2->field_alma_absent_id[$langs['field_alma_absent_id']][0]['value'] = $patron->absentPeriods[0]['id']; - } - else { - $profile2->field_reservation_pause[$langs['field_alma_reservation_pause']][0]['value'] = ' '; - $profile2->field_reservation_pause[$langs['field_alma_reservation_pause']][0]['value2'] = ' '; - } - - // Preferred_branch. - $profile2->field_alma_preferred_branch[$langs['field_alma_preferred_branch']][0]['value'] = $patron->branch; - - // Mobile; also here alma supports multiple phones - again we pick the first - $profile2->field_alma_mobile_phone[$langs['field_alma_mobile_phone']][0]['value'] = isset($patron->mobiles[0]['phone']) ? $patron->mobiles[0]['phone'] : ''; - $profile2->field_alma_phone_id[$langs['field_alma_phone_id']][0]['value'] = isset($patron->mobiles[0]['id']) ? $patron->mobiles[0]['id'] : NULL; - //$profile2->field_alma_phone_id[$langs['field_alma_phone_id']][0]['value'] = isset() .. etc - - // Handle init parameter in alma.module/alma_profile2_presave. - $profile2->alma_init = TRUE; - $profile2->save(); - unset($profile2->alma_init); -} - /** * update provider user; * @invoked from: ding_user/ding_user_user_presave From 309a69cfa45d8268d4e02a11cd270aed8bafa299 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 10 Apr 2013 20:20:37 +0200 Subject: [PATCH 025/158] Change profile2 to use metadata wrappers in all file and basic clean up --- alma.info | 1 + alma.module | 2 +- includes/alma.availability.inc | 47 +++++++++---- includes/alma.reservation.inc | 119 ++++++++++++++++++++------------- includes/alma.user.inc | 27 +++++++- 5 files changed, 134 insertions(+), 62 deletions(-) diff --git a/alma.info b/alma.info index c618fbf..bf744d9 100644 --- a/alma.info +++ b/alma.info @@ -7,6 +7,7 @@ version = 7.x-1.0-beta1 project = alma dependencies[] = date dependencies[] = ding_provider +dependencies[] = ding_reservation dependencies[] = features dependencies[] = list dependencies[] = profile2 diff --git a/alma.module b/alma.module index d2948ce..f7b619f 100644 --- a/alma.module +++ b/alma.module @@ -256,7 +256,7 @@ function alma_profile2_presave($entity) { // Use a metadata wrapper to access the data. $wrapper_original = entity_metadata_wrapper('profile2', $entity->original); $wrapper = entity_metadata_wrapper('profile2', $entity); - + // Reservation pause $value = $wrapper->field_alma_reservation_pause->value(); $start = is_null($value['value']) ? '' : $value['value']; diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index 3eb5c08..6a37eb7 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -1,4 +1,8 @@ field_alma_preferred_branch[field_language('profile2', $profile, 'field_alma_preferred_branch')][0]['value']; - $interest_period = $profile->field_alma_interest_period[field_language('profile2', $profile, 'field_alma_interest_period')][0]['value']; - } - else { - $preferred_branch = NULL; - $interest_period = NULL; + // Load profile2 profile. + $profile = ding_user_provider_profile($account); + + // Use a metadata wrapper to access the data. + $wrapper = entity_metadata_wrapper('profile2', $profile); + + // Get values. + $preferred_branch = $wrapper->field_alma_preferred_branch->value(); + $interest_period = $wrapper->field_alma_interest_period->value(); } + $form = array(); $form += ding_reservation_default_options_branch($type, 'alma_preferred_branch', $preferred_branch, $branches); $form += ding_reservation_interest_period_selector($type, 'alma_interest_period', $interest_period, $periods); return $form; } - /** * Validate reservations options. */ function alma_reservation_options_validate($type, $account, $reservables, $values) { + // Load profile2 profile. $profile = ding_user_provider_profile($account); - $field_language = field_language('profile2', $profile); - $profile_branch = $profile->field_alma_preferred_branch[$field_language['field_alma_preferred_branch']][0]['value']; - $interest_period = $profile->field_alma_interest_period[$field_language['field_alma_interest_period']][0]['value']; + + // Use a metadata wrapper to access the data. + $wrapper = entity_metadata_wrapper('profile2', $profile); + + // Get values. + $preferred_branch = $wrapper->field_alma_preferred_branch->value();; + $interest_period = $wrapper->field_alma_interest_period->value(); + // Perform a check to whether a show specific select dropdown. // Returning NULL means to skip this check, therefore to reserve instantly. - if (!empty($profile_branch) && !empty($interest_period) && $type == 'create') { + if (!empty($$preferred_branch) && !empty($interest_period) && $type == 'create') { return array( - 'alma_preferred_branch' => $profile_branch, + 'alma_preferred_branch' => $$preferred_branch, 'alma_interest_period' => $interest_period, ); } else { - $branch_valid = ding_reservation_default_options_branch_validate($type, 'alma_preferred_branch', $profile_branch, $values); + $branch_valid = ding_reservation_default_options_branch_validate($type, 'alma_preferred_branch', $$preferred_branch, $values); $period_valid = ding_reservation_default_options_interest_period_validate($type, 'alma_interest_period', $interest_period, $values); return array_merge($branch_valid, $period_valid); } @@ -69,28 +71,34 @@ function alma_reservation_options_validate($type, $account, $reservables, $value * Submit handler for reservations options. */ function alma_reservation_options_submit($type, $account, $reservables, $values) { + // Load profile2 profile. $profile = ding_user_provider_profile($account); - $field_language = field_language('profile2', $profile); - $profile_branch = $profile->field_alma_preferred_branch[$field_language['field_alma_preferred_branch']][0]['value']; - $update = ding_reservation_default_options_branch_submit($type, 'alma_preferred_branch', $profile_branch, $values); + + // Use a metadata wrapper to access the data. + $wrapper = entity_metadata_wrapper('profile2', $profile); + + // Get values. + $preferred_branch = $wrapper->field_alma_preferred_branch->value();; + + $update = ding_reservation_default_options_branch_submit($type, 'alma_preferred_branch', $preferred_branch, $values); if (!empty($update['alma_preferred_branch'])) { - $profile->field_alma_preferred_branch[$field_language['field_alma_preferred_branch']][0]['value'] = $update['alma_preferred_branch']; - $profile->save(); + $wrapper->field_alma_preferred_branch->set($update['alma_preferred_branch']); } } /** - * Set preferred pickup branch + * Set preferred pickup branch. + * + * @TODO: Is the branch format here correct and where is this function called + * from. + * */ function alma_reservation_set_preferred_branch($account, $branch) { // Throws an exception if we are not logged in. $creds = ding_user_get_creds($account); - /** - * @todo Should call alma an update the branch in the library system (not sure - * if branch has the right format). - */ - //alma_client_invoke('get_reservations', $creds['name'], $creds['pass'], $branch); + // Update preferred branch. + alma_client_invoke('get_reservations', $creds['name'], $creds['pass'], $branch); } /** @@ -264,10 +272,13 @@ function alma_reservation_branch_name($branch_id) { return NULL; } -/********************************** - * Helper functions +/** + * @TODO: add description. + * + * @param type $account + * @param type $reset + * @return type */ - function alma_reservation_get_reservations($account, $reset = FALSE) { $creds = ding_user_get_creds($account); @@ -279,10 +290,20 @@ function alma_reservation_get_reservations($account, $reset = FALSE) { return $_SESSION['alma_reservations']; } +/** + * @TODO: add description. + */ function alma_reservation_clear_cache() { unset($_SESSION['alma_reservations']); } +/** + * @TODO: add description. + * + * @param type $account + * @param type $item_id + * @return boolean + */ function alma_reservation_exists($account, $item_id) { $reservations = alma_reservation_get_reservations($account); foreach ($reservations as $res) { @@ -293,6 +314,12 @@ function alma_reservation_exists($account, $item_id) { } } +/** + * @TODO: add description. + * + * @param type $datetime + * @return type + */ function alma_reservation_format_date($datetime) { $timestamp = (!is_int($datetime)) ? strtotime($datetime) : $datetime; return date('Y-m-d', $timestamp); diff --git a/includes/alma.user.inc b/includes/alma.user.inc index b59e321..a875670 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -1,4 +1,9 @@ Date: Wed, 10 Apr 2013 20:23:42 +0200 Subject: [PATCH 026/158] Updated field weights --- alma.features.field.inc | 110 ++++++++++++++++++++++++---------------- alma.info | 1 + 2 files changed, 66 insertions(+), 45 deletions(-) diff --git a/alma.features.field.inc b/alma.features.field.inc index bc6dead..0075d9b 100644 --- a/alma.features.field.inc +++ b/alma.features.field.inc @@ -43,11 +43,13 @@ function alma_field_default_fields() { 'settings' => array(), 'type' => 'virtual_field', ), - 'virtual_field' => array( - 'entity_types' => array('profile2'), - ), 'translatable' => '0', 'type' => 'text', + 'virtual_field' => array( + 'entity_types' => array( + 0 => 'profile2', + ), + ), ), 'field_instance' => array( 'bundle' => 'provider_alma', @@ -59,7 +61,7 @@ function alma_field_default_fields() { 'label' => 'hidden', 'settings' => array(), 'type' => 'hidden', - 'weight' => '4', + 'weight' => '8', ), ), 'entity_type' => 'profile2', @@ -115,11 +117,13 @@ function alma_field_default_fields() { 'settings' => array(), 'type' => 'virtual_field', ), - 'virtual_field' => array( - 'entity_types' => array('profile2'), - ), 'translatable' => '0', 'type' => 'text', + 'virtual_field' => array( + 'entity_types' => array( + 0 => 'profile2', + ), + ), ), 'field_instance' => array( 'bundle' => 'provider_alma', @@ -132,7 +136,7 @@ function alma_field_default_fields() { 'module' => 'text', 'settings' => array(), 'type' => 'text_default', - 'weight' => 9, + 'weight' => '3', ), ), 'entity_type' => 'profile2', @@ -188,11 +192,13 @@ function alma_field_default_fields() { 'settings' => array(), 'type' => 'virtual_field', ), - 'virtual_field' => array( - 'entity_types' => array('profile2'), - ), 'translatable' => '0', 'type' => 'text', + 'virtual_field' => array( + 'entity_types' => array( + 0 => 'profile2', + ), + ), ), 'field_instance' => array( 'bundle' => 'provider_alma', @@ -205,7 +211,7 @@ function alma_field_default_fields() { 'module' => 'text', 'settings' => array(), 'type' => 'text_default', - 'weight' => 6, + 'weight' => '0', ), ), 'entity_type' => 'profile2', @@ -260,11 +266,13 @@ function alma_field_default_fields() { 'settings' => array(), 'type' => 'virtual_field', ), - 'virtual_field' => array( - 'entity_types' => array('profile2'), - ), 'translatable' => '0', 'type' => 'list_text', + 'virtual_field' => array( + 'entity_types' => array( + 0 => 'profile2', + ), + ), ), 'field_instance' => array( 'bundle' => 'provider_alma', @@ -280,8 +288,8 @@ function alma_field_default_fields() { 'label' => 'above', 'module' => 'list', 'settings' => array(), - 'type' => 'hidden', - 'weight' => '1', + 'type' => 'list_default', + 'weight' => '7', ), ), 'entity_type' => 'profile2', @@ -334,11 +342,13 @@ function alma_field_default_fields() { 'settings' => array(), 'type' => 'virtual_field', ), - 'virtual_field' => array( - 'entity_types' => array('profile2'), - ), 'translatable' => '0', 'type' => 'text', + 'virtual_field' => array( + 'entity_types' => array( + 0 => 'profile2', + ), + ), ), 'field_instance' => array( 'bundle' => 'provider_alma', @@ -350,8 +360,8 @@ function alma_field_default_fields() { 'label' => 'above', 'module' => 'text', 'settings' => array(), - 'type' => 'hidden', - 'weight' => '3', + 'type' => 'text_default', + 'weight' => '4', ), ), 'entity_type' => 'profile2', @@ -406,11 +416,13 @@ function alma_field_default_fields() { 'settings' => array(), 'type' => 'virtual_field', ), - 'virtual_field' => array( - 'entity_types' => array('profile2'), - ), 'translatable' => '0', 'type' => 'text', + 'virtual_field' => array( + 'entity_types' => array( + 0 => 'profile2', + ), + ), ), 'field_instance' => array( 'bundle' => 'provider_alma', @@ -422,7 +434,7 @@ function alma_field_default_fields() { 'label' => 'hidden', 'settings' => array(), 'type' => 'hidden', - 'weight' => '5', + 'weight' => '9', ), ), 'entity_type' => 'profile2', @@ -477,11 +489,13 @@ function alma_field_default_fields() { 'settings' => array(), 'type' => 'virtual_field', ), - 'virtual_field' => array( - 'entity_types' => array('profile2'), - ), 'translatable' => '0', 'type' => 'text', + 'virtual_field' => array( + 'entity_types' => array( + 0 => 'profile2', + ), + ), ), 'field_instance' => array( 'bundle' => 'provider_alma', @@ -494,7 +508,7 @@ function alma_field_default_fields() { 'module' => 'text', 'settings' => array(), 'type' => 'text_default', - 'weight' => 8, + 'weight' => '2', ), ), 'entity_type' => 'profile2', @@ -544,11 +558,13 @@ function alma_field_default_fields() { 'settings' => array(), 'type' => 'virtual_field', ), - 'virtual_field' => array( - 'entity_types' => array('profile2'), - ), 'translatable' => '0', 'type' => 'list_text', + 'virtual_field' => array( + 'entity_types' => array( + 0 => 'profile2', + ), + ), ), 'field_instance' => array( 'bundle' => 'provider_alma', @@ -560,8 +576,8 @@ function alma_field_default_fields() { 'label' => 'above', 'module' => 'list', 'settings' => array(), - 'type' => 'hidden', - 'weight' => '0', + 'type' => 'list_default', + 'weight' => '5', ), ), 'entity_type' => 'profile2', @@ -614,11 +630,13 @@ function alma_field_default_fields() { 'settings' => array(), 'type' => 'virtual_field', ), - 'virtual_field' => array( - 'entity_types' => array('profile2'), - ), 'translatable' => '0', 'type' => 'date', + 'virtual_field' => array( + 'entity_types' => array( + 0 => 'profile2', + ), + ), ), 'field_instance' => array( 'bundle' => 'provider_alma', @@ -635,8 +653,8 @@ function alma_field_default_fields() { 'multiple_number' => '', 'multiple_to' => '', ), - 'type' => 'hidden', - 'weight' => '2', + 'type' => 'date_default', + 'weight' => '6', ), ), 'entity_type' => 'profile2', @@ -702,11 +720,13 @@ function alma_field_default_fields() { 'settings' => array(), 'type' => 'virtual_field', ), - 'virtual_field' => array( - 'entity_types' => array('profile2'), - ), 'translatable' => '0', 'type' => 'text', + 'virtual_field' => array( + 'entity_types' => array( + 0 => 'profile2', + ), + ), ), 'field_instance' => array( 'bundle' => 'provider_alma', @@ -719,7 +739,7 @@ function alma_field_default_fields() { 'module' => 'text', 'settings' => array(), 'type' => 'text_default', - 'weight' => 7, + 'weight' => '1', ), ), 'entity_type' => 'profile2', @@ -749,12 +769,12 @@ function alma_field_default_fields() { t('Full name'); t('Interest period'); t('Phone'); + t('Phone id'); t('Postal code'); t('Preferred branch'); t('Reservation pause'); t('Set your reservations on pause.'); t('Street name'); - t('Phone id'); return $fields; } diff --git a/alma.info b/alma.info index bf744d9..8f595f3 100644 --- a/alma.info +++ b/alma.info @@ -11,6 +11,7 @@ dependencies[] = ding_reservation dependencies[] = features dependencies[] = list dependencies[] = profile2 +dependencies[] = virtual_field features[features_api][] = api:1 features[field][] = profile2-provider_alma-field_alma_absent_id features[field][] = profile2-provider_alma-field_alma_city From 0e31956c6529b533b95a909d5bff97a572aa856a Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 10 Apr 2013 20:31:52 +0200 Subject: [PATCH 027/158] Disabled edit of fields that should not be changed by the user on the profile --- alma.features.field.inc | 65 +++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/alma.features.field.inc b/alma.features.field.inc index 0075d9b..34eabb4 100644 --- a/alma.features.field.inc +++ b/alma.features.field.inc @@ -73,13 +73,10 @@ function alma_field_default_fields() { 'user_register_form' => FALSE, ), 'widget' => array( - 'active' => 1, - 'module' => 'text', - 'settings' => array( - 'size' => '60', - ), - 'type' => 'text_textfield', - 'weight' => '7', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => '38', ), ), ); @@ -148,13 +145,10 @@ function alma_field_default_fields() { 'user_register_form' => FALSE, ), 'widget' => array( - 'active' => 1, - 'module' => 'text', - 'settings' => array( - 'size' => '60', - ), - 'type' => 'text_textfield', - 'weight' => '3', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => '38', ), ), ); @@ -223,13 +217,10 @@ function alma_field_default_fields() { 'user_register_form' => FALSE, ), 'widget' => array( - 'active' => 1, - 'module' => 'text', - 'settings' => array( - 'size' => '60', - ), - 'type' => 'text_textfield', - 'weight' => '0', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => '38', ), ), ); @@ -446,12 +437,10 @@ function alma_field_default_fields() { 'user_register_form' => FALSE, ), 'widget' => array( - 'module' => 'text', - 'settings' => array( - 'size' => 60, - ), - 'type' => 'text_textfield', - 'weight' => '9', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => '38', ), ), ); @@ -520,13 +509,10 @@ function alma_field_default_fields() { 'user_register_form' => FALSE, ), 'widget' => array( - 'active' => 1, - 'module' => 'text', - 'settings' => array( - 'size' => '60', - ), - 'type' => 'text_textfield', - 'weight' => '2', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => '38', ), ), ); @@ -751,13 +737,10 @@ function alma_field_default_fields() { 'user_register_form' => FALSE, ), 'widget' => array( - 'active' => 1, - 'module' => 'text', - 'settings' => array( - 'size' => '60', - ), - 'type' => 'text_textfield', - 'weight' => '1', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => '38', ), ), ); From 1fbf8513965d55bfdcae7b3c13fbdc57abda4cd4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 11 Apr 2013 15:18:32 +0200 Subject: [PATCH 028/158] Added new email field to the profile2 profile --- alma.features.field.inc | 93 ++++++++++++++++++++++++++++++++--------- alma.info | 2 + 2 files changed, 75 insertions(+), 20 deletions(-) diff --git a/alma.features.field.inc b/alma.features.field.inc index 34eabb4..a44b944 100644 --- a/alma.features.field.inc +++ b/alma.features.field.inc @@ -61,7 +61,7 @@ function alma_field_default_fields() { 'label' => 'hidden', 'settings' => array(), 'type' => 'hidden', - 'weight' => '8', + 'weight' => '9', ), ), 'entity_type' => 'profile2', @@ -76,7 +76,7 @@ function alma_field_default_fields() { 'module' => 'virtual_field', 'settings' => array(), 'type' => 'hidden', - 'weight' => '38', + 'weight' => '9', ), ), ); @@ -129,7 +129,7 @@ function alma_field_default_fields() { 'description' => '', 'display' => array( 'default' => array( - 'label' => 'above', + 'label' => 'inline', 'module' => 'text', 'settings' => array(), 'type' => 'text_default', @@ -148,7 +148,7 @@ function alma_field_default_fields() { 'module' => 'virtual_field', 'settings' => array(), 'type' => 'hidden', - 'weight' => '38', + 'weight' => '3', ), ), ); @@ -201,7 +201,7 @@ function alma_field_default_fields() { 'description' => '', 'display' => array( 'default' => array( - 'label' => 'above', + 'label' => 'inline', 'module' => 'text', 'settings' => array(), 'type' => 'text_default', @@ -220,7 +220,7 @@ function alma_field_default_fields() { 'module' => 'virtual_field', 'settings' => array(), 'type' => 'hidden', - 'weight' => '38', + 'weight' => '0', ), ), ); @@ -276,11 +276,11 @@ function alma_field_default_fields() { 'description' => '', 'display' => array( 'default' => array( - 'label' => 'above', + 'label' => 'inline', 'module' => 'list', 'settings' => array(), 'type' => 'list_default', - 'weight' => '7', + 'weight' => '8', ), ), 'entity_type' => 'profile2', @@ -300,6 +300,57 @@ function alma_field_default_fields() { ), ); + // Exported field: 'profile2-provider_alma-field_alma_mail'. + $fields['profile2-provider_alma-field_alma_mail'] = array( + 'field_config' => array( + 'active' => '1', + 'cardinality' => '1', + 'deleted' => '0', + 'entity_types' => array(), + 'field_name' => 'field_alma_mail', + 'foreign keys' => array(), + 'indexes' => array(), + 'locked' => '0', + 'module' => 'email', + 'settings' => array( + 'profile2_private' => 0, + ), + 'translatable' => '0', + 'type' => 'email', + ), + 'field_instance' => array( + 'bundle' => 'provider_alma', + 'default_value' => NULL, + 'deleted' => '0', + 'description' => '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.', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'email', + 'settings' => array(), + 'type' => 'email_plain', + 'weight' => '4', + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_mail', + 'label' => 'E-mail', + 'required' => 0, + 'settings' => array( + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'email', + 'settings' => array( + 'size' => '60', + ), + 'type' => 'email_textfield', + 'weight' => '7', + ), + ), + ); + // Exported field: 'profile2-provider_alma-field_alma_mobile_phone'. $fields['profile2-provider_alma-field_alma_mobile_phone'] = array( 'field_config' => array( @@ -348,11 +399,11 @@ function alma_field_default_fields() { 'description' => '', 'display' => array( 'default' => array( - 'label' => 'above', + 'label' => 'inline', 'module' => 'text', 'settings' => array(), 'type' => 'text_default', - 'weight' => '4', + 'weight' => '5', ), ), 'entity_type' => 'profile2', @@ -425,7 +476,7 @@ function alma_field_default_fields() { 'label' => 'hidden', 'settings' => array(), 'type' => 'hidden', - 'weight' => '9', + 'weight' => '10', ), ), 'entity_type' => 'profile2', @@ -440,7 +491,7 @@ function alma_field_default_fields() { 'module' => 'virtual_field', 'settings' => array(), 'type' => 'hidden', - 'weight' => '38', + 'weight' => '10', ), ), ); @@ -493,7 +544,7 @@ function alma_field_default_fields() { 'description' => '', 'display' => array( 'default' => array( - 'label' => 'above', + 'label' => 'inline', 'module' => 'text', 'settings' => array(), 'type' => 'text_default', @@ -512,7 +563,7 @@ function alma_field_default_fields() { 'module' => 'virtual_field', 'settings' => array(), 'type' => 'hidden', - 'weight' => '38', + 'weight' => '2', ), ), ); @@ -559,11 +610,11 @@ function alma_field_default_fields() { 'description' => '', 'display' => array( 'default' => array( - 'label' => 'above', + 'label' => 'inline', 'module' => 'list', 'settings' => array(), 'type' => 'list_default', - 'weight' => '5', + 'weight' => '6', ), ), 'entity_type' => 'profile2', @@ -630,7 +681,7 @@ function alma_field_default_fields() { 'description' => 'Set your reservations on pause.', 'display' => array( 'default' => array( - 'label' => 'above', + 'label' => 'inline', 'module' => 'date', 'settings' => array( 'format_type' => 'long', @@ -640,7 +691,7 @@ function alma_field_default_fields() { 'multiple_to' => '', ), 'type' => 'date_default', - 'weight' => '6', + 'weight' => '7', ), ), 'entity_type' => 'profile2', @@ -721,7 +772,7 @@ function alma_field_default_fields() { 'description' => '', 'display' => array( 'default' => array( - 'label' => 'above', + 'label' => 'inline', 'module' => 'text', 'settings' => array(), 'type' => 'text_default', @@ -740,7 +791,7 @@ function alma_field_default_fields() { 'module' => 'virtual_field', 'settings' => array(), 'type' => 'hidden', - 'weight' => '38', + 'weight' => '1', ), ), ); @@ -749,6 +800,7 @@ function alma_field_default_fields() { // Included for use with string extractors like potx. t('Absent id'); t('City'); + t('E-mail'); t('Full name'); t('Interest period'); t('Phone'); @@ -758,6 +810,7 @@ function alma_field_default_fields() { t('Reservation pause'); 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.'); return $fields; } diff --git a/alma.info b/alma.info index 8f595f3..1d7f4e9 100644 --- a/alma.info +++ b/alma.info @@ -8,6 +8,7 @@ project = alma dependencies[] = date dependencies[] = ding_provider dependencies[] = ding_reservation +dependencies[] = email dependencies[] = features dependencies[] = list dependencies[] = profile2 @@ -17,6 +18,7 @@ features[field][] = profile2-provider_alma-field_alma_absent_id features[field][] = profile2-provider_alma-field_alma_city features[field][] = profile2-provider_alma-field_alma_full_name features[field][] = profile2-provider_alma-field_alma_interest_period +features[field][] = profile2-provider_alma-field_alma_mail features[field][] = profile2-provider_alma-field_alma_mobile_phone features[field][] = profile2-provider_alma-field_alma_phone_id features[field][] = profile2-provider_alma-field_alma_postal_code From 7d230a04b4cb732263823e9353805ffde598c486 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 11 Apr 2013 20:08:40 +0200 Subject: [PATCH 029/158] Moved mail updateds into the providers hook_profile2_presave() --- alma.features.field.inc | 2 +- alma.module | 50 +++++++++++++++++++++++++++++++++-------- includes/alma.user.inc | 20 +++++------------ 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/alma.features.field.inc b/alma.features.field.inc index a44b944..2475912 100644 --- a/alma.features.field.inc +++ b/alma.features.field.inc @@ -325,7 +325,7 @@ function alma_field_default_fields() { 'description' => '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.', 'display' => array( 'default' => array( - 'label' => 'above', + 'label' => 'inline', 'module' => 'email', 'settings' => array(), 'type' => 'email_plain', diff --git a/alma.module b/alma.module index f7b619f..70f6e13 100644 --- a/alma.module +++ b/alma.module @@ -287,9 +287,7 @@ function alma_profile2_presave($entity) { } } - /** - * Mobile phone. - */ + // Mobile phone. $value = $wrapper->field_alma_mobile_phone->value(); if (!is_null($wrapper_original->field_alma_mobile_phone->value())) { // Update mobile phone number. @@ -305,7 +303,11 @@ function alma_profile2_presave($entity) { $changes['mobile'] = $value; } - // Interest period ? apparently not an alma parameter.. @todo; check if Interest period should be saved on provider + // Get the mail. + $value = $wrapper->field_alma_mail->value(); + if (!is_null($value)) { + $changes['mail'] = $value; + } // Update provider if (!empty($changes)) { @@ -314,11 +316,11 @@ function alma_profile2_presave($entity) { } } -function alma_update_provider($changes, $profile2) { +function alma_update_provider($changes, $entity) { $error_message = t('Error communicating with library system. '); try { - $creds = ding_user_get_creds($profile2); + $creds = ding_user_get_creds($entity); } catch (Exception $e) { // Re-throw ?? @@ -422,6 +424,36 @@ function alma_update_provider($changes, $profile2) { drupal_set_message($error_message, 'warning'); } } + + // Update email (remeber to update the drupal user account). + if (!empty($changes['mail'])) { + global $user; + + // Update or add mail to alma + try { + // Add email + if (empty($user->mail) && !empty($changes['mail'])) { + $res = alma_client_invoke('add_email_address', $creds['name'], $creds['pass'], $changes['mail']); + } + // Change email + elseif (isset($user->mail) && !empty($changes['mail'])) { + $res = alma_client_invoke('change_email_address', $creds['name'], $creds['pass'], $user->mail, $changes['mail']); + } + } + catch (Exception $e) { + watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); + } + + if (empty($res)) { + $error_message .= t('mail was not saved'); + drupal_set_message($error_message, 'warning'); + } + else { + // Update drupal user account mail. + $user->mail = $changes['mail']; + user_save($user); + } + } } /** @@ -557,9 +589,9 @@ function alma_profile2_load($entities) { // Interest periode. $wrapper->field_alma_interest_period->set('180'); // WHERE IS IT STORED. - /** - * @TODO: Should mail be moved into the profile ? It would resolve all issue with the same email for diff users. - */ + + // Mail address. + $wrapper->field_alma_mail->set($patron->email); } } } \ No newline at end of file diff --git a/includes/alma.user.inc b/includes/alma.user.inc index a875670..60387a0 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -58,6 +58,7 @@ function alma_user_authenticate($uid, $pass) { 'country' => $res['addresses'][0]['country'], ); } + return $return; } @@ -88,10 +89,10 @@ function alma_user_clear_cache($creds = NULL) { } /** - * Update the information at alma e-mail and pin code. - * - * @TODO: Is this used any longer or are every ting running through profile2 ? + * Update pin code at alma. * + * @TODO: Rename this function to change hook_alma_change_pincode and in + * ding_user line 240. * * @param type $account * @param type $changes @@ -100,18 +101,7 @@ function alma_user_clear_cache($creds = NULL) { function alma_user_account_update($account, $changes) { $creds = ding_user_get_creds($account); - if (isset($changes['mail'])) { - // Add email - if (empty($account->mail) && !empty($changes['mail'])) { - $res = alma_client_invoke('add_email_address', $creds['name'], $creds['pass'], $changes['mail']); - } - // Change email - elseif (isset($account->mail) && !empty($changes['mail'])) { - $res = alma_client_invoke('change_email_address', $creds['name'], $creds['pass'], $account->mail, $changes['mail']); - } - } - - // Change password. + // Change the users pin code.. if (isset($changes['pass'])) { $res = alma_client_invoke('change_pin', $creds['name'], $creds['pass'], $changes['pass']); if ($res) { From d771d724b08c7a8c1b17ffbab9448ef10f35f257 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 11 Apr 2013 20:27:07 +0200 Subject: [PATCH 030/158] Moved interest periode back into the DB as alma do not support storing this value --- alma.features.field.inc | 11 ----------- alma.install | 1 + alma.module | 6 +++--- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/alma.features.field.inc b/alma.features.field.inc index 2475912..9903094 100644 --- a/alma.features.field.inc +++ b/alma.features.field.inc @@ -251,19 +251,8 @@ function alma_field_default_fields() { 'allowed_values_function' => '', 'profile2_private' => 0, ), - 'storage' => array( - 'active' => '1', - 'module' => 'virtual_field', - 'settings' => array(), - 'type' => 'virtual_field', - ), 'translatable' => '0', 'type' => 'list_text', - 'virtual_field' => array( - 'entity_types' => array( - 0 => 'profile2', - ), - ), ), 'field_instance' => array( 'bundle' => 'provider_alma', diff --git a/alma.install b/alma.install index 1850afe..908708b 100644 --- a/alma.install +++ b/alma.install @@ -23,5 +23,6 @@ function alma_update_7002() { 'storage_module' => 'virtual_field', )) ->condition('field_name', '%alma%', 'LIKE') + ->condition('field_name', 'field_alma_interest_period', 'NOT') ->execute(); } diff --git a/alma.module b/alma.module index 70f6e13..79182df 100644 --- a/alma.module +++ b/alma.module @@ -542,6 +542,9 @@ function alma_replace_entity($item) { * seams to be the right place and at the same time ensure that the information * is not stored locally. * + * Note: that the interest period is store locally in the database as alma do + * not have the ability to store it. So that field is not fill in here. + * */ function alma_profile2_load($entities) { foreach ($entities as $id => &$entity) { @@ -587,9 +590,6 @@ function alma_profile2_load($entities) { $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); - // Interest periode. - $wrapper->field_alma_interest_period->set('180'); // WHERE IS IT STORED. - // Mail address. $wrapper->field_alma_mail->set($patron->email); } From 0d843778036c71dd5efb038b943a4a800f929032 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 11 Apr 2013 20:40:32 +0200 Subject: [PATCH 031/158] Fixed interest period field in update and change mail to use virtual field --- alma.features.field.inc | 6 ++++++ alma.install | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/alma.features.field.inc b/alma.features.field.inc index 9903094..5f51166 100644 --- a/alma.features.field.inc +++ b/alma.features.field.inc @@ -304,6 +304,12 @@ function alma_field_default_fields() { 'settings' => array( 'profile2_private' => 0, ), + 'storage' => array( + 'active' => '1', + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), 'translatable' => '0', 'type' => 'email', ), diff --git a/alma.install b/alma.install index 908708b..d3c2844 100644 --- a/alma.install +++ b/alma.install @@ -23,6 +23,6 @@ function alma_update_7002() { 'storage_module' => 'virtual_field', )) ->condition('field_name', '%alma%', 'LIKE') - ->condition('field_name', 'field_alma_interest_period', 'NOT') + ->condition('field_name', 'field_alma_interest_period', '!=') ->execute(); } From 636efd17b2b6353615a72e2bb1ad9870381b3b1e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 12 Apr 2013 08:02:50 +0200 Subject: [PATCH 032/158] Changed the alma reservation pause field to a real datetime field --- alma.features.field.inc | 2 +- alma.module | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/alma.features.field.inc b/alma.features.field.inc index 5f51166..36659c9 100644 --- a/alma.features.field.inc +++ b/alma.features.field.inc @@ -663,7 +663,7 @@ function alma_field_default_fields() { 'type' => 'virtual_field', ), 'translatable' => '0', - 'type' => 'date', + 'type' => 'datetime', 'virtual_field' => array( 'entity_types' => array( 0 => 'profile2', diff --git a/alma.module b/alma.module index 79182df..d5f9fdd 100644 --- a/alma.module +++ b/alma.module @@ -569,8 +569,8 @@ function alma_profile2_load($entities) { )); if (isset($patron->absentPeriods[0]['from_date']) && isset($patron->absentPeriods[0]['to_date'])) { $wrapper->field_alma_reservation_pause->set(array( - 'value' => $patron->absentPeriods[0]['from_date'], - 'value2' => $patron->absentPeriods[0]['to_date'], + 'value' => $patron->absentPeriods[0]['from_date'] . ' 00:00:00', + 'value2' => $patron->absentPeriods[0]['to_date'] . ' 00:00:00', )); $wrapper->field_alma_absent_id->set($patron->absentPeriods[0]['id']); } From f98381b33a1e9f419ca3d6dc3e92fe65e8a3b422 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 12 Apr 2013 08:22:33 +0200 Subject: [PATCH 033/158] Added update function to change the reservation pause field type in the DB --- alma.install | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/alma.install b/alma.install index d3c2844..b56328a 100644 --- a/alma.install +++ b/alma.install @@ -14,7 +14,7 @@ function alma_update_7001() { } /** - * Convert field storage to virtual field. + * Convert field storage to virtual field. */ function alma_update_7002() { return db_update('field_config') @@ -26,3 +26,15 @@ function alma_update_7002() { ->condition('field_name', 'field_alma_interest_period', '!=') ->execute(); } + +/** + * Covert reservation field form data to datetime. + */ +function alma_update_7003() { + return db_update('field_config') + ->fields(array( + 'type' => 'datetime' + )) + ->condition('field_name', 'field_alma_reservation_pause', '=') + ->execute(); +} \ No newline at end of file From 473ca7521795ac7b9fc926eb0cafaa053be91737 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 12 Apr 2013 13:48:15 +0200 Subject: [PATCH 034/158] Added configuration option to enter max pin code lenght and hook to return it to ding_user --- alma.module | 11 +++++++---- includes/alma.user.inc | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/alma.module b/alma.module index d5f9fdd..40e0aaa 100644 --- a/alma.module +++ b/alma.module @@ -11,10 +11,6 @@ define('ALMA_AUTH_BLOCKED', '4e5531951f55ab8f6895684999c69c2'); * Get list of pickup branches. */ function alma_reservation_pickup_branches($account = NULL) { - // Throw exception if we're not logged in. ?? WHY this method needs no credentials - // ding_user_get_creds($account); - // return alma_client_invoke('get_reservation_branches'); - // Cache alma pickup branches - they are not likely to change static $alma_pickup_branches; if (!isset($alma_pickup_branches)) { @@ -114,6 +110,13 @@ function alma_settings_form() { '#default_value' => variable_get('alma_base_url', ''), ); + $form['alma']['alma_pincode_length'] = array( + '#type' => 'textfield', + '#title' => t('Length of the pin code'), + '#default_value' => variable_get('alma_pincode_length', '4'), + '#description' => t('The different libraries uses different pin code lenght (defaults to four).'), + ); + $form['alma']['alma_enable_reservation_deletion'] = array( '#type' => 'checkbox', '#title' => t('Enable reservation deletion'), diff --git a/includes/alma.user.inc b/includes/alma.user.inc index 60387a0..f67c08b 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -58,7 +58,7 @@ function alma_user_authenticate($uid, $pass) { 'country' => $res['addresses'][0]['country'], ); } - + return $return; } @@ -91,7 +91,7 @@ function alma_user_clear_cache($creds = NULL) { /** * Update pin code at alma. * - * @TODO: Rename this function to change hook_alma_change_pincode and in + * @TODO: Rename this function to change hook_alma_change_pincode and in * ding_user line 240. * * @param type $account @@ -116,3 +116,15 @@ function alma_user_account_update($account, $changes) { } } } + +/** + * Implements hook_user_pincode_length(). + * + * @return int + * The length of the pin code given on the configuration page for alma. It's + * used in the frontend to validate the max length of the pin code allowed for + * this installation. + */ +function alma_user_pincode_length() { + return variable_get('alma_pincode_length', 4); +} \ No newline at end of file From 580d1b3f3d8a342b779f5e089b450d511a79e87a Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 12 Apr 2013 13:59:45 +0200 Subject: [PATCH 035/158] Updated provider call account_update to update_pincode as it only updates pin code after provider profile was added --- includes/alma.user.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/alma.user.inc b/includes/alma.user.inc index f67c08b..60dd118 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -98,16 +98,16 @@ function alma_user_clear_cache($creds = NULL) { * @param type $changes * @return type */ -function alma_user_account_update($account, $changes) { +function alma_user_update_pincode($account, $new_pincode) { $creds = ding_user_get_creds($account); // Change the users pin code.. - if (isset($changes['pass'])) { - $res = alma_client_invoke('change_pin', $creds['name'], $creds['pass'], $changes['pass']); + if (isset($new_pincode)) { + $res = alma_client_invoke('change_pin', $creds['name'], $creds['pass'], $new_pincode); if ($res) { // @see ding_user.module/ding_user_user_presave // Set new password. - $creds['pass'] = $changes['pass']; + $creds['pass'] = $new_pincode; // Update creds. $result = array(); From 46b03b04f6ac055e2ea27c88cfcbc4ef072d504e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 12 Apr 2013 16:52:59 +0200 Subject: [PATCH 036/158] Added update function to remove un-used field database tables after switch to virtual fields --- alma.install | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/alma.install b/alma.install index b56328a..5f64866 100644 --- a/alma.install +++ b/alma.install @@ -37,4 +37,30 @@ function alma_update_7003() { )) ->condition('field_name', 'field_alma_reservation_pause', '=') ->execute(); -} \ No newline at end of file +} + +/** + * Remove old field_sql_storage file data from the database as they are using + * virtual fields now and don't need a database table. + */ +function alma_update_7004() { + // Absent id have been renamed to field_alma_absent_id as virtual field. + field_delete_field('field_absent_id'); + field_purge_batch(100); + + // Mobile phone. + db_drop_table('field_data_field_alma_mobile_phone'); + db_drop_table('field_revision_field_alma_mobile_phone'); + + // Mobile phone id. + db_drop_table('field_data_field_alma_phone_id'); + db_drop_table('field_revision_field_alma_phone_id'); + + // Preferred branch. + db_drop_table('field_data_field_alma_preferred_branch'); + db_drop_table('field_revision_field_alma_preferred_branch'); + + // Reservation pause. + db_drop_table('field_data_field_alma_reservation_pause'); + db_drop_table('field_revision_field_alma_reservation_pause'); +} From c0169b7478f4fc1f3889afce26ca96712c38f736 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 16 Apr 2013 08:09:36 +0200 Subject: [PATCH 037/158] Added hook_enable to create profile2 type on module activation --- alma.install | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/alma.install b/alma.install index 5f64866..911ef63 100644 --- a/alma.install +++ b/alma.install @@ -1,6 +1,22 @@ 'provider_alma', + 'label' => t('Profile for Alma'), + 'userCategory' => TRUE, + 'userView' => TRUE, + ) + ); + $profile_type->save(); +} /** * Update system table set alma weight=10 to ensure form_alter hooks are called From 809943ec6fab2d213beb9efd6f85e2e8e0829d48 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 17 Apr 2013 12:44:32 +0200 Subject: [PATCH 038/158] Catch exception if the user is not logged in. Happens when trying to delete user --- alma.module | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/alma.module b/alma.module index 40e0aaa..88ee146 100644 --- a/alma.module +++ b/alma.module @@ -558,7 +558,15 @@ function alma_profile2_load($entities) { if (!isset($patron)) { // Get information from alma about the current user. global $user; - $creds = ding_user_get_creds($user); + try { + $creds = ding_user_get_creds($user); + } + catch (DingProviderAuthException $e) { + // The user was not logged in, hence we can't fill out the profile. + return; + } + + // Get uers information from alma. $patron = alma_get_patron($creds); } From 934095ffeeac676d65513a6b0e30cdcfea1ff361 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 18 Apr 2013 11:15:29 +0200 Subject: [PATCH 039/158] Move pin code lenght into ding_user and ensured that presave it not executed on profile creation --- alma.module | 6 +++++- includes/alma.user.inc | 12 ------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/alma.module b/alma.module index 88ee146..d2ee85a 100644 --- a/alma.module +++ b/alma.module @@ -253,7 +253,11 @@ function _alma_user_info($creds = NULL) { * Updates changes add to the profile when its saved. */ function alma_profile2_presave($entity) { - if ($entity->type == 'provider_alma') { + // Check if the profile is just being created and is an alma_provider profile. + // If it's being created the fields are not yet loaded and can't be saved back + // to the provider. + $try_to_save = ($entity->created == $entity->changed) ? FALSE : TRUE; + if ($entity->type == 'provider_alma' && $try_to_save) { $changes = array(); // Use a metadata wrapper to access the data. diff --git a/includes/alma.user.inc b/includes/alma.user.inc index 60dd118..85396f6 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -115,16 +115,4 @@ function alma_user_update_pincode($account, $new_pincode) { return $result; } } -} - -/** - * Implements hook_user_pincode_length(). - * - * @return int - * The length of the pin code given on the configuration page for alma. It's - * used in the frontend to validate the max length of the pin code allowed for - * this installation. - */ -function alma_user_pincode_length() { - return variable_get('alma_pincode_length', 4); } \ No newline at end of file From 0f01d46199340038389e86e7c3d9867963cc85b2 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 18 Apr 2013 14:34:05 +0200 Subject: [PATCH 040/158] Updated handling of availability information for periodical and internet resources --- includes/alma.availability.inc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index 6a37eb7..c628aed 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -22,11 +22,21 @@ function alma_availability_holdings($provider_ids) { 'holdings' => $record['holdings'], 'reserved_count' => (int) $record['reservation_count'], 'deferred_period' => FALSE, - 'issues' => _alma_populate_issues($record['holdings']), + 'issues' => FALSE, 'is_periodical' => ($record['media_class'] == 'periodical'), 'is_internet' => ($record['media_class'] == 'internet'), ); + // If periodical render issue information. + if ($holding['is_periodical']) { + $holding['issues'] = _alma_populate_issues($record['holdings']); + } + + // If it's an internet holding, don't display holdings information. + if ($holding['is_internet']) { + $holding['holdings'] = FALSE; + } + $result[$alma_id] = $holding; $result[$alma_id]['html'] = _alma_get_holdings($details, $holding['is_periodical']); From c35aaf294591511ef7ace29c34dd8c0b9c940070 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 18 Apr 2013 15:16:26 +0200 Subject: [PATCH 041/158] Fixed reservation index error --- includes/alma.reservation.inc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index b8c44a1..7f7b076 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -61,7 +61,7 @@ function alma_reservation_options_validate($type, $account, $reservables, $value ); } else { - $branch_valid = ding_reservation_default_options_branch_validate($type, 'alma_preferred_branch', $$preferred_branch, $values); + $branch_valid = ding_reservation_default_options_branch_validate($type, 'alma_preferred_branch', $preferred_branch, $values); $period_valid = ding_reservation_default_options_interest_period_validate($type, 'alma_interest_period', $interest_period, $values); return array_merge($branch_valid, $period_valid); } @@ -157,8 +157,8 @@ function alma_reservation_create($account, $id, $branch, $expiry = NULL) { throw new DingProviderReservationExists(); } - $profile2 = profile2_load_by_user($account, 'provider_alma'); - if (!empty($profile2)) { + $entity = profile2_load_by_user($account, 'provider_alma'); + if (!empty($entity)) { $wrapper = entity_metadata_wrapper('profile2', $entity); // interest period if (!isset($expiry)) { @@ -188,6 +188,7 @@ function alma_reservation_create($account, $id, $branch, $expiry = NULL) { ); alma_reservation_clear_cache(); + // Try to make the reservation. $result = alma_client_invoke('add_reservation', $creds['name'], $creds['pass'], $params); From 0a2259268cb39be6c33100159439298c67954d53 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 19 Apr 2013 12:38:06 +0200 Subject: [PATCH 042/158] Added tid to pseudo objects as it is required to display the objects in the different lists --- alma.module | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/alma.module b/alma.module index d2ee85a..4cbae90 100644 --- a/alma.module +++ b/alma.module @@ -504,7 +504,8 @@ function alma_get_patron($creds = NULL, $reset = FALSE, $as_array = FALSE) { } /** - * Replace entity for the reservation in the case object in not in Ting anymore. + * Replace entity for the reservation in the case object in not in Ting anymore + * or the reservation is an remote reservation. * * @param $item * Provider reservation object. @@ -519,6 +520,7 @@ function alma_replace_entity($item) { if ($alma_object['request_status'] == 'ok' && isset($alma_object['records'][$faust_number])) { $source = $alma_object['records'][$faust_number]; $pseudo_ting_object = new TingEntity(); + $pseudo_ting_object->tid = $faust_number; $pseudo_ting_object->localId = $faust_number; $pseudo_ting_object->ding_entity_id = $item->ding_entity_id; $pseudo_ting_object->reply = new TingClientObject(); From e251dd57c129139145f4284617107986ed9683f4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 19 Apr 2013 15:54:12 +0200 Subject: [PATCH 043/158] Added new provider populate_pseudo_entity function and removed old replace_entity function --- alma.module | 40 ---------------------------------------- includes/alma.loan.inc | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 40 deletions(-) diff --git a/alma.module b/alma.module index 4cbae90..25fc2f2 100644 --- a/alma.module +++ b/alma.module @@ -503,46 +503,6 @@ function alma_get_patron($creds = NULL, $reset = FALSE, $as_array = FALSE) { return (object)$patron; } -/** - * Replace entity for the reservation in the case object in not in Ting anymore - * or the reservation is an remote reservation. - * - * @param $item - * Provider reservation object. - * @return - * Ting entity object, filled with data from provider service. - */ -function alma_replace_entity($item) { - $faust_number = explode(':', $item->ding_entity_id); - $faust_number = $faust_number[1]; - $alma_object = alma_client_invoke('catalogue_record_detail', $faust_number); - - if ($alma_object['request_status'] == 'ok' && isset($alma_object['records'][$faust_number])) { - $source = $alma_object['records'][$faust_number]; - $pseudo_ting_object = new TingEntity(); - $pseudo_ting_object->tid = $faust_number; - $pseudo_ting_object->localId = $faust_number; - $pseudo_ting_object->ding_entity_id = $item->ding_entity_id; - $pseudo_ting_object->reply = new TingClientObject(); - $pseudo_ting_object->reply->record['dc:title']['dkdcplus:full'] = array($source['titles'][0]); - $pseudo_ting_object->reply->record['dc:type']['dkdcplus:BibDK-Type'] = array($source['media_class']); - // @todo - // Author from provider. - $pseudo_ting_object->reply->record['dc:creator']['dkdcplus:aut'] = array(''); - $pseudo_ting_object->reply->record['dc:date'][''] = array($source['publication_year']); - $pseudo_ting_object->ting_title = array(LANGUAGE_NONE => array(array('id' => $item->ding_entity_id))); - $pseudo_ting_object->ting_type = array(LANGUAGE_NONE => array(array('id' => $item->ding_entity_id))); - $pseudo_ting_object->ting_author = array(LANGUAGE_NONE => array(array('id' => $item->ding_entity_id))); - $pseudo_ting_object->ting_cover = array(LANGUAGE_NONE => array(array('local_id' => $faust_number))); - $pseudo_ting_object->ding_entity_type = 'ding_entity'; - $pseudo_ting_object->provider_id = $faust_number; - - return $pseudo_ting_object; - } - - return FALSE; -} - /** * Implements hook_profile2_load(). * diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index 7b11aeb..e4e7dfd 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -60,3 +60,32 @@ function alma_loan_renew($account, $ids) { } return $result; } + +/** + * Replace entity for the reservation in the case object in not in Ting anymore + * or the reservation is an remote reservation. + * + * @param $ting_entity + * Provider reservation object. + * @return + * Ting entity object, filled with data from provider service. + */ +function alma_loan_populate_pseudo_entity($ting_entity) { + $alma_object = alma_client_invoke('catalogue_record_detail', $ting_entity->localId); + + if ($alma_object['request_status'] == 'ok' && isset($alma_object['records'][$ting_entity->localId])) { + $source = $alma_object['records'][$ting_entity->localId]; + + $ting_entity->reply->record['dc:title']['dkdcplus:full'] = array($source['titles'][0]); + $ting_entity->reply->record['dc:type']['dkdcplus:BibDK-Type'] = array($source['media_class']); + $ting_entity->reply->record['dc:date'][''] = array($source['publication_year']); + $ting_entity->reply->record['dc:creator']['dkdcplus:aut'] = $source['authors']; + + $ting_entity->ting_title = array(LANGUAGE_NONE => array(array('id' => $ting_entity->ding_entity_id))); + $ting_entity->ting_type = array(LANGUAGE_NONE => array(array('id' => $ting_entity->ding_entity_id))); + $ting_entity->ting_author = array(LANGUAGE_NONE => array(array('id' => $ting_entity->ding_entity_id))); + $ting_entity->ting_cover = array(LANGUAGE_NONE => array(array('local_id' => $ting_entity->localId))); + } + + return $ting_entity; +} \ No newline at end of file From 288057c3c51a656920402ec7a1a64826a04115a1 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 19 Apr 2013 16:50:54 +0200 Subject: [PATCH 044/158] Added dc:identifier to alma pseudo entity --- includes/alma.loan.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index e4e7dfd..0fd9179 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -80,11 +80,12 @@ function alma_loan_populate_pseudo_entity($ting_entity) { $ting_entity->reply->record['dc:type']['dkdcplus:BibDK-Type'] = array($source['media_class']); $ting_entity->reply->record['dc:date'][''] = array($source['publication_year']); $ting_entity->reply->record['dc:creator']['dkdcplus:aut'] = $source['authors']; + $ting_entity->reply->record['dc:identifier']['dkdcplus:ISBN'][0] = str_replace(array('-', ' ', 'ISBN'), '', $source['isbns'][0]); $ting_entity->ting_title = array(LANGUAGE_NONE => array(array('id' => $ting_entity->ding_entity_id))); $ting_entity->ting_type = array(LANGUAGE_NONE => array(array('id' => $ting_entity->ding_entity_id))); $ting_entity->ting_author = array(LANGUAGE_NONE => array(array('id' => $ting_entity->ding_entity_id))); - $ting_entity->ting_cover = array(LANGUAGE_NONE => array(array('local_id' => $ting_entity->localId))); + $ting_entity->ting_cover = array(LANGUAGE_NONE => array(array('local_id' => $ting_entity->provider_id))); } return $ting_entity; From a2bd30b83018d7e2b3d750e1c3498024a4a52cd3 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 22 Apr 2013 15:25:31 +0200 Subject: [PATCH 045/158] Added makefile to the module --- alma.features.field.inc | 1 + alma.make | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 alma.make diff --git a/alma.features.field.inc b/alma.features.field.inc index 36659c9..8fae039 100644 --- a/alma.features.field.inc +++ b/alma.features.field.inc @@ -247,6 +247,7 @@ function alma_field_default_fields() { 60 => '2 months', 90 => '3 months', 180 => '6 months', + 360 => '1 year', ), 'allowed_values_function' => '', 'profile2_private' => 0, diff --git a/alma.make b/alma.make new file mode 100644 index 0000000..e5e6919 --- /dev/null +++ b/alma.make @@ -0,0 +1,31 @@ +api = 2 +core = 7.x + +; Contrib + +projects[date][subdir] = "contrib" +projects[date][version] = "2.6" + +projects[email][subdir] = "contrib" +projects[email][version] = "1.2" + +projects[features][subdir] = "contrib" +projects[features][version] = "2.0-beta2" + +projects[profile2][subdir] = "contrib" +projects[profile2][version] = "1.3" + +projects[virtual_field][subdir] = "contrib" +projects[virtual_field][version] = "1.1" + +; Ding! modules + +projects[ding_provider][type] = "module" +projects[ding_provider][download][type] = "git" +projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" +projects[ding_provider][download][branch] = "development" + +projects[ding_reservation][type] = "module" +projects[ding_reservation][download][type] = "git" +projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" +projects[ding_reservation][download][branch] = "development" \ No newline at end of file From bbdeeb5baffd4c4553583078a3d1186cd84cca3c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 24 Apr 2013 21:11:24 +0200 Subject: [PATCH 046/158] Matched Alma http request to the newest drupal core patch to fix ssl version --- lib/AlmaClient/AlmaClient.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index 9ad4626..353a78d 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -55,7 +55,7 @@ public function request($method, $params = array(), $check_status = TRUE) { $startTime = explode(' ', microtime()); // For use with a non-Drupal-system, we should have a way to swap // the HTTP client out. - $request = drupal_http_request(url($this->base_url . $method, array('query' => $params)), array('ssl_version' => 'sslv3')); + $request = drupal_http_request(url($this->base_url . $method, array('query' => $params)), array('secure_socket_transport' => 'sslv3')); $stopTime = explode(' ', microtime()); // For use with a non-Drupal-system, we should have a way to swap // logging and logging preferences out. From 277910cd3467dd8f36f91930264dd3b16be24d34 Mon Sep 17 00:00:00 2001 From: Rasmus Frey Date: Thu, 25 Apr 2013 12:29:49 +0200 Subject: [PATCH 047/158] Exported with features 2 and language as english --- alma.features.field.inc | 812 ------------------------------- alma.features.field_base.inc | 429 ++++++++++++++++ alma.features.field_instance.inc | 396 +++++++++++++++ alma.info | 35 +- 4 files changed, 849 insertions(+), 823 deletions(-) delete mode 100644 alma.features.field.inc create mode 100644 alma.features.field_base.inc create mode 100644 alma.features.field_instance.inc diff --git a/alma.features.field.inc b/alma.features.field.inc deleted file mode 100644 index 8fae039..0000000 --- a/alma.features.field.inc +++ /dev/null @@ -1,812 +0,0 @@ - array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_alma_absent_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', - ), - ), - ), - 'field_instance' => array( - 'bundle' => 'provider_alma', - 'default_value' => NULL, - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'hidden', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => '9', - ), - ), - 'entity_type' => 'profile2', - 'field_name' => 'field_alma_absent_id', - 'label' => 'Absent id', - 'required' => 0, - 'settings' => array( - 'text_processing' => '0', - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'module' => 'virtual_field', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => '9', - ), - ), - ); - - // Exported field: 'profile2-provider_alma-field_alma_city'. - $fields['profile2-provider_alma-field_alma_city'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_alma_city', - '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', - ), - ), - ), - 'field_instance' => array( - 'bundle' => 'provider_alma', - 'default_value' => NULL, - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'inline', - 'module' => 'text', - 'settings' => array(), - 'type' => 'text_default', - 'weight' => '3', - ), - ), - 'entity_type' => 'profile2', - 'field_name' => 'field_alma_city', - 'label' => 'City', - 'required' => 0, - 'settings' => array( - 'text_processing' => '0', - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'module' => 'virtual_field', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => '3', - ), - ), - ); - - // Exported field: 'profile2-provider_alma-field_alma_full_name'. - $fields['profile2-provider_alma-field_alma_full_name'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_alma_full_name', - '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', - ), - ), - ), - 'field_instance' => array( - 'bundle' => 'provider_alma', - 'default_value' => NULL, - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'inline', - 'module' => 'text', - 'settings' => array(), - 'type' => 'text_default', - 'weight' => '0', - ), - ), - 'entity_type' => 'profile2', - 'field_name' => 'field_alma_full_name', - 'label' => 'Full name', - 'required' => 0, - 'settings' => array( - 'text_processing' => '0', - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'module' => 'virtual_field', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => '0', - ), - ), - ); - - // Exported field: 'profile2-provider_alma-field_alma_interest_period'. - $fields['profile2-provider_alma-field_alma_interest_period'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_alma_interest_period', - 'foreign keys' => array(), - 'indexes' => array( - 'value' => array( - 0 => 'value', - ), - ), - 'locked' => '0', - 'module' => 'list', - 'settings' => array( - 'allowed_values' => array( - 30 => '1 måned', - 60 => '2 months', - 90 => '3 months', - 180 => '6 months', - 360 => '1 year', - ), - 'allowed_values_function' => '', - 'profile2_private' => 0, - ), - 'translatable' => '0', - 'type' => 'list_text', - ), - 'field_instance' => array( - 'bundle' => 'provider_alma', - 'default_value' => array( - 0 => array( - 'value' => '30', - ), - ), - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'inline', - 'module' => 'list', - 'settings' => array(), - 'type' => 'list_default', - 'weight' => '8', - ), - ), - 'entity_type' => 'profile2', - 'field_name' => 'field_alma_interest_period', - 'label' => 'Interest period', - 'required' => 0, - 'settings' => array( - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'options', - 'settings' => array(), - 'type' => 'options_select', - 'weight' => '5', - ), - ), - ); - - // Exported field: 'profile2-provider_alma-field_alma_mail'. - $fields['profile2-provider_alma-field_alma_mail'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_alma_mail', - 'foreign keys' => array(), - 'indexes' => array(), - 'locked' => '0', - 'module' => 'email', - 'settings' => array( - 'profile2_private' => 0, - ), - 'storage' => array( - 'active' => '1', - 'module' => 'virtual_field', - 'settings' => array(), - 'type' => 'virtual_field', - ), - 'translatable' => '0', - 'type' => 'email', - ), - 'field_instance' => array( - 'bundle' => 'provider_alma', - 'default_value' => NULL, - 'deleted' => '0', - 'description' => '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.', - 'display' => array( - 'default' => array( - 'label' => 'inline', - 'module' => 'email', - 'settings' => array(), - 'type' => 'email_plain', - 'weight' => '4', - ), - ), - 'entity_type' => 'profile2', - 'field_name' => 'field_alma_mail', - 'label' => 'E-mail', - 'required' => 0, - 'settings' => array( - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'email', - 'settings' => array( - 'size' => '60', - ), - 'type' => 'email_textfield', - 'weight' => '7', - ), - ), - ); - - // Exported field: 'profile2-provider_alma-field_alma_mobile_phone'. - $fields['profile2-provider_alma-field_alma_mobile_phone'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_alma_mobile_phone', - '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' => '16', - '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', - ), - ), - ), - 'field_instance' => 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_mobile_phone', - 'label' => 'Phone', - 'required' => 0, - 'settings' => array( - 'text_processing' => '0', - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'text', - 'settings' => array( - 'size' => '12', - ), - 'type' => 'text_textfield', - 'weight' => '8', - ), - ), - ); - - // Exported field: 'profile2-provider_alma-field_alma_phone_id'. - $fields['profile2-provider_alma-field_alma_phone_id'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_alma_phone_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', - ), - 'storage' => array( - 'active' => '1', - 'module' => 'virtual_field', - 'settings' => array(), - 'type' => 'virtual_field', - ), - 'translatable' => '0', - 'type' => 'text', - 'virtual_field' => array( - 'entity_types' => array( - 0 => 'profile2', - ), - ), - ), - 'field_instance' => array( - 'bundle' => 'provider_alma', - 'default_value' => NULL, - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'hidden', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => '10', - ), - ), - 'entity_type' => 'profile2', - 'field_name' => 'field_alma_phone_id', - 'label' => 'Phone id', - 'required' => FALSE, - 'settings' => array( - 'text_processing' => 0, - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'module' => 'virtual_field', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => '10', - ), - ), - ); - - // Exported field: 'profile2-provider_alma-field_alma_postal_code'. - $fields['profile2-provider_alma-field_alma_postal_code'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_alma_postal_code', - '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', - ), - ), - ), - 'field_instance' => array( - 'bundle' => 'provider_alma', - 'default_value' => NULL, - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'inline', - 'module' => 'text', - 'settings' => array(), - 'type' => 'text_default', - 'weight' => '2', - ), - ), - 'entity_type' => 'profile2', - 'field_name' => 'field_alma_postal_code', - 'label' => 'Postal code', - 'required' => 0, - 'settings' => array( - 'text_processing' => '0', - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'module' => 'virtual_field', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => '2', - ), - ), - ); - - // Exported field: 'profile2-provider_alma-field_alma_preferred_branch'. - $fields['profile2-provider_alma-field_alma_preferred_branch'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_alma_preferred_branch', - 'foreign keys' => array(), - 'indexes' => array( - 'value' => array( - 0 => 'value', - ), - ), - 'locked' => '0', - 'module' => 'list', - 'settings' => array( - 'allowed_values' => array(), - 'allowed_values_function' => 'alma_reservation_pickup_branches', - 'profile2_private' => 0, - ), - 'storage' => array( - 'active' => '1', - 'module' => 'virtual_field', - 'settings' => array(), - 'type' => 'virtual_field', - ), - 'translatable' => '0', - 'type' => 'list_text', - 'virtual_field' => array( - 'entity_types' => array( - 0 => 'profile2', - ), - ), - ), - 'field_instance' => array( - 'bundle' => 'provider_alma', - 'default_value' => NULL, - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'inline', - 'module' => 'list', - 'settings' => array(), - 'type' => 'list_default', - 'weight' => '6', - ), - ), - 'entity_type' => 'profile2', - 'field_name' => 'field_alma_preferred_branch', - 'label' => 'Preferred branch', - 'required' => 0, - 'settings' => array( - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'options', - 'settings' => array(), - 'type' => 'options_select', - 'weight' => '4', - ), - ), - ); - - // Exported field: 'profile2-provider_alma-field_alma_reservation_pause'. - $fields['profile2-provider_alma-field_alma_reservation_pause'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_alma_reservation_pause', - 'foreign keys' => array(), - 'indexes' => array(), - 'locked' => '0', - 'module' => 'date', - 'settings' => array( - 'granularity' => array( - 'day' => 'day', - 'hour' => 0, - 'minute' => 0, - 'month' => 'month', - 'second' => 0, - 'year' => 'year', - ), - 'profile2_private' => 0, - 'repeat' => 0, - 'timezone_db' => '', - 'todate' => 'required', - 'tz_handling' => 'none', - ), - 'storage' => array( - 'active' => '1', - 'module' => 'virtual_field', - 'settings' => array(), - 'type' => 'virtual_field', - ), - 'translatable' => '0', - 'type' => 'datetime', - 'virtual_field' => array( - 'entity_types' => array( - 0 => 'profile2', - ), - ), - ), - 'field_instance' => array( - 'bundle' => 'provider_alma', - 'deleted' => '0', - 'description' => 'Set your reservations on pause.', - 'display' => array( - 'default' => array( - 'label' => 'inline', - 'module' => 'date', - 'settings' => array( - 'format_type' => 'long', - 'fromto' => 'both', - 'multiple_from' => '', - 'multiple_number' => '', - 'multiple_to' => '', - ), - 'type' => 'date_default', - 'weight' => '7', - ), - ), - 'entity_type' => 'profile2', - 'field_name' => 'field_alma_reservation_pause', - 'label' => 'Reservation pause', - 'required' => 0, - 'settings' => array( - 'default_value' => 'blank', - 'default_value2' => 'blank', - 'default_value_code' => '', - 'default_value_code2' => '', - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'date', - 'settings' => array( - 'display_all_day' => 0, - 'increment' => '15', - 'input_format' => 'd/m/Y', - 'input_format_custom' => '', - 'label_position' => 'above', - 'repeat_collapsed' => 0, - 'text_parts' => array(), - 'year_range' => '-3:+3', - ), - 'type' => 'date_popup', - 'weight' => '6', - ), - ), - ); - - // Exported field: 'profile2-provider_alma-field_alma_street_name'. - $fields['profile2-provider_alma-field_alma_street_name'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_alma_street_name', - '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', - ), - ), - ), - 'field_instance' => array( - 'bundle' => 'provider_alma', - 'default_value' => NULL, - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'inline', - 'module' => 'text', - 'settings' => array(), - 'type' => 'text_default', - 'weight' => '1', - ), - ), - 'entity_type' => 'profile2', - 'field_name' => 'field_alma_street_name', - 'label' => 'Street name', - 'required' => 0, - 'settings' => array( - 'text_processing' => '0', - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'module' => 'virtual_field', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => '1', - ), - ), - ); - - // Translatables - // Included for use with string extractors like potx. - t('Absent id'); - t('City'); - t('E-mail'); - t('Full name'); - t('Interest period'); - t('Phone'); - t('Phone id'); - t('Postal code'); - t('Preferred branch'); - t('Reservation pause'); - 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.'); - - return $fields; -} diff --git a/alma.features.field_base.inc b/alma.features.field_base.inc new file mode 100644 index 0000000..59ca658 --- /dev/null +++ b/alma.features.field_base.inc @@ -0,0 +1,429 @@ + 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_alma_absent_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_city' + $field_bases['field_alma_city'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_alma_city', + '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_full_name' + $field_bases['field_alma_full_name'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_alma_full_name', + '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_interest_period' + $field_bases['field_alma_interest_period'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_alma_interest_period', + 'foreign keys' => array(), + 'indexes' => array( + 'value' => array( + 0 => 'value', + ), + ), + 'locked' => 0, + 'module' => 'list', + 'settings' => array( + 'allowed_values' => array( + 30 => '1 måned', + 60 => '2 months', + 90 => '3 months', + 180 => '6 months', + ), + 'allowed_values_function' => '', + 'profile2_private' => 0, + ), + 'translatable' => 0, + 'type' => 'list_text', + ); + + // Exported field_base: 'field_alma_mail' + $field_bases['field_alma_mail'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_alma_mail', + 'foreign keys' => array(), + 'indexes' => array(), + 'locked' => 0, + 'module' => 'email', + 'settings' => array( + 'profile2_private' => 0, + ), + 'storage' => array( + 'active' => 1, + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), + 'translatable' => 0, + 'type' => 'email', + ); + + // Exported field_base: 'field_alma_mobile_phone' + $field_bases['field_alma_mobile_phone'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_alma_mobile_phone', + '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' => 16, + '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_phone_id' + $field_bases['field_alma_phone_id'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_alma_phone_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, + ), + '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_postal_code' + $field_bases['field_alma_postal_code'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_alma_postal_code', + '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_preferred_branch' + $field_bases['field_alma_preferred_branch'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_alma_preferred_branch', + 'foreign keys' => array(), + 'indexes' => array( + 'value' => array( + 0 => 'value', + ), + ), + 'locked' => 0, + 'module' => 'list', + 'settings' => array( + 'allowed_values' => array(), + 'allowed_values_function' => 'alma_reservation_pickup_branches', + 'profile2_private' => 0, + ), + 'storage' => array( + 'active' => 1, + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), + 'translatable' => 0, + 'type' => 'list_text', + 'virtual_field' => array( + 'entity_types' => array( + 0 => 'profile2', + ), + ), + ); + + // Exported field_base: 'field_alma_reservation_pause' + $field_bases['field_alma_reservation_pause'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_alma_reservation_pause', + 'foreign keys' => array(), + 'indexes' => array(), + 'locked' => 0, + 'module' => 'date', + 'settings' => array( + 'granularity' => array( + 'day' => 'day', + 'hour' => 0, + 'minute' => 0, + 'month' => 'month', + 'second' => 0, + 'year' => 'year', + ), + 'profile2_private' => 0, + 'repeat' => 0, + 'timezone_db' => '', + 'todate' => 'required', + 'tz_handling' => 'none', + ), + 'storage' => array( + 'active' => 1, + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'virtual_field', + ), + 'translatable' => 0, + 'type' => 'datetime', + 'virtual_field' => array( + 'entity_types' => array( + 0 => 'profile2', + ), + ), + ); + + // Exported field_base: 'field_alma_street_name' + $field_bases['field_alma_street_name'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_alma_street_name', + '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', + ), + ), + ); + + return $field_bases; +} diff --git a/alma.features.field_instance.inc b/alma.features.field_instance.inc new file mode 100644 index 0000000..bfcffb6 --- /dev/null +++ b/alma.features.field_instance.inc @@ -0,0 +1,396 @@ + 'provider_alma', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'hidden', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 9, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_absent_id', + 'label' => 'Absent id', + 'required' => 0, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 9, + ), + ); + + // Exported field_instance: 'profile2-provider_alma-field_alma_city' + $field_instances['profile2-provider_alma-field_alma_city'] = array( + 'bundle' => 'provider_alma', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'inline', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 3, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_city', + 'label' => 'City', + 'required' => 0, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 3, + ), + ); + + // Exported field_instance: 'profile2-provider_alma-field_alma_full_name' + $field_instances['profile2-provider_alma-field_alma_full_name'] = array( + 'bundle' => 'provider_alma', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'inline', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 0, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_full_name', + 'label' => 'Full name', + 'required' => 0, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ); + + // Exported field_instance: 'profile2-provider_alma-field_alma_interest_period' + $field_instances['profile2-provider_alma-field_alma_interest_period'] = array( + 'bundle' => 'provider_alma', + 'default_value' => array( + 0 => array( + 'value' => 30, + ), + ), + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'inline', + 'module' => 'list', + 'settings' => array(), + 'type' => 'list_default', + 'weight' => 8, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_interest_period', + 'label' => 'Interest period', + 'required' => 0, + 'settings' => array( + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'options', + 'settings' => array(), + 'type' => 'options_select', + 'weight' => 5, + ), + ); + + // Exported field_instance: 'profile2-provider_alma-field_alma_mail' + $field_instances['profile2-provider_alma-field_alma_mail'] = array( + 'bundle' => 'provider_alma', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '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.', + 'display' => array( + 'default' => array( + 'label' => 'inline', + 'module' => 'email', + 'settings' => array(), + 'type' => 'email_plain', + 'weight' => 4, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_mail', + 'label' => 'E-mail', + 'required' => 0, + 'settings' => array( + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'email', + 'settings' => array( + 'size' => 60, + ), + 'type' => 'email_textfield', + 'weight' => 7, + ), + ); + + // Exported field_instance: 'profile2-provider_alma-field_alma_mobile_phone' + $field_instances['profile2-provider_alma-field_alma_mobile_phone'] = 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_mobile_phone', + 'label' => 'Phone', + 'required' => 0, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'text', + 'settings' => array( + 'size' => 12, + ), + 'type' => 'text_textfield', + 'weight' => 8, + ), + ); + + // Exported field_instance: 'profile2-provider_alma-field_alma_phone_id' + $field_instances['profile2-provider_alma-field_alma_phone_id'] = array( + 'bundle' => 'provider_alma', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'hidden', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 10, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_phone_id', + 'label' => 'Phone id', + 'required' => FALSE, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 10, + ), + ); + + // Exported field_instance: 'profile2-provider_alma-field_alma_postal_code' + $field_instances['profile2-provider_alma-field_alma_postal_code'] = array( + 'bundle' => 'provider_alma', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'inline', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 2, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_postal_code', + 'label' => 'Postal code', + 'required' => 0, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 2, + ), + ); + + // Exported field_instance: 'profile2-provider_alma-field_alma_preferred_branch' + $field_instances['profile2-provider_alma-field_alma_preferred_branch'] = array( + 'bundle' => 'provider_alma', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'inline', + 'module' => 'list', + 'settings' => array(), + 'type' => 'list_default', + 'weight' => 6, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_preferred_branch', + 'label' => 'Preferred branch', + 'required' => 0, + 'settings' => array( + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'options', + 'settings' => array(), + 'type' => 'options_select', + 'weight' => 4, + ), + ); + + // Exported field_instance: 'profile2-provider_alma-field_alma_reservation_pause' + $field_instances['profile2-provider_alma-field_alma_reservation_pause'] = array( + 'bundle' => 'provider_alma', + 'deleted' => 0, + 'description' => 'Set your reservations on pause.', + 'display' => array( + 'default' => array( + 'label' => 'inline', + 'module' => 'date', + 'settings' => array( + 'format_type' => 'long', + 'fromto' => 'both', + 'multiple_from' => '', + 'multiple_number' => '', + 'multiple_to' => '', + ), + 'type' => 'date_default', + 'weight' => 7, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_reservation_pause', + 'label' => 'Reservation pause', + 'required' => 0, + 'settings' => array( + 'default_value' => 'blank', + 'default_value2' => 'blank', + 'default_value_code' => '', + 'default_value_code2' => '', + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'date', + 'settings' => array( + 'display_all_day' => 0, + 'increment' => 15, + 'input_format' => 'd/m/Y', + 'input_format_custom' => '', + 'label_position' => 'above', + 'repeat_collapsed' => 0, + 'text_parts' => array(), + 'year_range' => '-3:+3', + ), + 'type' => 'date_popup', + 'weight' => 6, + ), + ); + + // Exported field_instance: 'profile2-provider_alma-field_alma_street_name' + $field_instances['profile2-provider_alma-field_alma_street_name'] = array( + 'bundle' => 'provider_alma', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'inline', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 1, + ), + ), + 'entity_type' => 'profile2', + 'field_name' => 'field_alma_street_name', + 'label' => 'Street name', + 'required' => 0, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'module' => 'virtual_field', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 1, + ), + ); + + // Translatables + // Included for use with string extractors like potx. + t('Absent id'); + t('City'); + t('E-mail'); + t('Full name'); + t('Interest period'); + t('Phone'); + t('Phone id'); + t('Postal code'); + t('Preferred branch'); + t('Reservation pause'); + 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.'); + + return $field_instances; +} diff --git a/alma.info b/alma.info index 1d7f4e9..bb82a58 100644 --- a/alma.info +++ b/alma.info @@ -11,20 +11,33 @@ dependencies[] = ding_reservation dependencies[] = email dependencies[] = features dependencies[] = list +dependencies[] = options dependencies[] = profile2 +dependencies[] = text dependencies[] = virtual_field features[features_api][] = api:1 -features[field][] = profile2-provider_alma-field_alma_absent_id -features[field][] = profile2-provider_alma-field_alma_city -features[field][] = profile2-provider_alma-field_alma_full_name -features[field][] = profile2-provider_alma-field_alma_interest_period -features[field][] = profile2-provider_alma-field_alma_mail -features[field][] = profile2-provider_alma-field_alma_mobile_phone -features[field][] = profile2-provider_alma-field_alma_phone_id -features[field][] = profile2-provider_alma-field_alma_postal_code -features[field][] = profile2-provider_alma-field_alma_preferred_branch -features[field][] = profile2-provider_alma-field_alma_reservation_pause -features[field][] = profile2-provider_alma-field_alma_street_name +features[field_base][] = field_alma_absent_id +features[field_base][] = field_alma_city +features[field_base][] = field_alma_full_name +features[field_base][] = field_alma_interest_period +features[field_base][] = field_alma_mail +features[field_base][] = field_alma_mobile_phone +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_street_name +features[field_instance][] = profile2-provider_alma-field_alma_absent_id +features[field_instance][] = profile2-provider_alma-field_alma_city +features[field_instance][] = profile2-provider_alma-field_alma_full_name +features[field_instance][] = profile2-provider_alma-field_alma_interest_period +features[field_instance][] = profile2-provider_alma-field_alma_mail +features[field_instance][] = profile2-provider_alma-field_alma_mobile_phone +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_street_name files[] = alma.module files[] = includes/alma.availability.inc files[] = includes/alma.debt.inc From c81c2e5813e346834b99c41147a4cb6100033174 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 30 Apr 2013 14:48:09 +0200 Subject: [PATCH 048/158] Fixed variable names and function comments --- includes/alma.availability.inc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index c628aed..f7ed128 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -116,10 +116,11 @@ function _alma_set_holdings_periodical($res) { /** * Make the html-table. * - * @params $h; holding information for a given material + * @param array $holding + * Holding information for a given material. * @return html-table */ -function _alma_set_table_html($h, $r_count) { +function _alma_set_table_html($holdings, $r_count) { // Set a classname for styling the table. $variables['attributes'] = array( 'class' => array( @@ -137,7 +138,7 @@ function _alma_set_table_html($h, $r_count) { ); // Set table rows. - $variables['rows'] = _alma_set_rows($h); + $variables['rows'] = _alma_set_rows($holdings); // Set last row with reservation count. $row = array(); @@ -154,10 +155,11 @@ function _alma_set_table_html($h, $r_count) { /** * Set rows in table for given holdings. * - * @param $h; holding information for a given material + * @param $holdings + * Holding information for a given material * @return array; */ -function _alma_set_rows($h) { +function _alma_set_rows($holdings) { $rows = array(); $org = alma_get_organisation(); @@ -166,7 +168,7 @@ function _alma_set_rows($h) { $not_for_loan_total = 0; $checked_out_total = 0; - foreach ($h as $key => $data) { + foreach ($holdings as $key => $data) { $row = array(); if (!empty($data['branch_id'])) { From 1135ee2e96266d74acb4b4fe9eb864b6797e7eff Mon Sep 17 00:00:00 2001 From: Arni Date: Tue, 30 Apr 2013 15:30:24 +0200 Subject: [PATCH 049/158] Fixed changing reservationpause --- lib/AlmaClient/AlmaClient.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index 353a78d..8059e83 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -876,11 +876,11 @@ public function change_absent_period($borr_card, $pin_code, $absent_id, $from_da 'borrCard' => $borr_card, 'pinCode' => $pin_code, 'absentId' => $absent_id, - 'absentFromDate' => $from_date, - 'absentToDate' => $to_date, + 'absentFrom' => date_format(date_create($from_date), 'Y-m-d'), + 'absentTo' => date_format(date_create($to_date), 'Y-m-d'), ); - $doc = $this->request('patron/absentPeriod/change', $params); + $doc = $this->request('patron/absent/change', $params); return TRUE; } From abd441f267cb64713199912462eff201e14d0f86 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 30 Apr 2013 17:32:01 +0200 Subject: [PATCH 050/158] Removed space inside t function --- alma.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alma.module b/alma.module index 25fc2f2..c02ba6a 100644 --- a/alma.module +++ b/alma.module @@ -324,7 +324,7 @@ function alma_profile2_presave($entity) { } function alma_update_provider($changes, $entity) { - $error_message = t('Error communicating with library system. '); + $error_message = t('Error communicating with library system.'); try { $creds = ding_user_get_creds($entity); From 3cbcc0ce5d6da3957ea07d09a5c55024869b188a Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 2 May 2013 12:31:03 +0200 Subject: [PATCH 051/158] Disable sticky header for the availability --- includes/alma.availability.inc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index f7ed128..ccd0cbc 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -146,6 +146,9 @@ function _alma_set_table_html($holdings, $r_count) { $row['data']['Copies'] = array('data' => $r_count, 'colspan' => 4); $variables['rows'][] = $row; + // Disable sticky headers. + $variables['sticky'] = FALSE; + // Theme the table. $html = theme('table', $variables); From ec477a4b2442a4e70f50ad037c001e387c33d7f3 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 3 May 2013 11:57:42 +0200 Subject: [PATCH 052/158] Added extra check of changed mail address --- alma.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alma.module b/alma.module index c02ba6a..12b2001 100644 --- a/alma.module +++ b/alma.module @@ -312,7 +312,7 @@ function alma_profile2_presave($entity) { // Get the mail. $value = $wrapper->field_alma_mail->value(); - if (!is_null($value)) { + if (!is_null($value) && $value != $wrapper_original->field_alma_mail->value()) { $changes['mail'] = $value; } From 634ac62ea09c9e49d185debf00cb7349686fd8c0 Mon Sep 17 00:00:00 2001 From: Rasmus Frey Date: Fri, 3 May 2013 14:28:03 +0200 Subject: [PATCH 053/158] Added Features_extra to make file, so it's possible to add menu_blocks etc. to features --- alma.make | 3 +++ 1 file changed, 3 insertions(+) diff --git a/alma.make b/alma.make index e5e6919..28aee28 100644 --- a/alma.make +++ b/alma.make @@ -12,6 +12,9 @@ projects[email][version] = "1.2" projects[features][subdir] = "contrib" projects[features][version] = "2.0-beta2" +projects[features_extra][subdir] = "contrib" +projects[features_extra][version] = "1.0-beta1" + projects[profile2][subdir] = "contrib" projects[profile2][version] = "1.3" From 9c0b66344b5fbd1fa9d1a18f282874229f91ce7c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 6 May 2013 11:26:48 +0200 Subject: [PATCH 054/158] Changed makefile to point to ding2 on github --- alma.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/alma.make b/alma.make index e5e6919..9f805bd 100644 --- a/alma.make +++ b/alma.make @@ -22,10 +22,10 @@ projects[virtual_field][version] = "1.1" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" -projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][branch] = "development" +projects[ding_provider][download][url] = "git@github.com:ding2/ding_provider.git" +projects[ding_provider][download][branch] = "master" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" -projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" -projects[ding_reservation][download][branch] = "development" \ No newline at end of file +projects[ding_reservation][download][url] = "git@github.com:ding2/ding_reservation.git" +projects[ding_reservation][download][branch] = "master" From 993f81daf826b5b8249ab6ef85f02419c174c612 Mon Sep 17 00:00:00 2001 From: Rune Schjellerup Philosof Date: Wed, 15 May 2013 14:22:43 +0200 Subject: [PATCH 055/158] Avoid a notice when no absentPeriods have been set. --- alma.module | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/alma.module b/alma.module index 12b2001..0a54dbe 100644 --- a/alma.module +++ b/alma.module @@ -544,7 +544,8 @@ function alma_profile2_load($entities) { 'value' => '', 'value2' => '', )); - if (isset($patron->absentPeriods[0]['from_date']) && isset($patron->absentPeriods[0]['to_date'])) { + if (isset($patron->absentPeriods[0]) && + isset($patron->absentPeriods[0]['from_date']) && isset($patron->absentPeriods[0]['to_date'])) { $wrapper->field_alma_reservation_pause->set(array( 'value' => $patron->absentPeriods[0]['from_date'] . ' 00:00:00', 'value2' => $patron->absentPeriods[0]['to_date'] . ' 00:00:00', From 2fa2962721290c99a08c9d0fd02af6c6df967703 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 15 May 2013 19:08:04 +0200 Subject: [PATCH 056/158] Fixed some function comments and typos --- alma.module | 14 +++++++++++++- includes/alma.user.inc | 12 ++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/alma.module b/alma.module index 12b2001..0860eba 100644 --- a/alma.module +++ b/alma.module @@ -316,13 +316,25 @@ function alma_profile2_presave($entity) { $changes['mail'] = $value; } - // Update provider + // Update provider. if (!empty($changes)) { alma_update_provider($changes, $entity); } } } +/** + * Update user information at the provider. + * + * @global object $user + * The user object for the currently logged in user. + * + * @param array $changes + * Array with the fields/information that have changed and should be updated at + * the provider. + * @param object $entity + * An profile2 entity, mainly used to the user credentials. + */ function alma_update_provider($changes, $entity) { $error_message = t('Error communicating with library system.'); diff --git a/includes/alma.user.inc b/includes/alma.user.inc index 85396f6..4fa54ae 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -91,12 +91,12 @@ function alma_user_clear_cache($creds = NULL) { /** * Update pin code at alma. * - * @TODO: Rename this function to change hook_alma_change_pincode and in - * ding_user line 240. - * - * @param type $account - * @param type $changes - * @return type + * @param object $account + * User account object or the user provider profile2. + * @param string $new_pincode + * The users new pincode. + * @return array + * Updated credential array. */ function alma_user_update_pincode($account, $new_pincode) { $creds = ding_user_get_creds($account); From 8670c5ac2eb3ad6227df8a6b05e05eae376431eb Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 16 May 2013 11:36:00 +0200 Subject: [PATCH 057/158] Update drupal users mail after mail have changed in the profile --- alma.module | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/alma.module b/alma.module index a92614f..9787381 100644 --- a/alma.module +++ b/alma.module @@ -319,6 +319,20 @@ function alma_profile2_presave($entity) { // Update provider. if (!empty($changes)) { alma_update_provider($changes, $entity); + + // Update local drupal user (mail and display name). + if (isset($changes['mail'])) { + $creds = ding_user_get_creds($entity); + $auth_name = ding_user_default_authname($creds['name']); + _ding_user_create_account($auth_name, array( + 'user' => array( + 'mail' => $changes['mail'], + 'data' => array( + 'display_name' => $wrapper->field_alma_full_name->value(), + ), + ), + )); + } } } } From a7d752a7ef04a30a4ab7c6ee2e9f5c60d6b16b79 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 16 May 2013 14:56:24 +0200 Subject: [PATCH 058/158] Fixed missing absent_id in update of reservation pause --- alma.module | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/alma.module b/alma.module index 9787381..fe6e984 100644 --- a/alma.module +++ b/alma.module @@ -267,22 +267,22 @@ function alma_profile2_presave($entity) { // Reservation pause $value = $wrapper->field_alma_reservation_pause->value(); $start = is_null($value['value']) ? '' : $value['value']; - $start = str_replace('T00:00:00', '', $start); + $start = str_replace(' 00:00:00', '', $start); $stop = is_null($value['value2']) ? '' : $value['value2']; - $stop = str_replace('T00:00:00', '', $stop); + $stop = str_replace(' 00:00:00', '', $stop); $value = $wrapper_original->field_alma_reservation_pause->value(); $org_start = is_null($value['value']) ? '' : $value['value']; - $org_start = str_replace('T00:00:00', '', $org_start); + $org_start = str_replace(' 00:00:00', '', $org_start); $org_stop = is_null($value['value2']) ? '' : $value['value2']; - $org_stop = str_replace('T00:00:00', '', $org_stop); + $org_stop = str_replace(' 00:00:00', '', $org_stop); if ($start != $org_start || $stop != $org_stop) { $changes['reservation_pause_start'] = $start; $changes['reservation_pause_stop'] = $stop; // Set absent id. - $wrapper->field_alma_absent_id->value(); + $value = $wrapper->field_alma_absent_id->value(); $changes['absent_id'] = is_null($value) ? '' : $value; } From 5caa7cff1ec2915961c4721a73f28e3d9a24a6be Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 16 May 2013 15:01:58 +0200 Subject: [PATCH 059/158] Added option to have a 12 months interest period --- alma.features.field_base.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/alma.features.field_base.inc b/alma.features.field_base.inc index 59ca658..201aca3 100644 --- a/alma.features.field_base.inc +++ b/alma.features.field_base.inc @@ -154,6 +154,7 @@ function alma_field_default_field_bases() { 60 => '2 months', 90 => '3 months', 180 => '6 months', + 360 => '12 months' ), 'allowed_values_function' => '', 'profile2_private' => 0, From 103a9cf4b758aae66e6f66739b9057cbf4506f40 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 16 May 2013 15:08:38 +0200 Subject: [PATCH 060/158] Added documentation to some of the functions in alma reservation --- includes/alma.reservation.inc | 43 ++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 7f7b076..3f8cb0f 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -1,12 +1,13 @@ Date: Thu, 16 May 2013 15:51:27 +0200 Subject: [PATCH 061/158] Fixed reservation expire times during creation and update --- includes/alma.reservation.inc | 32 ++++++++++++++++------------- lib/AlmaClient/AlmaClient.class.php | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 3f8cb0f..30ed0ca 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -164,14 +164,14 @@ function alma_reservation_list($account) { * * @param type $account * @param type $id - * @param type $branch + * @param type $options * @param type $expiry * @return type * @throws DingProviderReservationExists * @throws DingProviderReservationNotAllowed * @throws DingProviderReservationNotAvailable */ -function alma_reservation_create($account, $id, $branch, $expiry = NULL) { +function alma_reservation_create($account, $id, $options = array(), $expiry = NULL) { $creds = ding_user_get_creds($account); // Check if the users has this reservation and throw exception. @@ -188,16 +188,18 @@ function alma_reservation_create($account, $id, $branch, $expiry = NULL) { // Use a metadata wrapper to access the data. $interest_period = $wrapper->field_alma_interest_period->value(); if ($interest_period) { - $expiry = REQUEST_TIME + ($interest_period['key'] * 24 * 60 * 60); + // Change it to secounds from days. + $expiry = $interest_period * 86400; } } if (!isset($expiry)) { - $expiry = REQUEST_TIME + DING_RESERVATION_DEFAULT_INTEREST_PERIOD; + $expiry = DING_RESERVATION_DEFAULT_INTEREST_PERIOD; } - // preferred branch - if (empty($branch)) { - $branch = $wrapper->field_alma_preferred_branch->value(); + // Preferred branch + $branch = $wrapper->field_alma_preferred_branch->value(); + if (isset($options['alma_preferred_branch'])) { + $branch = $options['alma_preferred_branch']; } } @@ -205,10 +207,11 @@ function alma_reservation_create($account, $id, $branch, $expiry = NULL) { $params = array( 'id' => $id, 'valid_from' => date('Y-m-d'), - 'valid_to' => alma_reservation_format_date($expiry), + 'valid_to' => alma_reservation_format_date(time() + $expiry), 'pickup_branch' => $branch, ); + // Clear the local alma cache. alma_reservation_clear_cache(); // Try to make the reservation. @@ -347,12 +350,13 @@ function alma_reservation_exists($account, $item_id) { } /** - * @TODO: add description. + * Helper function calculate the date in the feature base on interest period. * - * @param type $datetime - * @return type + * @param int $expiry + * The number of secounds into the feature we need at date. + * @return string + * The date in the feature in the format 'Y-m-d'. */ -function alma_reservation_format_date($datetime) { - $timestamp = (!is_int($datetime)) ? strtotime($datetime) : $datetime; - return date('Y-m-d', $timestamp); +function alma_reservation_format_date($expiry) { + return date('Y-m-d', $expiry); } diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index 8059e83..1f9744f 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -428,7 +428,7 @@ public function add_reservation($borr_card, $pin_code, $reservation) { 'borrCard' => $borr_card, 'pinCode' => $pin_code, 'reservable' => $reservation['id'], - 'reservationPickUpBranch' => $reservation['pickup_branch']['alma_preferred_branch'], + 'reservationPickUpBranch' => $reservation['pickup_branch'], 'reservationValidFrom' => $reservation['valid_from'], 'reservationValidTo' => $reservation['valid_to'], ); From 45a2a478240646fbe06a7cac029af673ee8236bf Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 16 May 2013 16:40:24 +0200 Subject: [PATCH 062/158] Added support for configurable default interest period --- alma.module | 6 ++++++ includes/alma.reservation.inc | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/alma.module b/alma.module index fe6e984..e4a8132 100644 --- a/alma.module +++ b/alma.module @@ -117,6 +117,12 @@ function alma_settings_form() { '#description' => t('The different libraries uses different pin code lenght (defaults to four).'), ); + // Add the option to select default interest period, which default as default + // to 180 days. + $periods = alma_get_interest_periods(); + $default = variable_get('alma_default_interest_period', 180); + $form['alma'] += ding_reservation_interest_period_selector('', 'alma_default_interest_period', $default, $periods); + $form['alma']['alma_enable_reservation_deletion'] = array( '#type' => 'checkbox', '#title' => t('Enable reservation deletion'), diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 30ed0ca..5f8a3be 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -193,7 +193,9 @@ function alma_reservation_create($account, $id, $options = array(), $expiry = NU } } if (!isset($expiry)) { - $expiry = DING_RESERVATION_DEFAULT_INTEREST_PERIOD; + // The user don't have a default interest period, so use the system wide + // one for alma (which default is 180 days). + $expiry = variable_get('alma_default_interest_period', 180) * 86400; } // Preferred branch From d8fd9f215a3ed8e09ef9e8b9376f79155d1bb6b0 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 16 May 2013 16:41:51 +0200 Subject: [PATCH 063/158] Removed old pincode length option from alma as global option have been created --- alma.module | 7 ------- 1 file changed, 7 deletions(-) diff --git a/alma.module b/alma.module index e4a8132..226b4cb 100644 --- a/alma.module +++ b/alma.module @@ -110,13 +110,6 @@ function alma_settings_form() { '#default_value' => variable_get('alma_base_url', ''), ); - $form['alma']['alma_pincode_length'] = array( - '#type' => 'textfield', - '#title' => t('Length of the pin code'), - '#default_value' => variable_get('alma_pincode_length', '4'), - '#description' => t('The different libraries uses different pin code lenght (defaults to four).'), - ); - // Add the option to select default interest period, which default as default // to 180 days. $periods = alma_get_interest_periods(); From b9b5473dd78e98acc3f8f0214236460d58cbbc24 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 16 May 2013 17:39:10 +0200 Subject: [PATCH 064/158] Added support for session based caching of parton information --- alma.module | 49 +++++++++++++++++++++++++++--------------- includes/alma.user.inc | 4 ++-- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/alma.module b/alma.module index 226b4cb..189391a 100644 --- a/alma.module +++ b/alma.module @@ -332,6 +332,9 @@ function alma_profile2_presave($entity) { ), )); } + + // Clear local session cache. + alma_user_clear_cache($creds, TRUE); } } } @@ -505,27 +508,39 @@ function alma_get_patron($creds = NULL, $reset = FALSE, $as_array = FALSE) { $creds = ding_user_get_creds($user); } - static $patron; + // Try static cache. + $patron = &drupal_static(__FUNCTION__); if (!$patron || $reset) { - $info = alma_client_invoke('get_patron_info', $creds['name'], $creds['pass'], TRUE); - $organisation = alma_get_organisation(); - $patron = array( - 'name' => $info['user_name'], - 'email' => isset($info['mails'][0]) ? $info['mails'][0]['mail'] : '', - 'address' => isset($info['addresses'][0]) ? $info['addresses'][0]['street'] : '', - 'postal' => isset($info['addresses'][0]) ? $info['addresses'][0]['postal_code'] : '', - 'city' => isset($info['addresses'][0]) ? $info['addresses'][0]['city'] : '', - 'mobiles' => isset($info['phones']) ? $info['phones'] : '', - 'branch' => $info['preferences']['patron_branch'], - 'branchName' => $organisation['branch'][$info['preferences']['patron_branch']], - 'absentPeriods' => isset($info['absent_periods']) ? $info['absent_periods'] : '', - ); + // Try session cache. + if (!$reset && isset($_SESSION['alma_patron_info'])) { + $patron = $_SESSION['alma_patron_info']; + } + else { + $info = alma_client_invoke('get_patron_info', $creds['name'], $creds['pass'], TRUE); + $organisation = alma_get_organisation(); + $patron = array( + 'name' => $info['user_name'], + 'email' => isset($info['mails'][0]) ? $info['mails'][0]['mail'] : '', + 'address' => isset($info['addresses'][0]) ? $info['addresses'][0]['street'] : '', + 'postal' => isset($info['addresses'][0]) ? $info['addresses'][0]['postal_code'] : '', + 'city' => isset($info['addresses'][0]) ? $info['addresses'][0]['city'] : '', + 'mobiles' => isset($info['phones']) ? $info['phones'] : '', + 'branch' => $info['preferences']['patron_branch'], + 'branchName' => $organisation['branch'][$info['preferences']['patron_branch']], + 'absentPeriods' => isset($info['absent_periods']) ? $info['absent_periods'] : '', + ); + + // Store information in session cache. + $_SESSION['alma_patron_info'] = $patron; + } } - if ($as_array) { - return $patron; + + // Cast petron to object. + if (!$as_array) { + $patron = (object)$patron; } - return (object)$patron; + return $patron; } /** diff --git a/includes/alma.user.inc b/includes/alma.user.inc index 4fa54ae..ddb2783 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -80,12 +80,12 @@ function alma_user_profile_form_validate($form, $form_state) { } /** - * Clear user cache based on creds. + * Clear user session cache based on creds. * * @param array $creds */ function alma_user_clear_cache($creds = NULL) { - alma_get_patron($creds); + alma_get_patron($creds, TRUE); } /** From 0bc11186a56352d01104c71ae55fedf4081ed33e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 30 May 2013 16:49:52 +0200 Subject: [PATCH 065/158] Added provider session cacheing of user loans --- includes/alma.loan.inc | 52 +++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index 0fd9179..da82a52 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -11,27 +11,39 @@ * as DingProviderLoan objects. * */ -function alma_loan_list($account) { +function alma_loan_list($account, $reset = FALSE) { + // Get creds is outside cache function as it may throw exception if the user + // is not longer logged in. $creds = ding_user_get_creds($account); - $results = array(); - try { - // Get all loans form alma for the user account given. - $loans = alma_client_invoke('get_loans', $creds['name'], $creds['pass']); - } - catch (Exception $e) { - throw new DingProviderLoanUserError($e->getMessage()); - } + $cache_key = 'alma_loans'; + $results = &drupal_static(__FUNCTION__, FALSE); + if (!$results || $reset) { + $results = ding_provider_session_cache_get($cache_key); + if (!$results) { + try { + // Get all loans form alma for the user account given. + $loans = alma_client_invoke('get_loans', $creds['name'], $creds['pass']); + } + catch (Exception $e) { + throw new DingProviderLoanUserError($e->getMessage()); + } + + $results = array(); + foreach ($loans as $loan) { + $results[$loan['id']] = new DingProviderLoan($loan['id'], array( + 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $loan['record_id'], + 'loan_date' => $loan['loan_date'], + 'expiry' => $loan['due_date'], + 'renewable' => $loan['is_renewable'], + 'materials_number' => $loan['id'], + 'notes' => isset($loan['notes']) ? $loan['notes'] : DingEntityBase::NULL, + )); + } - foreach ($loans as $loan) { - $results[$loan['id']] = new DingProviderLoan($loan['id'], array( - 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $loan['record_id'], - 'loan_date' => $loan['loan_date'], - 'expiry' => $loan['due_date'], - 'renewable' => $loan['is_renewable'], - 'materials_number' => $loan['id'], - 'notes' => isset($loan['notes']) ? $loan['notes'] : DingEntityBase::NULL, - )); + // Store result into the session cache. + ding_provider_session_cache_set($cache_key, $results, 300); + } } return $results; @@ -58,6 +70,10 @@ function alma_loan_renew($account, $ids) { $result[$id] = DingProviderLoan::STATUS_NOT_RENEWED; } } + + // Clear loans session cache. + ding_provider_session_cache_clear('alma_loans'); + return $result; } From 5d110f60255e433cf8da042d73eaa2182277645d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 30 May 2013 17:23:22 +0200 Subject: [PATCH 066/158] Added session cache to alma debts --- includes/alma.debt.inc | 45 ++++++++++++++++++++++++------------------ includes/alma.loan.inc | 2 +- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/includes/alma.debt.inc b/includes/alma.debt.inc index d4e874f..78a4309 100644 --- a/includes/alma.debt.inc +++ b/includes/alma.debt.inc @@ -12,17 +12,31 @@ * @return array * DingProviderDebt objects in array, keyed by debt ID. */ -function alma_debt_list($account) { - $data = alma_debt_get_debts($account); - $debts = array(); +function alma_debt_list($account, $reset = FALSE) { + $creds = ding_user_get_creds($account); + + // Use session cache to speed up communication with Alma. + $cache_key = 'alma_debts'; + $results = &drupal_static(__FUNCTION__, FALSE); + if (!$results || $reset) { + $results = ding_provider_session_cache_get($cache_key); + if (!$results || $reset) { + // Get debts from Alma. + $debts = alma_client_invoke('get_debts', $creds['name'], $creds['pass']); + + // Create DingProviderDebt instances from Alma's list. + $result = array(); + foreach ($debts['debts'] as $debt) { + $debt_object = new DingProviderDebt($debt['id'], $debt); + $result[$debt['id']] = $debt_object; + } - // Create DingProviderDebt instances from Alma's list. - foreach ($data['debts'] as $debt) { - $debt_object = new DingProviderDebt($debt['id'], $debt); - $debts[$debt['id']] = $debt_object; + // Store result into the session cache. + ding_provider_session_cache_set($cache_key, $results); + } } - return $debts; + return $result; } /** @@ -36,16 +50,9 @@ function alma_debt_list($account) { * Order ID of the payment transaction, to be recorded in the backend system. */ function alma_debt_payment_received($amount, $debt_ids = array(), $order_id = NULL) { - // TODO: We should probably check that $amount adds up to the debts - // we're going to mark paid, since Alma doesn't. - return alma_client_invoke('add_payment', implode(',', $debt_ids), $order_id); -} + // Clear loans session cache. + ding_provider_session_cache_clear('alma_debts'); -/** - * Get list of debts from Alma. - */ -function alma_debt_get_debts($account, $reset = FALSE) { - $creds = ding_user_get_creds($account); - - return alma_client_invoke('get_debts', $creds['name'], $creds['pass']); + // Return result from Alma. + return alma_client_invoke('add_payment', implode(',', $debt_ids), $order_id); } diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index da82a52..4416181 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -20,7 +20,7 @@ function alma_loan_list($account, $reset = FALSE) { $results = &drupal_static(__FUNCTION__, FALSE); if (!$results || $reset) { $results = ding_provider_session_cache_get($cache_key); - if (!$results) { + if (!$results || $reset) { try { // Get all loans form alma for the user account given. $loans = alma_client_invoke('get_loans', $creds['name'], $creds['pass']); From 93b7e62847397e14a4ffa916df725a06db5a5673 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 31 May 2013 09:54:11 +0200 Subject: [PATCH 067/158] Change reservation to use provider session cache --- includes/alma.reservation.inc | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 5f8a3be..9c61112 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -310,28 +310,35 @@ function alma_reservation_branch_name($branch_id) { } /** - * @TODO: add description. + * Get all reservation from Alma and store them in the cache. * - * @param type $account - * @param type $reset - * @return type + * @param object $account + * User account object. + * @param bool $reset + * If TRUE the cache will be by-passed. + * @return mixed + * Alma reservations. */ function alma_reservation_get_reservations($account, $reset = FALSE) { $creds = ding_user_get_creds($account); - // Try to look in the session for reservation information. - if (!isset($_SESSION['alma_reservations']) || !is_array($_SESSION['alma_reservations']) || $reset) { - $_SESSION['alma_reservations'] = alma_client_invoke('get_reservations', $creds['name'], $creds['pass']); + $cache_key = 'alma_reservations'; + $reservations = &drupal_static(__FUNCTION__, FALSE); + if (!$reservations || $reset) { + $reservations = ding_provider_session_cache_get($cache_key); + if (!$reservations || $reset) { + $reservations = alma_client_invoke('get_reservations', $creds['name'], $creds['pass']); + } } - return $_SESSION['alma_reservations']; + return $reservations; } /** - * @TODO: add description. + * Clear reservations stored in the current session cache. */ function alma_reservation_clear_cache() { - unset($_SESSION['alma_reservations']); + ding_provider_session_cache_clear('alma_reservations'); } /** From a6c005a183c679d3f730ba6cfeb41d4c4526f8e1 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Jun 2013 13:00:43 +0200 Subject: [PATCH 068/158] Moved profile create into features from hook_enable() --- alma.features.field_base.inc | 2 +- alma.features.inc | 21 +++++++++++++++++++++ alma.info | 4 +++- alma.install | 17 ----------------- alma.module | 8 +++++--- 5 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 alma.features.inc diff --git a/alma.features.field_base.inc b/alma.features.field_base.inc index 201aca3..fd8dc6f 100644 --- a/alma.features.field_base.inc +++ b/alma.features.field_base.inc @@ -154,7 +154,7 @@ function alma_field_default_field_bases() { 60 => '2 months', 90 => '3 months', 180 => '6 months', - 360 => '12 months' + 360 => '12 months', ), 'allowed_values_function' => '', 'profile2_private' => 0, diff --git a/alma.features.inc b/alma.features.inc new file mode 100644 index 0000000..70cdb4b --- /dev/null +++ b/alma.features.inc @@ -0,0 +1,21 @@ + 'provider_alma', - 'label' => t('Profile for Alma'), - 'userCategory' => TRUE, - 'userView' => TRUE, - ) - ); - $profile_type->save(); -} - /** * Update system table set alma weight=10 to ensure form_alter hooks are called * AFTER ding_user and ding_provider diff --git a/alma.module b/alma.module index 189391a..c943fc4 100644 --- a/alma.module +++ b/alma.module @@ -1,8 +1,7 @@ field_alma_mail->set($patron->email); } } -} \ No newline at end of file +} + +// Include the feature code. +include_once 'alma.features.inc'; From e1568f9e3274c706702680c34fa3a33226193f10 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Jun 2013 13:05:30 +0200 Subject: [PATCH 069/158] Removed features extra module as it is not used --- alma.make | 3 --- 1 file changed, 3 deletions(-) diff --git a/alma.make b/alma.make index 546305d..9f805bd 100644 --- a/alma.make +++ b/alma.make @@ -12,9 +12,6 @@ projects[email][version] = "1.2" projects[features][subdir] = "contrib" projects[features][version] = "2.0-beta2" -projects[features_extra][subdir] = "contrib" -projects[features_extra][version] = "1.0-beta1" - projects[profile2][subdir] = "contrib" projects[profile2][version] = "1.3" From 0bd6d0cff8921842f28d2e7697adac22627323b6 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Jun 2013 13:09:25 +0200 Subject: [PATCH 070/158] Added better description to the code and removed commented out code --- alma.module | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/alma.module b/alma.module index c943fc4..cce2a0b 100644 --- a/alma.module +++ b/alma.module @@ -109,8 +109,9 @@ function alma_settings_form() { '#default_value' => variable_get('alma_base_url', ''), ); - // Add the option to select default interest period, which default as default - // to 180 days. + // Add the option to select a default interest period for reservations, if not + // selected it will default to 180 days (6 months). The users can override + // this during reservation. $periods = alma_get_interest_periods(); $default = variable_get('alma_default_interest_period', 180); $form['alma'] += ding_reservation_interest_period_selector('', 'alma_default_interest_period', $default, $periods); @@ -208,7 +209,7 @@ function alma_get_organisation($reset = FALSE) { 'location' => alma_client_invoke('get_locations'), 'sublocation' => alma_client_invoke('get_sublocations'), 'collection' => alma_client_invoke('get_collections'), - 'reservation' => alma_reservation_pickup_branches(), //alma_client_invoke('get_reservation_branches'), + 'reservation' => alma_reservation_pickup_branches(), ); // Cache output for 24 hours if we got all the data correctly. From 37923256738f7188f8dcd707bb31508d1eca8d15 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Jun 2013 13:12:51 +0200 Subject: [PATCH 071/158] Fixed function description to match module name --- alma.module | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/alma.module b/alma.module index cce2a0b..4aa3e0e 100644 --- a/alma.module +++ b/alma.module @@ -110,7 +110,7 @@ function alma_settings_form() { ); // Add the option to select a default interest period for reservations, if not - // selected it will default to 180 days (6 months). The users can override + // selected it will default to 180 days (6 months). The users can override // this during reservation. $periods = alma_get_interest_periods(); $default = variable_get('alma_default_interest_period', 180); @@ -225,10 +225,16 @@ function alma_get_organisation($reset = FALSE) { } /** - * Callback function to get OpenRuth user information + * Callback function to get user information from Alma. + * + * @param array $creds + * The credentials for the user for which the information shold be retrived + * from Alma. + * @return array + * Available information about the patron from Alma. */ function _alma_user_info($creds = NULL) { - // Get patron informations from ALMA. + // Get patron informations from Alma. $status = alma_get_patron($creds); // Build basic information array, with patron information. From 6868b6bc645e00cfa8090761df25f27e3e77a680 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Jun 2013 13:49:11 +0200 Subject: [PATCH 072/158] Fixed reservation date in presave to use php date functions and removed alma_user_clear_cache() as it was not needed --- alma.module | 32 +++++++++++++++++++++----------- includes/alma.user.inc | 9 --------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/alma.module b/alma.module index 4aa3e0e..9674dc7 100644 --- a/alma.module +++ b/alma.module @@ -269,19 +269,29 @@ function alma_profile2_presave($entity) { $wrapper_original = entity_metadata_wrapper('profile2', $entity->original); $wrapper = entity_metadata_wrapper('profile2', $entity); - // Reservation pause + // Reservation pause (Start) $value = $wrapper->field_alma_reservation_pause->value(); - $start = is_null($value['value']) ? '' : $value['value']; - $start = str_replace(' 00:00:00', '', $start); - $stop = is_null($value['value2']) ? '' : $value['value2']; - $stop = str_replace(' 00:00:00', '', $stop); + $start = ''; + if (!is_null($value['value'])) { + $start = date('Y-m-d', strtotime($value['value'])); + } + $stop = ''; + if (!is_null($value['value2'])) { + $stop = date('Y-m-d', strtotime($value['value2'])); + } + // Reservation pause (Stop) $value = $wrapper_original->field_alma_reservation_pause->value(); - $org_start = is_null($value['value']) ? '' : $value['value']; - $org_start = str_replace(' 00:00:00', '', $org_start); - $org_stop = is_null($value['value2']) ? '' : $value['value2']; - $org_stop = str_replace(' 00:00:00', '', $org_stop); + $org_start = ''; + if (!is_null($value['value'])) { + $org_start = date('Y-m-d', strtotime($value['value'])); + } + $org_stop = ''; + if (!is_null($value['value2'])) { + $org_stop = date('Y-m-d', strtotime($value['value2'])); + } + // Check if the reservation pause have changed. if ($start != $org_start || $stop != $org_stop) { $changes['reservation_pause_start'] = $start; $changes['reservation_pause_stop'] = $stop; @@ -339,8 +349,8 @@ function alma_profile2_presave($entity) { )); } - // Clear local session cache. - alma_user_clear_cache($creds, TRUE); + // Clear local session cache by reloading patron from Alma. + alma_get_patron(NULL, TRUE); } } } diff --git a/includes/alma.user.inc b/includes/alma.user.inc index ddb2783..4700a34 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -79,15 +79,6 @@ function alma_user_profile_form_validate($form, $form_state) { } -/** - * Clear user session cache based on creds. - * - * @param array $creds - */ -function alma_user_clear_cache($creds = NULL) { - alma_get_patron($creds, TRUE); -} - /** * Update pin code at alma. * From c806dc46e6f238658651a6151c651f92ef17bf26 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Jun 2013 13:51:41 +0200 Subject: [PATCH 073/158] Added watchdog statement in alma_update_provider --- alma.module | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/alma.module b/alma.module index 9674dc7..31575a8 100644 --- a/alma.module +++ b/alma.module @@ -373,9 +373,9 @@ function alma_update_provider($changes, $entity) { try { $creds = ding_user_get_creds($entity); } - catch (Exception $e) { - // Re-throw ?? - throw $e; + catch (Exception $exception) { + watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); + throw $exception; } // Mobile phone; add, change, delete. @@ -385,8 +385,8 @@ function alma_update_provider($changes, $entity) { try { $res = alma_client_invoke('remove_phone_number', $creds['name'], $creds['pass'], $changes['phone_id']); } - catch (Exception $e) { - watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); + catch (Exception $exception) { + watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); } if (empty($res)) { @@ -399,8 +399,8 @@ function alma_update_provider($changes, $entity) { try { $res = alma_client_invoke('change_phone_number', $creds['name'], $creds['pass'], $changes['phone_id'], $changes['mobile']); } - catch (Exception $e) { - watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); + catch (Exception $exception) { + watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); } if (!$res) { @@ -414,8 +414,8 @@ function alma_update_provider($changes, $entity) { try { $res = alma_client_invoke('add_phone_number', $creds['name'], $creds['pass'], $changes['mobile']); } - catch (Exception $e) { - watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); + catch (Exception $exception) { + watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); } if (!$res) { $error_message .= t('mobile not added'); @@ -431,8 +431,8 @@ function alma_update_provider($changes, $entity) { try { $res = alma_client_invoke('change_absent_period', $creds['name'], $creds['pass'], $changes['absent_id'], $changes['reservation_pause_start'], $changes['reservation_pause_stop']); } - catch (Exception $e) { - watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); + catch (Exception $exception) { + watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); } if (empty($res)) { $error_message .= t('reservation pause not updated'); @@ -444,8 +444,8 @@ function alma_update_provider($changes, $entity) { try { $res = alma_client_invoke('add_absent_period', $creds['name'], $creds['pass'], $changes['reservation_pause_start'], $changes['reservation_pause_stop']); } - catch (Exception $e) { - watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); + catch (Exception $exception) { + watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); } if (empty($res)) { $error_message .= t('reservation pause not added'); @@ -457,8 +457,8 @@ function alma_update_provider($changes, $entity) { try { $res = alma_client_invoke('remove_absent_period', $creds['name'], $creds['pass'], $changes['absent_id']); } - catch (Exception $e) { - watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); + catch (Exception $exception) { + watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); } } @@ -467,8 +467,8 @@ function alma_update_provider($changes, $entity) { try { $res = alma_client_invoke('change_patron_preferences', $creds['name'], $creds['pass'], $changes['preferred_branch']); } - catch (Exception $e) { - watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); + catch (Exception $exception) { + watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); } if (empty($res)) { $error_message .= t('pickup branch not saved'); @@ -491,8 +491,8 @@ function alma_update_provider($changes, $entity) { $res = alma_client_invoke('change_email_address', $creds['name'], $creds['pass'], $user->mail, $changes['mail']); } } - catch (Exception $e) { - watchdog('Alma provider', $e->getMessage(), array(), WATCHDOG_ERROR); + catch (Exception $exception) { + watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); } if (empty($res)) { From d1c6c53855e49a7d640e893d80a0a812564b70a7 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Jun 2013 13:55:30 +0200 Subject: [PATCH 074/158] Updated reservation pause in hook_profile2_load to use date function --- alma.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alma.module b/alma.module index 31575a8..1c7eae7 100644 --- a/alma.module +++ b/alma.module @@ -603,8 +603,8 @@ function alma_profile2_load($entities) { if (isset($patron->absentPeriods[0]) && isset($patron->absentPeriods[0]['from_date']) && isset($patron->absentPeriods[0]['to_date'])) { $wrapper->field_alma_reservation_pause->set(array( - 'value' => $patron->absentPeriods[0]['from_date'] . ' 00:00:00', - 'value2' => $patron->absentPeriods[0]['to_date'] . ' 00:00:00', + 'value' => date('Y-m-d m:i:s', strtotime($patron->absentPeriods[0]['from_date'])), + 'value2' => date('Y-m-d m:i:s', strtotime($patron->absentPeriods[0]['to_date'])), )); $wrapper->field_alma_absent_id->set($patron->absentPeriods[0]['id']); } From 376c9c0ae76302b2f1cdc18d7559e1c52a6f5adb Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Jun 2013 14:01:30 +0200 Subject: [PATCH 075/158] Added better function description in availability callback --- includes/alma.availability.inc | 6 +++++- includes/alma.loan.inc | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index ccd0cbc..26bf5c5 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -47,7 +47,11 @@ function alma_availability_holdings($provider_ids) { } /** - * @TODO: Add function description. + * Get holdings base information from alma and base on if it's a periodical or + * not. + * + * @todo: Rewrite this to have the provider create the holdings tables and not + * return HTML from inside the provides them self. * * @param type $res * Returned array from alma_client class diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index 0fd9179..7dc4e99 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -89,4 +89,4 @@ function alma_loan_populate_pseudo_entity($ting_entity) { } return $ting_entity; -} \ No newline at end of file +} From 87bf1e47d1bf6f972174fc6471db3458afe081d3 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 4 Jun 2013 10:06:15 +0200 Subject: [PATCH 076/158] Added the new hook_default_interest_period() --- includes/alma.reservation.inc | 69 +++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 5f8a3be..6f649f3 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -34,7 +34,7 @@ function alma_reservation_options($type, $account, $reservables) { $form = array(); $form += ding_reservation_default_options_branch($type, 'alma_preferred_branch', $preferred_branch, $branches); - $form += ding_reservation_interest_period_selector($type, 'alma_interest_period', $interest_period, $periods); + $form += ding_reservation_interest_period_selector($type, 'interest_period', $interest_period, $periods); return $form; } @@ -64,12 +64,12 @@ function alma_reservation_options_validate($type, $account, $reservables, $value if (!empty($$preferred_branch) && !empty($interest_period) && $type == 'create') { return array( 'alma_preferred_branch' => $$preferred_branch, - 'alma_interest_period' => $interest_period, + 'interest_period' => $interest_period, ); } else { $branch_valid = ding_reservation_default_options_branch_validate($type, 'alma_preferred_branch', $preferred_branch, $values); - $period_valid = ding_reservation_default_options_interest_period_validate($type, 'alma_interest_period', $interest_period, $values); + $period_valid = ding_reservation_default_options_interest_period_validate($type, 'interest_period', $interest_period, $values); return array_merge($branch_valid, $period_valid); } } @@ -182,20 +182,26 @@ function alma_reservation_create($account, $id, $options = array(), $expiry = NU $entity = profile2_load_by_user($account, 'provider_alma'); if (!empty($entity)) { $wrapper = entity_metadata_wrapper('profile2', $entity); - // interest period - if (!isset($expiry)) { - - // Use a metadata wrapper to access the data. - $interest_period = $wrapper->field_alma_interest_period->value(); - if ($interest_period) { - // Change it to secounds from days. - $expiry = $interest_period * 86400; + + // Interest period + $expiry = 0; + if (!isset($options['interest_period'])) { + if (!isset($expiry)) { + // Use a metadata wrapper to access the data. + $interest_period = $wrapper->field_alma_interest_period->value(); + if ($interest_period) { + // Change it to secounds from days. + $expiry = $interest_period * 86400; + } + } + else { + // The user don't have a default interest period, so use the system wide + // one for alma (which default is 180 days). + $expiry = variable_get('alma_default_interest_period', 180) * 86400; } } - if (!isset($expiry)) { - // The user don't have a default interest period, so use the system wide - // one for alma (which default is 180 days). - $expiry = variable_get('alma_default_interest_period', 180) * 86400; + else { + $expiry = $options['interest_period'] * 86400; } // Preferred branch @@ -256,7 +262,7 @@ function alma_reservation_update($account, $ids, $options) { // Processing IDs. If at least one is updated, return true. foreach ($ids as $id) { if (isset($reservations[$id])) { - $expiry_date = !empty($options['alma_interest_period']) ? alma_reservation_format_date(strtotime($reservations[$id]['valid_from']) + $options['alma_interest_period'] * 86400) : $reservations[$id]['valid_to']; + $expiry_date = !empty($options['interest_period']) ? alma_reservation_format_date(strtotime($reservations[$id]['valid_from']) + $options['interest_period'] * 86400) : $reservations[$id]['valid_to']; $pickup_branch = !empty($options['alma_preferred_branch']) ? $options['alma_preferred_branch'] : $reservations[$id]['pickup_branch']; $changes = array( 'valid_to' => $expiry_date, @@ -293,6 +299,37 @@ function alma_reservation_delete($account, $id) { } } +/** + * Implements hook_default_interest_period(). + * + * Tries to find the users default interst period based on the users profile2 + * provider profile. + * + * @param object $profile + * The users profile2 provider profile. + * @return string + * The default interest period selected by the user in his/her profile or the + * default value selected by the site. + */ +function alma_reservation_default_interest_period($profile = NULL) { + // If profile is not given, try loading it for the user. + if (is_null($profile)) { + global $user; + $profile = ding_user_provider_profile($user); + } + + // Get interest period from the profile. + $wrapper = entity_metadata_wrapper('profile2', $profile); + $value = $wrapper->field_alma_interest_period->value(); + + // If no period is seleted, try getting default value. + if (is_null($value) || empty($value)) { + $value = variable_get('alma_default_interest_period', 180); + } + + return $value; +} + /** * Return a branch name for a given branch id. * From c1381c146e10197bd855d3d7a61c6784e46d2908 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 4 Jun 2013 10:08:00 +0200 Subject: [PATCH 077/158] Updated makefile to point to ding2tal --- alma.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alma.make b/alma.make index 9f805bd..946afd9 100644 --- a/alma.make +++ b/alma.make @@ -22,10 +22,10 @@ projects[virtual_field][version] = "1.1" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" -projects[ding_provider][download][url] = "git@github.com:ding2/ding_provider.git" +projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" projects[ding_provider][download][branch] = "master" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" -projects[ding_reservation][download][url] = "git@github.com:ding2/ding_reservation.git" +projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" projects[ding_reservation][download][branch] = "master" From 6c5c15b7c470173d51314ecdadcb57346bc56eb6 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 4 Jun 2013 10:26:08 +0200 Subject: [PATCH 078/158] Fixed reservation create to use ding_user_provider_profile() --- includes/alma.reservation.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 6f649f3..1768b31 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -179,12 +179,11 @@ function alma_reservation_create($account, $id, $options = array(), $expiry = NU throw new DingProviderReservationExists(); } - $entity = profile2_load_by_user($account, 'provider_alma'); + $entity = ding_user_provider_profile($account);; if (!empty($entity)) { $wrapper = entity_metadata_wrapper('profile2', $entity); // Interest period - $expiry = 0; if (!isset($options['interest_period'])) { if (!isset($expiry)) { // Use a metadata wrapper to access the data. From c2539cc7f1c6d5b5f19f73ca195237ef2ae9885c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 4 Jun 2013 11:32:14 +0200 Subject: [PATCH 079/158] Added new hook_reservation_deletion_enabled() --- includes/alma.reservation.inc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 1768b31..15f5605 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -329,6 +329,18 @@ function alma_reservation_default_interest_period($profile = NULL) { return $value; } +/** + * Implements hook_reservation_deletion_enabled(). + * + * Check where reservation deletion have been enabled in the providers settings. + * + * @return bool + * If enabled TRUE else FALSE. + */ +function alma_reservation_reservation_deletion_enabled() { + return variable_get('alma_enable_reservation_deletion', FALSE); +} + /** * Return a branch name for a given branch id. * From 06f8e7b628975a9e4fd69db47032c8707f08cf59 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 5 Jun 2013 10:43:31 +0200 Subject: [PATCH 080/158] Removed session based cache, as it do not play nice with drupal --- includes/alma.debt.inc | 23 ++++++------------- includes/alma.loan.inc | 43 ++++++++++++++--------------------- includes/alma.reservation.inc | 7 ++---- 3 files changed, 26 insertions(+), 47 deletions(-) diff --git a/includes/alma.debt.inc b/includes/alma.debt.inc index 78a4309..2c08fa8 100644 --- a/includes/alma.debt.inc +++ b/includes/alma.debt.inc @@ -19,20 +19,14 @@ function alma_debt_list($account, $reset = FALSE) { $cache_key = 'alma_debts'; $results = &drupal_static(__FUNCTION__, FALSE); if (!$results || $reset) { - $results = ding_provider_session_cache_get($cache_key); - if (!$results || $reset) { - // Get debts from Alma. - $debts = alma_client_invoke('get_debts', $creds['name'], $creds['pass']); + // Get debts from Alma. + $debts = alma_client_invoke('get_debts', $creds['name'], $creds['pass']); - // Create DingProviderDebt instances from Alma's list. - $result = array(); - foreach ($debts['debts'] as $debt) { - $debt_object = new DingProviderDebt($debt['id'], $debt); - $result[$debt['id']] = $debt_object; - } - - // Store result into the session cache. - ding_provider_session_cache_set($cache_key, $results); + // Create DingProviderDebt instances from Alma's list. + $result = array(); + foreach ($debts['debts'] as $debt) { + $debt_object = new DingProviderDebt($debt['id'], $debt); + $result[$debt['id']] = $debt_object; } } @@ -50,9 +44,6 @@ function alma_debt_list($account, $reset = FALSE) { * Order ID of the payment transaction, to be recorded in the backend system. */ function alma_debt_payment_received($amount, $debt_ids = array(), $order_id = NULL) { - // Clear loans session cache. - ding_provider_session_cache_clear('alma_debts'); - // Return result from Alma. return alma_client_invoke('add_payment', implode(',', $debt_ids), $order_id); } diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index c710b4f..45f01b7 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -19,30 +19,24 @@ function alma_loan_list($account, $reset = FALSE) { $cache_key = 'alma_loans'; $results = &drupal_static(__FUNCTION__, FALSE); if (!$results || $reset) { - $results = ding_provider_session_cache_get($cache_key); - if (!$results || $reset) { - try { - // Get all loans form alma for the user account given. - $loans = alma_client_invoke('get_loans', $creds['name'], $creds['pass']); - } - catch (Exception $e) { - throw new DingProviderLoanUserError($e->getMessage()); - } - - $results = array(); - foreach ($loans as $loan) { - $results[$loan['id']] = new DingProviderLoan($loan['id'], array( - 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $loan['record_id'], - 'loan_date' => $loan['loan_date'], - 'expiry' => $loan['due_date'], - 'renewable' => $loan['is_renewable'], - 'materials_number' => $loan['id'], - 'notes' => isset($loan['notes']) ? $loan['notes'] : DingEntityBase::NULL, - )); - } + try { + // Get all loans form alma for the user account given. + $loans = alma_client_invoke('get_loans', $creds['name'], $creds['pass']); + } + catch (Exception $e) { + throw new DingProviderLoanUserError($e->getMessage()); + } - // Store result into the session cache. - ding_provider_session_cache_set($cache_key, $results, 300); + $results = array(); + foreach ($loans as $loan) { + $results[$loan['id']] = new DingProviderLoan($loan['id'], array( + 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $loan['record_id'], + 'loan_date' => $loan['loan_date'], + 'expiry' => $loan['due_date'], + 'renewable' => $loan['is_renewable'], + 'materials_number' => $loan['id'], + 'notes' => isset($loan['notes']) ? $loan['notes'] : DingEntityBase::NULL, + )); } } @@ -71,9 +65,6 @@ function alma_loan_renew($account, $ids) { } } - // Clear loans session cache. - ding_provider_session_cache_clear('alma_loans'); - return $result; } diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index feaeb5e..0109988 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -373,10 +373,7 @@ function alma_reservation_get_reservations($account, $reset = FALSE) { $cache_key = 'alma_reservations'; $reservations = &drupal_static(__FUNCTION__, FALSE); if (!$reservations || $reset) { - $reservations = ding_provider_session_cache_get($cache_key); - if (!$reservations || $reset) { - $reservations = alma_client_invoke('get_reservations', $creds['name'], $creds['pass']); - } + $reservations = alma_client_invoke('get_reservations', $creds['name'], $creds['pass']); } return $reservations; @@ -386,7 +383,7 @@ function alma_reservation_get_reservations($account, $reset = FALSE) { * Clear reservations stored in the current session cache. */ function alma_reservation_clear_cache() { - ding_provider_session_cache_clear('alma_reservations'); + } /** From 3b5b352adc8eac95212f9e1b86921707eb3048c7 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 6 Jun 2013 13:09:03 +0200 Subject: [PATCH 081/158] Moved sorting of reservation types into the module --- includes/alma.reservation.inc | 59 +++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 0109988..0a63d6d 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -113,46 +113,57 @@ function alma_reservation_set_preferred_branch($account, $branch) { } /** - * Get list of reserved items. + * Get list of reserved items index by reservation type. * * @param type $account * @return object DingProviderReservation */ -function alma_reservation_list($account) { +function alma_reservation_list($account, $type = NULL) { $reservations = alma_reservation_get_reservations($account); - $result = array(); + $result = array( + 'ready_for_pickup' => array(), + 'not_ready_for_pickup' => array(), + 'interlibrary_loans' => array(), + ); - // Create DingProviderReservation objects into to categories base on pickup - // status. + // Create DingProviderReservation objects into three categories. foreach ($reservations as $reservation) { - if (isset($reservation['pickup_number'])) { - $result[$reservation['id']] = new DingProviderReservation($reservation['id'], array( + // Build standard array which matches all types of reservations. + $data = array( 'order_id' => $reservation['id'], 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $reservation['record_id'], 'pickup_branch_id' => $reservation['pickup_branch'], 'order_arrived' => NULL, - 'pickup_order_id' => $reservation['pickup_number'], - 'pickup_date' => $reservation['pickup_expire_date'], + 'pickup_order_id' => NULL, + 'pickup_date' => NULL, + 'ready_for_pickup' => FALSE, 'created' => $reservation['create_date'], 'expiry' => $reservation['valid_to'], 'queue_number' => $reservation['queue_number'], - 'ready_for_pickup' => 1, + 'ill_status' => FALSE, 'notes' => isset($reservation['notes']) ? $reservation['notes'] : '', - )); + ); + + // If the reservation is ready for pick-up, we fill in that data. + if (isset($reservation['pickup_number'])) { + // Set pick-up information. + $data['pickup_order_id'] = $reservation['pickup_number']; + $data['pickup_date'] = $reservation['pickup_expire_date']; + $data['ready_for_pickup'] = TRUE; + + // Create reservation object. + $result['ready_for_pickup'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data); + } + else if ($reservation['id'] < 0) { + // Interlibrary loan reservations have negative IDs (undocumented Axiell "feature"). + $data['ill_status'] = TRUE; + + // Create reservation object. + $result['interlibrary_loans'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data);; } else { - $result[$reservation['id']] = new DingProviderReservation($reservation['id'], array( - 'order_id' => $reservation['id'], - 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $reservation['record_id'], - 'pickup_branch_id' => $reservation['pickup_branch'], - 'order_arrived' => NULL, - 'pickup_order_id' => NULL, - 'created' => $reservation['create_date'], - 'expiry' => $reservation['valid_to'], - 'queue_number' => $reservation['queue_number'], - 'ready_for_pickup' => 0, - 'notes' => isset($reservation['notes']) ? $reservation['notes'] : '', - )); + // Default case with, so just create the reservation object. + $result['not_ready_for_pickup'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data);; } } @@ -383,7 +394,7 @@ function alma_reservation_get_reservations($account, $reset = FALSE) { * Clear reservations stored in the current session cache. */ function alma_reservation_clear_cache() { - + } /** From 5eaf4eb461ebecfb3aab228b582c6a39c2c7a7ae Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 6 Jun 2013 13:47:34 +0200 Subject: [PATCH 082/158] Added support for getting only one type of reservations --- includes/alma.reservation.inc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 0a63d6d..529f81b 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -167,6 +167,16 @@ function alma_reservation_list($account, $type = NULL) { } } + if (!is_null($type)) { + if (isset($result[$type])) { + return $result[$type]; + } + else { + watchdog('alma', 'Unknown reservation type (%type) requested', array('%type' => $type) , WATCHDOG_ERROR); + return array(); + } + } + return $result; } From 47071841de5e52784bb6359c0477fcad8080d416 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 6 Jun 2013 15:01:29 +0200 Subject: [PATCH 083/158] Fixed undefined indexes for ill records in hook_populate_pseudo_entity() --- includes/alma.loan.inc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index 45f01b7..4701bb6 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -86,8 +86,16 @@ function alma_loan_populate_pseudo_entity($ting_entity) { $ting_entity->reply->record['dc:title']['dkdcplus:full'] = array($source['titles'][0]); $ting_entity->reply->record['dc:type']['dkdcplus:BibDK-Type'] = array($source['media_class']); $ting_entity->reply->record['dc:date'][''] = array($source['publication_year']); - $ting_entity->reply->record['dc:creator']['dkdcplus:aut'] = $source['authors']; - $ting_entity->reply->record['dc:identifier']['dkdcplus:ISBN'][0] = str_replace(array('-', ' ', 'ISBN'), '', $source['isbns'][0]); + + // If it a ill Alma record authors are not always available. + if (isset($source['authors'])) { + $ting_entity->reply->record['dc:creator']['dkdcplus:aut'] = $source['authors']; + } + + // If it a ill Alma record isbn are not always available. + if (isset($source['isbns'][0])) { + $ting_entity->reply->record['dc:identifier']['dkdcplus:ISBN'][0] = str_replace(array('-', ' ', 'ISBN'), '', $source['isbns'][0]); + } $ting_entity->ting_title = array(LANGUAGE_NONE => array(array('id' => $ting_entity->ding_entity_id))); $ting_entity->ting_type = array(LANGUAGE_NONE => array(array('id' => $ting_entity->ding_entity_id))); From 1b793a08577b46e83084888cf68f2df2f2e10b3c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 6 Jun 2013 16:38:33 +0200 Subject: [PATCH 084/158] Added session cache to alma reservations --- alma.module | 14 +++++ includes/alma.reservation.inc | 104 ++++++++++++++++++++-------------- 2 files changed, 74 insertions(+), 44 deletions(-) diff --git a/alma.module b/alma.module index 1c7eae7..f023650 100644 --- a/alma.module +++ b/alma.module @@ -630,5 +630,19 @@ function alma_profile2_load($entities) { } } +/** + * Implements hook_ding_session_cache_defaults(). + * + * Set default ding_session_cache settings and tell ding_session_cache that this + * module supports it. + */ +function alma_ding_session_cache_defaults() { + return array( + 'titel' => 'Alma (reservations, loans)', + 'enabled' => TRUE, + 'expire' => 3600, + ); +} + // Include the feature code. include_once 'alma.features.inc'; diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 529f81b..a2590da 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -119,51 +119,68 @@ function alma_reservation_set_preferred_branch($account, $branch) { * @return object DingProviderReservation */ function alma_reservation_list($account, $type = NULL) { - $reservations = alma_reservation_get_reservations($account); - $result = array( - 'ready_for_pickup' => array(), - 'not_ready_for_pickup' => array(), - 'interlibrary_loans' => array(), - ); + $result = &drupal_static(__FUNCTION__); + if (!isset($result)) { + // Check if ding_session_cache is available. + if (module_exists('ding_session_cache')) { + $result = ding_session_cache_get('alma', 'reservations'); + } - // Create DingProviderReservation objects into three categories. - foreach ($reservations as $reservation) { - // Build standard array which matches all types of reservations. - $data = array( - 'order_id' => $reservation['id'], - 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $reservation['record_id'], - 'pickup_branch_id' => $reservation['pickup_branch'], - 'order_arrived' => NULL, - 'pickup_order_id' => NULL, - 'pickup_date' => NULL, - 'ready_for_pickup' => FALSE, - 'created' => $reservation['create_date'], - 'expiry' => $reservation['valid_to'], - 'queue_number' => $reservation['queue_number'], - 'ill_status' => FALSE, - 'notes' => isset($reservation['notes']) ? $reservation['notes'] : '', - ); + // If both static cache and session cache faild, try reloading information + // from alma. + if (!isset($result) || !$result) { + $reservations = alma_reservation_get_reservations($account); + $result = array( + 'ready_for_pickup' => array(), + 'not_ready_for_pickup' => array(), + 'interlibrary_loans' => array(), + ); - // If the reservation is ready for pick-up, we fill in that data. - if (isset($reservation['pickup_number'])) { - // Set pick-up information. - $data['pickup_order_id'] = $reservation['pickup_number']; - $data['pickup_date'] = $reservation['pickup_expire_date']; - $data['ready_for_pickup'] = TRUE; + // Create DingProviderReservation objects into three categories. + foreach ($reservations as $reservation) { + // Build standard array which matches all types of reservations. + $data = array( + 'order_id' => $reservation['id'], + 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $reservation['record_id'], + 'pickup_branch_id' => $reservation['pickup_branch'], + 'order_arrived' => NULL, + 'pickup_order_id' => NULL, + 'pickup_date' => NULL, + 'ready_for_pickup' => FALSE, + 'created' => $reservation['create_date'], + 'expiry' => $reservation['valid_to'], + 'queue_number' => $reservation['queue_number'], + 'ill_status' => FALSE, + 'notes' => isset($reservation['notes']) ? $reservation['notes'] : '', + ); + + // If the reservation is ready for pick-up, we fill in that data. + if (isset($reservation['pickup_number'])) { + // Set pick-up information. + $data['pickup_order_id'] = $reservation['pickup_number']; + $data['pickup_date'] = $reservation['pickup_expire_date']; + $data['ready_for_pickup'] = TRUE; + + // Create reservation object. + $result['ready_for_pickup'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data); + } + else if ($reservation['id'] < 0) { + // Interlibrary loan reservations have negative IDs (undocumented Axiell "feature"). + $data['ill_status'] = TRUE; - // Create reservation object. - $result['ready_for_pickup'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data); - } - else if ($reservation['id'] < 0) { - // Interlibrary loan reservations have negative IDs (undocumented Axiell "feature"). - $data['ill_status'] = TRUE; + // Create reservation object. + $result['interlibrary_loans'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data);; + } + else { + // Default case with, so just create the reservation object. + $result['not_ready_for_pickup'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data);; + } + } - // Create reservation object. - $result['interlibrary_loans'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data);; - } - else { - // Default case with, so just create the reservation object. - $result['not_ready_for_pickup'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data);; + // Store the reservations into ding session cache. + if (module_exists('ding_session_cache')) { + ding_session_cache_set('alma', 'reservations', $result); + } } } @@ -391,7 +408,6 @@ function alma_reservation_branch_name($branch_id) { function alma_reservation_get_reservations($account, $reset = FALSE) { $creds = ding_user_get_creds($account); - $cache_key = 'alma_reservations'; $reservations = &drupal_static(__FUNCTION__, FALSE); if (!$reservations || $reset) { $reservations = alma_client_invoke('get_reservations', $creds['name'], $creds['pass']); @@ -404,7 +420,7 @@ function alma_reservation_get_reservations($account, $reset = FALSE) { * Clear reservations stored in the current session cache. */ function alma_reservation_clear_cache() { - + ding_session_cache_clear('alma', 'reservations'); } /** @@ -434,4 +450,4 @@ function alma_reservation_exists($account, $item_id) { */ function alma_reservation_format_date($expiry) { return date('Y-m-d', $expiry); -} +} \ No newline at end of file From 79b1c0b32836d1f14dd6d2e69e7a15eaa9322ebd Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 6 Jun 2013 21:56:59 +0200 Subject: [PATCH 085/158] Added ding session cache to loans --- includes/alma.loan.inc | 47 ++++++++++++++++++++++------------- includes/alma.reservation.inc | 2 +- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index 4701bb6..d6b5136 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -16,27 +16,40 @@ function alma_loan_list($account, $reset = FALSE) { // is not longer logged in. $creds = ding_user_get_creds($account); - $cache_key = 'alma_loans'; $results = &drupal_static(__FUNCTION__, FALSE); if (!$results || $reset) { - try { - // Get all loans form alma for the user account given. - $loans = alma_client_invoke('get_loans', $creds['name'], $creds['pass']); - } - catch (Exception $e) { - throw new DingProviderLoanUserError($e->getMessage()); + // Check if ding_session_cache is available. + if (module_exists('ding_session_cache')) { + $results = ding_session_cache_get('alma', 'loans'); } - $results = array(); - foreach ($loans as $loan) { - $results[$loan['id']] = new DingProviderLoan($loan['id'], array( - 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $loan['record_id'], - 'loan_date' => $loan['loan_date'], - 'expiry' => $loan['due_date'], - 'renewable' => $loan['is_renewable'], - 'materials_number' => $loan['id'], - 'notes' => isset($loan['notes']) ? $loan['notes'] : DingEntityBase::NULL, - )); + // If both static cache and session cache faild, try reloading information + // from alma. + if (empty($results) || $reset) { + try { + // Get all loans form alma for the user account given. + $loans = alma_client_invoke('get_loans', $creds['name'], $creds['pass']); + } + catch (Exception $e) { + throw new DingProviderLoanUserError($e->getMessage()); + } + + $results = array(); + foreach ($loans as $loan) { + $results[$loan['id']] = new DingProviderLoan($loan['id'], array( + 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $loan['record_id'], + 'loan_date' => $loan['loan_date'], + 'expiry' => $loan['due_date'], + 'renewable' => $loan['is_renewable'], + 'materials_number' => $loan['id'], + 'notes' => isset($loan['notes']) ? $loan['notes'] : DingEntityBase::NULL, + )); + } + + // Store the reservations into ding session cache. + if (module_exists('ding_session_cache')) { + ding_session_cache_set('alma', 'loans', $results); + } } } diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index a2590da..c49f606 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -128,7 +128,7 @@ function alma_reservation_list($account, $type = NULL) { // If both static cache and session cache faild, try reloading information // from alma. - if (!isset($result) || !$result) { + if (empty($result)) { $reservations = alma_reservation_get_reservations($account); $result = array( 'ready_for_pickup' => array(), From 509ebe4e53b6e07c14db14ce620744a95952d62d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 6 Jun 2013 22:05:19 +0200 Subject: [PATCH 086/158] Added session cache clear for loans --- includes/alma.loan.inc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index d6b5136..5f35109 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -69,6 +69,11 @@ function alma_loan_renew($account, $ids) { foreach ($ids as $id) { if (isset($res[$id]) && $res[$id] === TRUE) { $result[$id] = DingProviderLoan::STATUS_RENEWED; + + // Clear ding session cache. + if (module_exists('ding_session_cache')) { + ding_session_cache_clear('alma', 'loans'); + } } else { /** From 4f3e963f3dc409818a8bed4b6bf12a403e040d65 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 10 Jun 2013 12:51:06 +0200 Subject: [PATCH 087/158] Fixed already reservated (move return statement outside foreach) --- includes/alma.reservation.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index c49f606..72bbb71 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -436,8 +436,8 @@ function alma_reservation_exists($account, $item_id) { if ($res['record_id'] == $item_id) { return TRUE; } - return FALSE; } + return FALSE; } /** From a4bb4dedd348dbde63a039139a7fc10036bef78e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 11 Jun 2013 15:55:28 +0200 Subject: [PATCH 088/158] Changed default interest period to 6 months --- alma.features.field_instance.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alma.features.field_instance.inc b/alma.features.field_instance.inc index bfcffb6..149a19f 100644 --- a/alma.features.field_instance.inc +++ b/alma.features.field_instance.inc @@ -107,7 +107,7 @@ function alma_field_default_field_instances() { 'bundle' => 'provider_alma', 'default_value' => array( 0 => array( - 'value' => 30, + 'value' => 180, ), ), 'deleted' => 0, From eab1d5cb8ad7e4ef332ff0d5741d1812bef96e9e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 20 Jun 2013 11:10:07 +0200 Subject: [PATCH 089/158] Changed watchdog statements to watchdog exception statements --- alma.module | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/alma.module b/alma.module index 1c7eae7..a327a5a 100644 --- a/alma.module +++ b/alma.module @@ -374,7 +374,7 @@ function alma_update_provider($changes, $entity) { $creds = ding_user_get_creds($entity); } catch (Exception $exception) { - watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); + watchdog_exception('Alma provider', $exception); throw $exception; } @@ -386,7 +386,7 @@ function alma_update_provider($changes, $entity) { $res = alma_client_invoke('remove_phone_number', $creds['name'], $creds['pass'], $changes['phone_id']); } catch (Exception $exception) { - watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); + watchdog_exception('Alma provider', $exception); } if (empty($res)) { @@ -400,7 +400,7 @@ function alma_update_provider($changes, $entity) { $res = alma_client_invoke('change_phone_number', $creds['name'], $creds['pass'], $changes['phone_id'], $changes['mobile']); } catch (Exception $exception) { - watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); + watchdog_exception('Alma provider', $exception); } if (!$res) { @@ -415,7 +415,7 @@ function alma_update_provider($changes, $entity) { $res = alma_client_invoke('add_phone_number', $creds['name'], $creds['pass'], $changes['mobile']); } catch (Exception $exception) { - watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); + watchdog_exception('Alma provider', $exception); } if (!$res) { $error_message .= t('mobile not added'); @@ -432,7 +432,7 @@ function alma_update_provider($changes, $entity) { $res = alma_client_invoke('change_absent_period', $creds['name'], $creds['pass'], $changes['absent_id'], $changes['reservation_pause_start'], $changes['reservation_pause_stop']); } catch (Exception $exception) { - watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); + watchdog_exception('Alma provider', $exception); } if (empty($res)) { $error_message .= t('reservation pause not updated'); @@ -445,7 +445,7 @@ function alma_update_provider($changes, $entity) { $res = alma_client_invoke('add_absent_period', $creds['name'], $creds['pass'], $changes['reservation_pause_start'], $changes['reservation_pause_stop']); } catch (Exception $exception) { - watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); + watchdog_exception('Alma provider', $exception); } if (empty($res)) { $error_message .= t('reservation pause not added'); @@ -458,7 +458,7 @@ function alma_update_provider($changes, $entity) { $res = alma_client_invoke('remove_absent_period', $creds['name'], $creds['pass'], $changes['absent_id']); } catch (Exception $exception) { - watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); + watchdog_exception('Alma provider', $exception); } } @@ -468,7 +468,7 @@ function alma_update_provider($changes, $entity) { $res = alma_client_invoke('change_patron_preferences', $creds['name'], $creds['pass'], $changes['preferred_branch']); } catch (Exception $exception) { - watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); + watchdog_exception('Alma provider', $exception); } if (empty($res)) { $error_message .= t('pickup branch not saved'); @@ -492,7 +492,7 @@ function alma_update_provider($changes, $entity) { } } catch (Exception $exception) { - watchdog('Alma provider', $exception->getMessage(), array(), WATCHDOG_ERROR); + watchdog_exception('Alma provider', $exception); } if (empty($res)) { From 942d8ace72d68c1107cb17cc50a46963494b0fb5 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 20 Jun 2013 11:25:07 +0200 Subject: [PATCH 090/158] Added constants for the date formats used by alma --- alma.module | 16 ++++++++++------ includes/alma.reservation.inc | 6 +++--- lib/AlmaClient/AlmaClient.class.php | 6 +++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/alma.module b/alma.module index a327a5a..6977f91 100644 --- a/alma.module +++ b/alma.module @@ -6,6 +6,10 @@ define('ALMA_AUTH_BLOCKED', '4e5531951f55ab8f6895684999c69c2'); +// Define date formats used by Alma +define('ALMA_DATE', 'Y-m-d'); +define('ALMA_DATE_LONG', 'Y-m-d m:i:s'); + /** * Get list of pickup branches. */ @@ -273,22 +277,22 @@ function alma_profile2_presave($entity) { $value = $wrapper->field_alma_reservation_pause->value(); $start = ''; if (!is_null($value['value'])) { - $start = date('Y-m-d', strtotime($value['value'])); + $start = date(ALMA_DATE, strtotime($value['value'])); } $stop = ''; if (!is_null($value['value2'])) { - $stop = date('Y-m-d', strtotime($value['value2'])); + $stop = date(ALMA_DATE, strtotime($value['value2'])); } // Reservation pause (Stop) $value = $wrapper_original->field_alma_reservation_pause->value(); $org_start = ''; if (!is_null($value['value'])) { - $org_start = date('Y-m-d', strtotime($value['value'])); + $org_start = date(ALMA_DATE, strtotime($value['value'])); } $org_stop = ''; if (!is_null($value['value2'])) { - $org_stop = date('Y-m-d', strtotime($value['value2'])); + $org_stop = date(ALMA_DATE, strtotime($value['value2'])); } // Check if the reservation pause have changed. @@ -603,8 +607,8 @@ function alma_profile2_load($entities) { if (isset($patron->absentPeriods[0]) && isset($patron->absentPeriods[0]['from_date']) && isset($patron->absentPeriods[0]['to_date'])) { $wrapper->field_alma_reservation_pause->set(array( - 'value' => date('Y-m-d m:i:s', strtotime($patron->absentPeriods[0]['from_date'])), - 'value2' => date('Y-m-d m:i:s', strtotime($patron->absentPeriods[0]['to_date'])), + 'value' => date(ALMA_DATE_LONG, strtotime($patron->absentPeriods[0]['from_date'])), + 'value2' => date(ALMA_DATE_LONG, strtotime($patron->absentPeriods[0]['to_date'])), )); $wrapper->field_alma_absent_id->set($patron->absentPeriods[0]['id']); } diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 15f5605..15885e9 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -213,7 +213,7 @@ function alma_reservation_create($account, $id, $options = array(), $expiry = NU // Build the reservation parameters to send. $params = array( 'id' => $id, - 'valid_from' => date('Y-m-d'), + 'valid_from' => date(ALMA_DATE), 'valid_to' => alma_reservation_format_date(time() + $expiry), 'pickup_branch' => $branch, ); @@ -405,8 +405,8 @@ function alma_reservation_exists($account, $item_id) { * @param int $expiry * The number of secounds into the feature we need at date. * @return string - * The date in the feature in the format 'Y-m-d'. + * The date in the feature in the format 'Y-m-d' (ALMA_DATE). */ function alma_reservation_format_date($expiry) { - return date('Y-m-d', $expiry); + return date(ALMA_DATE, $expiry); } diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index 1f9744f..c66318a 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -435,7 +435,7 @@ public function add_reservation($borr_card, $pin_code, $reservation) { // If there's not a validFrom date, set it as today. if (empty($params['reservationValidFrom'])) { - $params['reservationValidFrom'] = date('Y-m-d', $_SERVER['REQUEST_TIME']); + $params['reservationValidFrom'] = date(ALMA_DATE, $_SERVER['REQUEST_TIME']); } // If there's not a validTo date, set it a year in the future. @@ -876,8 +876,8 @@ public function change_absent_period($borr_card, $pin_code, $absent_id, $from_da 'borrCard' => $borr_card, 'pinCode' => $pin_code, 'absentId' => $absent_id, - 'absentFrom' => date_format(date_create($from_date), 'Y-m-d'), - 'absentTo' => date_format(date_create($to_date), 'Y-m-d'), + 'absentFrom' => date_format(date_create($from_date), ALMA_DATE), + 'absentTo' => date_format(date_create($to_date), ALMA_DATE), ); $doc = $this->request('patron/absent/change', $params); From 0833137cc47117c39c80b1f30ab3696a9793bba4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 24 Jun 2013 14:52:34 +0200 Subject: [PATCH 091/158] Changed makefile to use development branch --- alma.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alma.make b/alma.make index 946afd9..17b4a6d 100644 --- a/alma.make +++ b/alma.make @@ -23,9 +23,9 @@ projects[virtual_field][version] = "1.1" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][branch] = "master" +projects[ding_provider][download][branch] = "development" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" -projects[ding_reservation][download][branch] = "master" +projects[ding_reservation][download][branch] = "development" From f5ecd05603d6126110e046620133711f624c29e5 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 3 Jul 2013 13:34:43 +0200 Subject: [PATCH 092/158] Updated makefile to point to development branch and ding2tal --- alma.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alma.make b/alma.make index 946afd9..17b4a6d 100644 --- a/alma.make +++ b/alma.make @@ -23,9 +23,9 @@ projects[virtual_field][version] = "1.1" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][branch] = "master" +projects[ding_provider][download][branch] = "development" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" -projects[ding_reservation][download][branch] = "master" +projects[ding_reservation][download][branch] = "development" From 2ac9fa9f996f7045acc3cfae9e34e9c3cff054a7 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 9 Sep 2013 15:53:44 +0200 Subject: [PATCH 093/158] Fixed coding styles --- includes/alma.reservation.inc | 57 +++++++++++++++++------------------ 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index fe0791c..99b08dc 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -57,7 +57,7 @@ function alma_reservation_options_validate($type, $account, $reservables, $value // Get values. $preferred_branch = $wrapper->field_alma_preferred_branch->value();; - $interest_period = $wrapper->field_alma_interest_period->value(); + $interest_period = $wrapper->field_alma_interest_period->value(); // Perform a check to whether a show specific select dropdown. // Returning NULL means to skip this check, therefore to reserve instantly. @@ -140,18 +140,18 @@ function alma_reservation_list($account, $type = NULL) { foreach ($reservations as $reservation) { // Build standard array which matches all types of reservations. $data = array( - 'order_id' => $reservation['id'], - 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $reservation['record_id'], - 'pickup_branch_id' => $reservation['pickup_branch'], - 'order_arrived' => NULL, - 'pickup_order_id' => NULL, - 'pickup_date' => NULL, - 'ready_for_pickup' => FALSE, - 'created' => $reservation['create_date'], - 'expiry' => $reservation['valid_to'], - 'queue_number' => $reservation['queue_number'], - 'ill_status' => FALSE, - 'notes' => isset($reservation['notes']) ? $reservation['notes'] : '', + 'order_id' => $reservation['id'], + 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $reservation['record_id'], + 'pickup_branch_id' => $reservation['pickup_branch'], + 'order_arrived' => NULL, + 'pickup_order_id' => NULL, + 'pickup_date' => NULL, + 'ready_for_pickup' => FALSE, + 'created' => $reservation['create_date'], + 'expiry' => $reservation['valid_to'], + 'queue_number' => $reservation['queue_number'], + 'ill_status' => FALSE, + 'notes' => isset($reservation['notes']) ? $reservation['notes'] : '', ); // If the reservation is ready for pick-up, we fill in that data. @@ -164,7 +164,7 @@ function alma_reservation_list($account, $type = NULL) { // Create reservation object. $result['ready_for_pickup'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data); } - else if ($reservation['id'] < 0) { + elseif ($reservation['id'] < 0) { // Interlibrary loan reservations have negative IDs (undocumented Axiell "feature"). $data['ill_status'] = TRUE; @@ -189,7 +189,7 @@ function alma_reservation_list($account, $type = NULL) { return $result[$type]; } else { - watchdog('alma', 'Unknown reservation type (%type) requested', array('%type' => $type) , WATCHDOG_ERROR); + watchdog('alma', 'Unknown reservation type (%type) requested', array('%type' => $type), WATCHDOG_ERROR); return array(); } } @@ -221,13 +221,13 @@ function alma_reservation_create($account, $id, $options = array(), $expiry = NU if (!empty($entity)) { $wrapper = entity_metadata_wrapper('profile2', $entity); - // Interest period + // Interest period. if (!isset($options['interest_period'])) { if (!isset($expiry)) { // Use a metadata wrapper to access the data. $interest_period = $wrapper->field_alma_interest_period->value(); if ($interest_period) { - // Change it to secounds from days. + // Change it to seconds from days. $expiry = $interest_period * 86400; } } @@ -241,7 +241,7 @@ function alma_reservation_create($account, $id, $options = array(), $expiry = NU $expiry = $options['interest_period'] * 86400; } - // Preferred branch + // Preferred branch. $branch = $wrapper->field_alma_preferred_branch->value(); if (isset($options['alma_preferred_branch'])) { $branch = $options['alma_preferred_branch']; @@ -263,15 +263,13 @@ function alma_reservation_create($account, $id, $options = array(), $expiry = NU $result = alma_client_invoke('add_reservation', $creds['name'], $creds['pass'], $params); if ($result === ALMA_AUTH_BLOCKED) { - /** - * @todo return better exception that informs the user about the block - * status. - */ + // @todo return better exception that informs the user about the block + // status. throw new DingProviderReservationNotAllowed(); } if (is_int($result)) { - // Reset session cache + // Reset session cache. alma_reservation_clear_cache(); return array( 'branch' => $branch, @@ -286,9 +284,10 @@ function alma_reservation_create($account, $id, $options = array(), $expiry = NU /** * Update order, by defining new expiry date or pickup branch. * - * @param type $account - * @param type $ids - * @param type $options + * @param object $account + * @param array $ids + * @param array $options + * * @return boolean */ function alma_reservation_update($account, $ids, $options) { @@ -359,7 +358,7 @@ function alma_reservation_default_interest_period($profile = NULL) { $wrapper = entity_metadata_wrapper('profile2', $profile); $value = $wrapper->field_alma_interest_period->value(); - // If no period is seleted, try getting default value. + // If no period is selected, try getting default value. if (is_null($value) || empty($value)) { $value = variable_get('alma_default_interest_period', 180); } @@ -386,7 +385,7 @@ function alma_reservation_reservation_deletion_enabled() { * @return String */ function alma_reservation_branch_name($branch_id) { - // Get library organistation from alma. + // Get library organization from alma. $organisation = alma_get_organisation(); $branch = (is_array($branch_id) && isset($branch_id['alma_preferred_branch'])) ? $branch_id['alma_preferred_branch'] : $branch_id; if (isset($organisation['branch'][$branch])) { @@ -444,7 +443,7 @@ function alma_reservation_exists($account, $item_id) { * Helper function calculate the date in the feature base on interest period. * * @param int $expiry - * The number of secounds into the feature we need at date. + * The number of seconds into the feature we need at date. * @return string * The date in the feature in the format 'Y-m-d' (ALMA_DATE). */ From a9d07623a09391c1ccf5044858af52a89b72526d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 10 Sep 2013 11:30:27 +0200 Subject: [PATCH 094/158] Removed material number form display name in debts --- alma.info | 1 + includes/alma.debt.inc | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/alma.info b/alma.info index 28736ff..9c63c75 100644 --- a/alma.info +++ b/alma.info @@ -8,6 +8,7 @@ project = alma dependencies[] = date dependencies[] = ding_provider dependencies[] = ding_reservation +dependencies[] = ding_user dependencies[] = email dependencies[] = entity dependencies[] = features diff --git a/includes/alma.debt.inc b/includes/alma.debt.inc index 2c08fa8..ea9ff1e 100644 --- a/includes/alma.debt.inc +++ b/includes/alma.debt.inc @@ -9,6 +9,9 @@ * * @param stdClass $account * User object to provide debts for. + * @param bool $reset + * Reset static cache if TRUE else get debts from cache. + * * @return array * DingProviderDebt objects in array, keyed by debt ID. */ @@ -16,7 +19,6 @@ function alma_debt_list($account, $reset = FALSE) { $creds = ding_user_get_creds($account); // Use session cache to speed up communication with Alma. - $cache_key = 'alma_debts'; $results = &drupal_static(__FUNCTION__, FALSE); if (!$results || $reset) { // Get debts from Alma. @@ -25,6 +27,11 @@ function alma_debt_list($account, $reset = FALSE) { // Create DingProviderDebt instances from Alma's list. $result = array(); foreach ($debts['debts'] as $debt) { + // Get the material number from the display name and remove it form it. + preg_match('/^(\w+)\s+(.+)/', $debt['display_name'], $matchs); + $debt['display_name'] = $matchs[2]; + $debt['material_number'] = $matchs[1]; + $debt_object = new DingProviderDebt($debt['id'], $debt); $result[$debt['id']] = $debt_object; } @@ -42,6 +49,9 @@ function alma_debt_list($account, $reset = FALSE) { * IDs of the paid debts. * @param mixed $order_id * Order ID of the payment transaction, to be recorded in the backend system. + * + * @return array + * Array from ALMA with the results. */ function alma_debt_payment_received($amount, $debt_ids = array(), $order_id = NULL) { // Return result from Alma. From 1f4a199d4a473b24e09e391f56ae3c23bd266d11 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 10 Sep 2013 16:50:10 +0200 Subject: [PATCH 095/158] Updated coding style --- alma.install | 20 +++++++- alma.module | 87 +++++++++++++--------------------- includes/alma.availability.inc | 36 +++++++------- includes/alma.reservation.inc | 17 ++++--- 4 files changed, 83 insertions(+), 77 deletions(-) diff --git a/alma.install b/alma.install index 5077573..356ebc2 100644 --- a/alma.install +++ b/alma.install @@ -1,5 +1,23 @@ 'SimpleXML', + 'description' => $t('The Alma module requires SimpleXML to function. Please install and/or enable SimpleXML in your PHP configuration.'), + 'severity' => REQUIREMENT_ERROR, + ); + } + + return $requirements; +} /** * Update system table set alma weight=10 to ensure form_alter hooks are called @@ -32,7 +50,7 @@ function alma_update_7002() { function alma_update_7003() { return db_update('field_config') ->fields(array( - 'type' => 'datetime' + 'type' => 'datetime', )) ->condition('field_name', 'field_alma_reservation_pause', '=') ->execute(); diff --git a/alma.module b/alma.module index da7a7f5..7486610 100644 --- a/alma.module +++ b/alma.module @@ -6,7 +6,7 @@ define('ALMA_AUTH_BLOCKED', '4e5531951f55ab8f6895684999c69c2'); -// Define date formats used by Alma +// Define date formats used by Alma. define('ALMA_DATE', 'Y-m-d'); define('ALMA_DATE_LONG', 'Y-m-d m:i:s'); @@ -14,7 +14,7 @@ define('ALMA_DATE_LONG', 'Y-m-d m:i:s'); * Get list of pickup branches. */ function alma_reservation_pickup_branches($account = NULL) { - // Cache alma pickup branches - they are not likely to change + // Cache alma pickup branches - they are not likely to change. static $alma_pickup_branches; if (!isset($alma_pickup_branches)) { if ($cache = cache_get('alma_pickup_branches')) { @@ -38,25 +38,6 @@ function alma_get_interest_periods() { return $interest_periods; } -/** - * Implements hook_requirements(). - */ -function alma_requirements($phase) { - $requirements = array(); - // Ensure translations don't break at install time. - $t = get_t(); - - if (!function_exists('simplexml_load_string')) { - $requirements['simplexml'] = array( - 'title' => 'SimpleXML', - 'description' => $t('The Alma module requires SimpleXML to function. Please install and/or enable SimpleXML in your PHP configuration.'), - 'severity' => REQUIREMENT_ERROR, - ); - } - - return $requirements; -} - /** * Implements hook_ding_provider(). */ @@ -143,7 +124,7 @@ function alma_settings_form() { function alma_client() { // This is basically a singleton. We also wait until right before // instantiating to include our required classes. That seems like a - // decent performance tradeoff instead of loading everything on every + // decent performance trade-off instead of loading everything on every // page load. static $client; if (!isset($client)) { @@ -164,10 +145,8 @@ function alma_client() { * * @param $method * The desired method. - * @param ... - * Arguments to the method. * - * @return mixed + * @return array * NULL on error, or the result of the method call. */ function alma_client_invoke($method) { @@ -189,15 +168,16 @@ function alma_client_invoke($method) { /** * Get the complete organisation info from Alma. * - * Includes branches, departments, locations, sublocations and collections. The + * Includes branches, departments, locations, sub-locations and collections. The * information is cache until the cache is cleared or the reset parameter is * TRUE. * * @param boolean $reset - * Optional. If TRUE reset the cached data and reload. + * Optional. If TRUE reset the cached data and reload. + * * @return array - * Array of the different organisational unit, each an array of their - * member units. + * Array of the different organisational unit, each an array of their + * member units. */ function alma_get_organisation($reset = FALSE) { // Return data from cache if available. @@ -213,7 +193,7 @@ function alma_get_organisation($reset = FALSE) { 'location' => alma_client_invoke('get_locations'), 'sublocation' => alma_client_invoke('get_sublocations'), 'collection' => alma_client_invoke('get_collections'), - 'reservation' => alma_reservation_pickup_branches(), + 'reservation' => alma_reservation_pickup_branches(), ); // Cache output for 24 hours if we got all the data correctly. @@ -232,10 +212,11 @@ function alma_get_organisation($reset = FALSE) { * Callback function to get user information from Alma. * * @param array $creds - * The credentials for the user for which the information shold be retrived - * from Alma. + * The credentials for the user for which the information should be retrieved + * from Alma. + * * @return array - * Available information about the patron from Alma. + * Available information about the patron from Alma. */ function _alma_user_info($creds = NULL) { // Get patron informations from Alma. @@ -273,7 +254,7 @@ function alma_profile2_presave($entity) { $wrapper_original = entity_metadata_wrapper('profile2', $entity->original); $wrapper = entity_metadata_wrapper('profile2', $entity); - // Reservation pause (Start) + // Reservation pause (Start). $value = $wrapper->field_alma_reservation_pause->value(); $start = ''; if (!is_null($value['value'])) { @@ -284,7 +265,7 @@ function alma_profile2_presave($entity) { $stop = date(ALMA_DATE, strtotime($value['value2'])); } - // Reservation pause (Stop) + // Reservation pause (Stop). $value = $wrapper_original->field_alma_reservation_pause->value(); $org_start = ''; if (!is_null($value['value'])) { @@ -305,7 +286,7 @@ function alma_profile2_presave($entity) { $changes['absent_id'] = is_null($value) ? '' : $value; } - // Get preferred branch (patronBranch) + // Get preferred branch (patronBranch). $value = $wrapper->field_alma_preferred_branch->value(); if (!is_null($value)) { if ($value != $wrapper_original->field_alma_preferred_branch->value()) { @@ -325,14 +306,14 @@ function alma_profile2_presave($entity) { $changes['phone_id'] = $wrapper->field_alma_phone_id->value(); } } - else if (!is_null($value) && is_null($wrapper_original->field_alma_mobile_phone->value())) { + elseif (!is_null($value) && is_null($wrapper_original->field_alma_mobile_phone->value())) { $changes['mobile'] = $value; } // Get the mail. $value = $wrapper->field_alma_mail->value(); if (!is_null($value) && $value != $wrapper_original->field_alma_mail->value()) { - $changes['mail'] = $value; + $changes['mail'] = $value; } // Update provider. @@ -363,13 +344,13 @@ function alma_profile2_presave($entity) { * Update user information at the provider. * * @global object $user - * The user object for the currently logged in user. + * The user object for the currently logged in user. * * @param array $changes - * Array with the fields/information that have changed and should be updated at - * the provider. + * Array with the fields/information that have changed and should be updated + * at the provider. * @param object $entity - * An profile2 entity, mainly used to the user credentials. + * An profile2 entity, mainly used to the user credentials. */ function alma_update_provider($changes, $entity) { $error_message = t('Error communicating with library system.'); @@ -430,7 +411,7 @@ function alma_update_provider($changes, $entity) { // Update reservation pause (absentPeriod). if (!empty( $changes['absent_id']) && !empty($changes['reservation_pause_start']) && - !empty( $changes['reservation_pause_stop'])) { + !empty($changes['reservation_pause_stop'])) { try { $res = alma_client_invoke('change_absent_period', $creds['name'], $creds['pass'], $changes['absent_id'], $changes['reservation_pause_start'], $changes['reservation_pause_stop']); @@ -443,7 +424,7 @@ function alma_update_provider($changes, $entity) { drupal_set_message($error_message, 'warning'); } } - // Add reservation pause + // Add reservation pause. elseif (!empty($changes['reservation_pause_start']) && !empty($changes['reservation_pause_stop'])) { try { $res = alma_client_invoke('add_absent_period', $creds['name'], $creds['pass'], $changes['reservation_pause_start'], $changes['reservation_pause_stop']); @@ -480,17 +461,17 @@ function alma_update_provider($changes, $entity) { } } - // Update email (remeber to update the drupal user account). + // Update email (remember to update the drupal user account). if (!empty($changes['mail'])) { global $user; - // Update or add mail to alma + // Update or add mail to ALMA. try { - // Add email + // Add email. if (empty($user->mail) && !empty($changes['mail'])) { $res = alma_client_invoke('add_email_address', $creds['name'], $creds['pass'], $changes['mail']); } - // Change email + // Change email. elseif (isset($user->mail) && !empty($changes['mail'])) { $res = alma_client_invoke('change_email_address', $creds['name'], $creds['pass'], $user->mail, $changes['mail']); } @@ -555,9 +536,9 @@ function alma_get_patron($creds = NULL, $reset = FALSE, $as_array = FALSE) { } } - // Cast petron to object. + // Cast patron to object. if (!$as_array) { - $patron = (object)$patron; + $patron = (object) $patron; } return $patron; @@ -573,7 +554,6 @@ function alma_get_patron($creds = NULL, $reset = FALSE, $as_array = FALSE) { * * Note: that the interest period is store locally in the database as alma do * not have the ability to store it. So that field is not fill in here. - * */ function alma_profile2_load($entities) { foreach ($entities as $id => &$entity) { @@ -592,7 +572,7 @@ function alma_profile2_load($entities) { return; } - // Get uers information from alma. + // Get user information from alma. $patron = alma_get_patron($creds); } @@ -624,7 +604,8 @@ 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 + // 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); diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index 6d81e48..b43da96 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -8,7 +8,7 @@ * Implements provider availability, items. */ function alma_availability_items($provider_ids) { - $ids = join(',', $provider_ids); + $ids = implode(',', $provider_ids); $result = alma_client_invoke('get_availability', $ids); if (!$result) { $result = array(); @@ -20,7 +20,7 @@ function alma_availability_items($provider_ids) { * Implements provider availability, holdings. */ function alma_availability_holdings($provider_ids) { - $ids = join(',', $provider_ids); + $ids = implode(',', $provider_ids); $details = alma_client_invoke('catalogue_record_detail', $ids); $result = array(); @@ -66,13 +66,13 @@ function alma_availability_holdings($provider_ids) { * @todo: Rewrite this to have the provider create the holdings tables and not * return HTML from inside the provides them self. * - * @param type $res - * Returned array from alma_client class - * @param boolean $is_periodical - * Indicates whether the shown record is a periodical or not + * @param array $res + * Returned array from alma_client class + * @param bool $is_periodical + * Indicates whether the shown record is a periodical or not * * @return string - * HTML to be shown or FALSE if no data is received from alma. + * HTML to be shown or FALSE if no data is received from alma. */ function _alma_get_holdings($res, $is_periodical = FALSE) { if (isset($res['records'])) { @@ -92,6 +92,7 @@ function _alma_get_holdings($res, $is_periodical = FALSE) { * Set holdings for all kinds of material except periodicals. * * @param array $res + * * @return array $result; */ function _alma_set_holdings($res) { @@ -134,7 +135,8 @@ function _alma_set_holdings_periodical($res) { * Make the html-table. * * @param array $holding - * Holding information for a given material. + * Holding information for a given material. + * * @return html-table */ function _alma_set_table_html($holdings, $r_count) { @@ -176,7 +178,8 @@ function _alma_set_table_html($holdings, $r_count) { * Set rows in table for given holdings. * * @param $holdings - * Holding information for a given material + * Holding information for a given material + * * @return array; */ function _alma_set_rows($holdings) { @@ -213,16 +216,16 @@ function _alma_set_rows($holdings) { $row['placement'] = implode(' > ', $row['placement']); - $row['copies'] = isset($data['total_count']) ? (int)$data['total_count'] : 0; + $row['copies'] = isset($data['total_count']) ? (int) $data['total_count'] : 0; $copies_total += $row['copies']; - $row['home'] = isset($data['available_count']) ? (int)$data['available_count'] : 0; + $row['home'] = isset($data['available_count']) ? (int) $data['available_count'] : 0; $home_total += $row['home']; - $row['not_for_loan'] = isset($data['reference_count']) ? (int)$data['reference_count'] : 0; + $row['not_for_loan'] = isset($data['reference_count']) ? (int) $data['reference_count'] : 0; $not_for_loan_total += $row['not_for_loan']; - $row['checked_out'] = isset($data['checked_out_count']) ? (int)$data['checked_out_count'] : 0; + $row['checked_out'] = isset($data['checked_out_count']) ? (int) $data['checked_out_count'] : 0; $checked_out_total += $row['checked_out']; $rows[] = $row; @@ -231,7 +234,7 @@ function _alma_set_rows($holdings) { if (count($rows) >= 1) { $rows = _clean_up_rows($rows); } - // Adding row - totals + // Adding row - totals. $row = array(); $row['data']['Library'] = t('Total'); $row['data']['Copies'] = $copies_total; @@ -249,7 +252,7 @@ function _alma_set_rows($holdings) { * * @param array * - * @return array; + * @return array */ function _clean_up_rows($_rows) { $rows = array(); @@ -289,7 +292,7 @@ function _get_placements_with_key($_rows, $currkey) { * Sum material for same placement in one row. * * @param array $placementsarr - * All instances of the same placement - ie. 'Hovedbiblioteket' + * All instances of the same placement - ie. 'Hovedbiblioteket'. * * @return array $row */ @@ -331,7 +334,6 @@ function _sum_placement($placementsarr) { function _alma_populate_issues($input) { $org = alma_get_organisation(); $output = array(); - $placement = array(); $prev_hash = ''; // Numeric info about the issue. diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 99b08dc..92bb096 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -6,13 +6,17 @@ /** - * Creates form with which can be used during reservation to select preferred - * branch and interest period. + * Creates form which can be used during reservation. * - * @param type $type - * @param type $account - * @param type $reservables - * @return type + * It's used to select preferred branch and interest period. + * + * @param string $type + * @param stdClass $account + * @param array $reservables + * + * @return array + * Form element with the provider reservation options (branch and interest + * period). */ function alma_reservation_options($type, $account, $reservables) { $branches = alma_reservation_pickup_branches($account); @@ -46,6 +50,7 @@ function alma_reservation_options($type, $account, $reservables) { * @param type $account * @param type $reservables * @param type $values + * * @return type */ function alma_reservation_options_validate($type, $account, $reservables, $values) { From 4523c19c8a71fc4f924c1351676158f55088c495 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 10 Sep 2013 16:57:23 +0200 Subject: [PATCH 096/158] Removed legacy function "alma_reservation_set_preferred_branch" --- includes/alma.reservation.inc | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 92bb096..0008504 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -103,20 +103,6 @@ function alma_reservation_options_submit($type, $account, $reservables, $values) } } -/** - * Set preferred pickup branch. - * - * @param type $account - * @param type $branch - */ -function alma_reservation_set_preferred_branch($account, $branch) { - // Throws an exception if we are not logged in. - $creds = ding_user_get_creds($account); - - // Update preferred branch. - alma_client_invoke('get_reservations', $creds['name'], $creds['pass'], $branch); -} - /** * Get list of reserved items index by reservation type. * From 424ab346df2a76694e9dda51eab85886b20cf234 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 11 Sep 2013 08:21:39 +0200 Subject: [PATCH 097/158] Added a litter more documentation to the reservation part of the code --- alma.module | 9 ++++- includes/alma.reservation.inc | 69 ++++++++++++++++++++++++----------- 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/alma.module b/alma.module index 7486610..63a7568 100644 --- a/alma.module +++ b/alma.module @@ -30,10 +30,17 @@ function alma_reservation_pickup_branches($account = NULL) { /** * Get a list of allowed interest periods. + * + * The values are extracted from the interest period field in the provider + * profile2 user profile. + * + * @return array + * Array with the allowed interest period values. */ function alma_get_interest_periods() { + // Get the interest period profile fields allowed values. $field_info = field_info_field('field_alma_interest_period'); - $interest_periods = isset($field_info['settings']['allowed_values']) ? $field_info['settings']['allowed_values'] : FALSE; + $interest_periods = isset($field_info['settings']['allowed_values']) ? $field_info['settings']['allowed_values'] : array(); return $interest_periods; } diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 0008504..045e1dc 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -11,8 +11,11 @@ * It's used to select preferred branch and interest period. * * @param string $type + * String used to indicate the type of operation ('create'). * @param stdClass $account + * Drupal user account object. * @param array $reservables + * Unknown parameter (@todo what is this used for?). * * @return array * Form element with the provider reservation options (branch and interest @@ -46,12 +49,17 @@ function alma_reservation_options($type, $account, $reservables) { /** * Validate reservations options. * - * @param type $type - * @param type $account - * @param type $reservables - * @param type $values + * @param string $type + * String used to indicate the type of operation ('create'). + * @param stdClass $account + * Drupal user account object. + * @param array $reservables + * Unknown parameter (@todo what is this used for?). + * @param array $values + * The values that should be validated. * - * @return type + * @return array + * The valid reservation options (@todo needs better description). */ function alma_reservation_options_validate($type, $account, $reservables, $values) { // Load profile2 profile. @@ -64,7 +72,7 @@ function alma_reservation_options_validate($type, $account, $reservables, $value $preferred_branch = $wrapper->field_alma_preferred_branch->value();; $interest_period = $wrapper->field_alma_interest_period->value(); - // Perform a check to whether a show specific select dropdown. + // Perform a check to whether to show a specific select drop down. // Returning NULL means to skip this check, therefore to reserve instantly. if (!empty($$preferred_branch) && !empty($interest_period) && $type == 'create') { return array( @@ -75,6 +83,7 @@ function alma_reservation_options_validate($type, $account, $reservables, $value else { $branch_valid = ding_reservation_default_options_branch_validate($type, 'alma_preferred_branch', $preferred_branch, $values); $period_valid = ding_reservation_default_options_interest_period_validate($type, 'interest_period', $interest_period, $values); + return array_merge($branch_valid, $period_valid); } } @@ -82,10 +91,14 @@ function alma_reservation_options_validate($type, $account, $reservables, $value /** * Submit handler for reservations options. * - * @param type $type - * @param type $account - * @param type $reservables - * @param type $values + * @param string $type + * String used to indicate the type of operation ('create'). + * @param stdClass $account + * Drupal user account object. + * @param array $reservables + * Unknown parameter (@todo what is this used for?). + * @param array $values + * The values that should be submitted (@todo needs better description). */ function alma_reservation_options_submit($type, $account, $reservables, $values) { // Load profile2 profile. @@ -106,10 +119,18 @@ function alma_reservation_options_submit($type, $account, $reservables, $values) /** * Get list of reserved items index by reservation type. * - * @param type $account - * @return object DingProviderReservation + * @param stdClass $account + * Drupal user account object. + * @param string $type + * Reservation type to return. The sting should be one of 'ready_for_pickup', + * 'not_ready_for_pickup' or 'interlibrary_loans'. + * + * @return array + * An empty array or an array of DingProviderReservation objects. */ function alma_reservation_list($account, $type = NULL) { + // Use a static cache to speed up the process of getting reservations from + // alma, when call more than once in a single HTTP request. $result = &drupal_static(__FUNCTION__); if (!isset($result)) { // Check if ding_session_cache is available. @@ -117,16 +138,19 @@ function alma_reservation_list($account, $type = NULL) { $result = ding_session_cache_get('alma', 'reservations'); } - // If both static cache and session cache faild, try reloading information + // If both static cache and session cache failed, try reloading information // from alma. if (empty($result)) { - $reservations = alma_reservation_get_reservations($account); + // Set default reservation types. $result = array( 'ready_for_pickup' => array(), 'not_ready_for_pickup' => array(), 'interlibrary_loans' => array(), ); + // Get reservations from ALMA for the current account. + $reservations = alma_reservation_get_reservations($account); + // Create DingProviderReservation objects into three categories. foreach ($reservations as $reservation) { // Build standard array which matches all types of reservations. @@ -156,7 +180,8 @@ function alma_reservation_list($account, $type = NULL) { $result['ready_for_pickup'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data); } elseif ($reservation['id'] < 0) { - // Interlibrary loan reservations have negative IDs (undocumented Axiell "feature"). + // Inter-library loan reservations have negative IDs (undocumented + // Axiell "feature"). $data['ill_status'] = TRUE; // Create reservation object. @@ -189,13 +214,15 @@ function alma_reservation_list($account, $type = NULL) { } /** - * Create a reservation for a given account. + * Create a new reservation in the library system. + * + * @param stdClass $account + * @param string $id + * @param array $options + * @param string $expiry + * + * @return array * - * @param type $account - * @param type $id - * @param type $options - * @param type $expiry - * @return type * @throws DingProviderReservationExists * @throws DingProviderReservationNotAllowed * @throws DingProviderReservationNotAvailable From e742f5a4eb436062c39e24308f05afa454a3b480 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 11 Sep 2013 08:29:19 +0200 Subject: [PATCH 098/158] Added even more function documentation to the reservation code --- includes/alma.reservation.inc | 63 ++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 045e1dc..aa8ca2c 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -4,7 +4,6 @@ * Handles reservation with Alma. */ - /** * Creates form which can be used during reservation. * @@ -302,11 +301,11 @@ function alma_reservation_create($account, $id, $options = array(), $expiry = NU /** * Update order, by defining new expiry date or pickup branch. * - * @param object $account + * @param stdClass $account * @param array $ids * @param array $options * - * @return boolean + * @return bool */ function alma_reservation_update($account, $ids, $options) { $creds = ding_user_get_creds($account); @@ -339,8 +338,9 @@ function alma_reservation_update($account, $ids, $options) { /** * Delete a reservation for a given account. * - * @param type $account - * @param type $id + * @param stdClass $account + * @param string $id + * * @return type */ function alma_reservation_delete($account, $id) { @@ -348,22 +348,23 @@ function alma_reservation_delete($account, $id) { $reservations = alma_reservation_get_reservations($account); alma_reservation_clear_cache(); - if (isset($reservations[(string)$id])) { - return alma_client_invoke('remove_reservation', $creds['name'], $creds['pass'], $reservations[(string)$id]); + if (isset($reservations[(string) $id])) { + return alma_client_invoke('remove_reservation', $creds['name'], $creds['pass'], $reservations[(string) $id]); } } /** * Implements hook_default_interest_period(). * - * Tries to find the users default interst period based on the users profile2 + * Tries to find the users default interest period based on the users profile2 * provider profile. * * @param object $profile - * The users profile2 provider profile. + * The users profile2 provider profile. + * * @return string - * The default interest period selected by the user in his/her profile or the - * default value selected by the site. + * The default interest period selected by the user in his/her profile or the + * default value selected by the site. */ function alma_reservation_default_interest_period($profile = NULL) { // If profile is not given, try loading it for the user. @@ -390,7 +391,7 @@ function alma_reservation_default_interest_period($profile = NULL) { * Check where reservation deletion have been enabled in the providers settings. * * @return bool - * If enabled TRUE else FALSE. + * If enabled TRUE else FALSE. */ function alma_reservation_reservation_deletion_enabled() { return variable_get('alma_enable_reservation_deletion', FALSE); @@ -399,8 +400,11 @@ function alma_reservation_reservation_deletion_enabled() { /** * Return a branch name for a given branch id. * - * @param $branch_id String - * @return String + * @param string $branch_id + * The identifier for a given pick-up branch (e.g. hb) + * + * @return string + * The human name for the id or NULL if one do not exist. */ function alma_reservation_branch_name($branch_id) { // Get library organization from alma. @@ -415,12 +419,14 @@ function alma_reservation_branch_name($branch_id) { /** * Get all reservation from Alma and store them in the cache. * - * @param object $account - * User account object. + * @param stdClass $account + * Drupal user account object. + * * @param bool $reset - * If TRUE the cache will be by-passed. + * If TRUE the cache will be by-passed. + * * @return mixed - * Alma reservations. + * Alma reservations. */ function alma_reservation_get_reservations($account, $reset = FALSE) { $creds = ding_user_get_creds($account); @@ -441,16 +447,20 @@ function alma_reservation_clear_cache() { } /** - * @TODO: add description. + * Check if a reservation exists at the provider (ALMA). * - * @param type $account - * @param type $item_id - * @return boolean + * @param stdClass $account + * Drupal user account object. + * @param string $reservation_id + * The id of the reservation to test for. + * + * @return bool + * TRUE if the reservation exists else FALSE. */ -function alma_reservation_exists($account, $item_id) { +function alma_reservation_exists($account, $reservation_id) { $reservations = alma_reservation_get_reservations($account); foreach ($reservations as $res) { - if ($res['record_id'] == $item_id) { + if ($res['record_id'] == $reservation_id) { return TRUE; } } @@ -461,9 +471,10 @@ function alma_reservation_exists($account, $item_id) { * Helper function calculate the date in the feature base on interest period. * * @param int $expiry - * The number of seconds into the feature we need at date. + * The number of seconds into the feature we need at date. + * * @return string - * The date in the feature in the format 'Y-m-d' (ALMA_DATE). + * The date in the feature in the format 'Y-m-d' (ALMA_DATE). */ function alma_reservation_format_date($expiry) { return date(ALMA_DATE, $expiry); From 31505df89e3700298fdf06e2228fd4fc14c0cb32 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 11 Sep 2013 16:25:42 +0200 Subject: [PATCH 099/158] Reworked the reserve process to handle better branch seletion and better user interface --- alma.module | 6 ++-- includes/alma.reservation.inc | 56 +++++++++++------------------------ 2 files changed, 21 insertions(+), 41 deletions(-) diff --git a/alma.module b/alma.module index 63a7568..ec5a99c 100644 --- a/alma.module +++ b/alma.module @@ -13,7 +13,7 @@ define('ALMA_DATE_LONG', 'Y-m-d m:i:s'); /** * Get list of pickup branches. */ -function alma_reservation_pickup_branches($account = NULL) { +function alma_reservation_pickup_branches() { // Cache alma pickup branches - they are not likely to change. static $alma_pickup_branches; if (!isset($alma_pickup_branches)) { @@ -533,8 +533,8 @@ function alma_get_patron($creds = NULL, $reset = FALSE, $as_array = FALSE) { 'postal' => isset($info['addresses'][0]) ? $info['addresses'][0]['postal_code'] : '', 'city' => isset($info['addresses'][0]) ? $info['addresses'][0]['city'] : '', 'mobiles' => isset($info['phones']) ? $info['phones'] : '', - 'branch' => $info['preferences']['patron_branch'], - 'branchName' => $organisation['branch'][$info['preferences']['patron_branch']], + 'branch' => empty($info['preferences']['patron_branch']) ? FALSE : $info['preferences']['patron_branch'], + 'branchName' => !empty($info['preferences']['patron_branch']) ? $organisation['branch'][$info['preferences']['patron_branch']] : FALSE, 'absentPeriods' => isset($info['absent_periods']) ? $info['absent_periods'] : '', ); diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index aa8ca2c..ab0062e 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -9,19 +9,15 @@ * * It's used to select preferred branch and interest period. * - * @param string $type - * String used to indicate the type of operation ('create'). * @param stdClass $account * Drupal user account object. - * @param array $reservables - * Unknown parameter (@todo what is this used for?). * * @return array * Form element with the provider reservation options (branch and interest * period). */ -function alma_reservation_options($type, $account, $reservables) { - $branches = alma_reservation_pickup_branches($account); +function alma_reservation_options($account) { + $branches = alma_reservation_pickup_branches(); $periods = alma_get_interest_periods(); $preferred_branch = NULL; @@ -39,8 +35,8 @@ function alma_reservation_options($type, $account, $reservables) { } $form = array(); - $form += ding_reservation_default_options_branch($type, 'alma_preferred_branch', $preferred_branch, $branches); - $form += ding_reservation_interest_period_selector($type, 'interest_period', $interest_period, $periods); + $form += ding_reservation_default_options_branch('alma_preferred_branch', $preferred_branch, $branches); + $form += ding_reservation_interest_period_selector('interest_period', $interest_period, $periods); return $form; } @@ -48,19 +44,13 @@ function alma_reservation_options($type, $account, $reservables) { /** * Validate reservations options. * - * @param string $type - * String used to indicate the type of operation ('create'). * @param stdClass $account * Drupal user account object. - * @param array $reservables - * Unknown parameter (@todo what is this used for?). - * @param array $values - * The values that should be validated. * * @return array - * The valid reservation options (@todo needs better description). + * The interest period and default pick-up branch from the provider profile. */ -function alma_reservation_options_validate($type, $account, $reservables, $values) { +function alma_reservation_default_options($account) { // Load profile2 profile. $profile = ding_user_provider_profile($account); @@ -71,35 +61,23 @@ function alma_reservation_options_validate($type, $account, $reservables, $value $preferred_branch = $wrapper->field_alma_preferred_branch->value();; $interest_period = $wrapper->field_alma_interest_period->value(); - // Perform a check to whether to show a specific select drop down. - // Returning NULL means to skip this check, therefore to reserve instantly. - if (!empty($$preferred_branch) && !empty($interest_period) && $type == 'create') { - return array( - 'alma_preferred_branch' => $$preferred_branch, - 'interest_period' => $interest_period, - ); - } - else { - $branch_valid = ding_reservation_default_options_branch_validate($type, 'alma_preferred_branch', $preferred_branch, $values); - $period_valid = ding_reservation_default_options_interest_period_validate($type, 'interest_period', $interest_period, $values); + $result = array( + 'alma_preferred_branch' => $preferred_branch, + 'interest_period' => $interest_period, + ); - return array_merge($branch_valid, $period_valid); - } + return $result; } /** * Submit handler for reservations options. * - * @param string $type - * String used to indicate the type of operation ('create'). * @param stdClass $account * Drupal user account object. - * @param array $reservables - * Unknown parameter (@todo what is this used for?). * @param array $values * The values that should be submitted (@todo needs better description). */ -function alma_reservation_options_submit($type, $account, $reservables, $values) { +function alma_reservation_options_submit($account, $values) { // Load profile2 profile. $profile = ding_user_provider_profile($account); @@ -107,11 +85,13 @@ function alma_reservation_options_submit($type, $account, $reservables, $values) $wrapper = entity_metadata_wrapper('profile2', $profile); // Get values. - $preferred_branch = $wrapper->field_alma_preferred_branch->value();; + $preferred_branch = $wrapper->field_alma_preferred_branch->value(); - $update = ding_reservation_default_options_branch_submit($type, 'alma_preferred_branch', $preferred_branch, $values); - if (!empty($update['alma_preferred_branch'])) { - $wrapper->field_alma_preferred_branch->set($update['alma_preferred_branch']); + // If default branch was not found in the profile, update the profile with the + // one selected. + if ($preferred_branch) { + $wrapper->field_alma_preferred_branch->set($values['alma_preferred_branch']); + $profile->save(); } } From 85dd41787bd65201930aa967414584150d72f923 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 11 Sep 2013 16:36:54 +0200 Subject: [PATCH 100/158] Fixed logic in reservation options submit --- includes/alma.reservation.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index ab0062e..9972c32 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -89,7 +89,7 @@ function alma_reservation_options_submit($account, $values) { // If default branch was not found in the profile, update the profile with the // one selected. - if ($preferred_branch) { + if (!$preferred_branch) { $wrapper->field_alma_preferred_branch->set($values['alma_preferred_branch']); $profile->save(); } From f81635a53ad50a194e242815d4db878dd3ab53e0 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 11 Sep 2013 17:28:56 +0200 Subject: [PATCH 101/158] Added default_value to override provider options defaults --- includes/alma.reservation.inc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 9972c32..e30cd51 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -11,12 +11,14 @@ * * @param stdClass $account * Drupal user account object. + * @param string $default_value + * The name of the branch that should be selected as default value. * * @return array * Form element with the provider reservation options (branch and interest * period). */ -function alma_reservation_options($account) { +function alma_reservation_options($account, $default_value = '') { $branches = alma_reservation_pickup_branches(); $periods = alma_get_interest_periods(); @@ -34,8 +36,14 @@ function alma_reservation_options($account) { $interest_period = $wrapper->field_alma_interest_period->value(); } + // Set default value in the selection box if given else use preferred_branch. + $default = $preferred_branch; + if (!empty($default_value)) { + $default = $default_value; + } + $form = array(); - $form += ding_reservation_default_options_branch('alma_preferred_branch', $preferred_branch, $branches); + $form += ding_reservation_default_options_branch('alma_preferred_branch', $default, $branches); $form += ding_reservation_interest_period_selector('interest_period', $interest_period, $periods); return $form; From 9a16c78359853c4e0257729c95a0f3bfde7c0187 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 12 Sep 2013 14:26:49 +0200 Subject: [PATCH 102/158] Updated coding style in alma.loan.inc --- includes/alma.loan.inc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index 5f35109..3ab9b93 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -9,7 +9,6 @@ * * This functions finds all loans for a given user account and returns the loans * as DingProviderLoan objects. - * */ function alma_loan_list($account, $reset = FALSE) { // Get creds is outside cache function as it may throw exception if the user @@ -23,12 +22,12 @@ function alma_loan_list($account, $reset = FALSE) { $results = ding_session_cache_get('alma', 'loans'); } - // If both static cache and session cache faild, try reloading information + // If both static cache and session cache failed, try reloading information // from alma. if (empty($results) || $reset) { try { // Get all loans form alma for the user account given. - $loans = alma_client_invoke('get_loans', $creds['name'], $creds['pass']); + $loans = alma_client_invoke('get_loans', $creds['name'], $creds['pass']); } catch (Exception $e) { throw new DingProviderLoanUserError($e->getMessage()); @@ -76,9 +75,6 @@ function alma_loan_renew($account, $ids) { } } else { - /** - * @todo there are message saying why, the renew failed. - */ $result[$id] = DingProviderLoan::STATUS_NOT_RENEWED; } } @@ -87,12 +83,15 @@ function alma_loan_renew($account, $ids) { } /** - * Replace entity for the reservation in the case object in not in Ting anymore - * or the reservation is an remote reservation. + * Replace entity for the reservation. + * + * Should be used in the case object in not in Ting anymore or the reservation + * is an remote reservation. * - * @param $ting_entity + * @param object $ting_entity * Provider reservation object. - * @return + * + * @return object * Ting entity object, filled with data from provider service. */ function alma_loan_populate_pseudo_entity($ting_entity) { From 30b4d969fab6b9499ed57d2ac5e5eece829bfe59 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 12 Sep 2013 16:17:22 +0200 Subject: [PATCH 103/158] Added translation of ALMA fee types in to english text strings --- alma.module | 12 ++++-- includes/alma.debt.inc | 85 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 4 deletions(-) diff --git a/alma.module b/alma.module index ec5a99c..51f29ca 100644 --- a/alma.module +++ b/alma.module @@ -158,7 +158,8 @@ function alma_client() { */ function alma_client_invoke($method) { $args = func_get_args(); - array_shift($args); // Lose the method. + // Lose the method. + array_shift($args); $client = alma_client(); try { @@ -179,7 +180,7 @@ function alma_client_invoke($method) { * information is cache until the cache is cleared or the reset parameter is * TRUE. * - * @param boolean $reset + * @param bool $reset * Optional. If TRUE reset the cached data and reload. * * @return array @@ -226,7 +227,7 @@ function alma_get_organisation($reset = FALSE) { * Available information about the patron from Alma. */ function _alma_user_info($creds = NULL) { - // Get patron informations from Alma. + // Get patron information from Alma. $status = alma_get_patron($creds); // Build basic information array, with patron information. @@ -504,8 +505,11 @@ function alma_update_provider($changes, $entity) { * * @param array $creds * Array with 'name' and 'pass' keys, used to authenticate user with Alma. - * @param boolean $reset + * @param bool $reset * Reset static caching for this function. + * @param bool $as_array + * Return the patron information as an array. + * * @return stdClass * Patron object. */ diff --git a/includes/alma.debt.inc b/includes/alma.debt.inc index ea9ff1e..bdb3383 100644 --- a/includes/alma.debt.inc +++ b/includes/alma.debt.inc @@ -32,6 +32,9 @@ function alma_debt_list($account, $reset = FALSE) { $debt['display_name'] = $matchs[2]; $debt['material_number'] = $matchs[1]; + // Translate the fee type code into an text string. + $debt['type'] = alma_debt_translate_debt_type($debt['type']); + $debt_object = new DingProviderDebt($debt['id'], $debt); $result[$debt['id']] = $debt_object; } @@ -57,3 +60,85 @@ function alma_debt_payment_received($amount, $debt_ids = array(), $order_id = NU // Return result from Alma. return alma_client_invoke('add_payment', implode(',', $debt_ids), $order_id); } + +/** + * Translate alma debt types into an human readable string in english. + * + * @param string $debt_type + * The ALMA debt type. + * + * @return string + * English translation of the debt type. It has been + */ +function alma_debt_translate_debt_type($debt_type) { + // If translation is not found, return the type. So set it as default. + $str = t($debt_type); + + switch ($debt_type) { + case 'overdueFeeInvoiceDebt': + $str = 'Overdue fee invoice'; + break; + + case 'overdueFeeDebt': + $str = 'Overdue fee'; + break; + + case 'loanFeeDebt': + $str = 'Loan fee'; + break; + + case 'reservationPickupFeeDebt': + $str = 'Reservation pick-up fee'; + break; + + case 'reservationFeeDebt': + $str = 'Reservation fee'; + break; + + case 'deleteReservationFeeDebt': + $str = 'Delete reservation fee'; + break; + + case 'illFeeDebt': + $str = 'Interlibrary fee'; + break; + + case 'smsReservationFeeDebt': + $str = 'SMS reservation fee'; + break; + + case 'smsReminderFeeDebt': + $str = 'SMS reminder fee'; + break; + + case 'smsRecall1FeeDebt': + $str = 'SMS first recall fee'; + break; + + case 'smsRecall2FeeDebt': + $str = 'SMS second recall fee'; + break; + + case 'smsRecall3FeeDebt': + $str = 'SMS third recall fee'; + break; + + case 'smsRecall4FeeDebt': + $str = 'SMS fourth recall fee'; + break; + + case 'smsRecall5FeeDebt': + $str = 'SMS fifth recall fee'; + break; + + case 'emailReminderFeeDebt': + $str = 'E-mail reminder fee'; + break; + + case 'otherFeeDebt': + $str = 'Unknown or other fee'; + break; + }; + + return t($str); +} From a55968c21bd5a39478389e248c24bf9615c55e59 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 20 Sep 2013 11:38:35 +0200 Subject: [PATCH 104/158] Added inter-library status to ready-for-pickup --- includes/alma.reservation.inc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index e30cd51..078d20b 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -163,6 +163,13 @@ function alma_reservation_list($account, $type = NULL) { $data['pickup_date'] = $reservation['pickup_expire_date']; $data['ready_for_pickup'] = TRUE; + // Ready for pick-up can also be a inter-library loan. + if ($reservation['id'] < 0) { + // Inter-library loan reservations have negative IDs (undocumented + // Axiell "feature"). + $data['ill_status'] = TRUE; + } + // Create reservation object. $result['ready_for_pickup'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data); } From 0436c94815663f98554b04fef41af1f5ceb5fb55 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 7 Oct 2013 10:10:37 +0200 Subject: [PATCH 105/158] Fixed default interest period selector in the administration interface --- alma.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alma.module b/alma.module index 51f29ca..2746632 100644 --- a/alma.module +++ b/alma.module @@ -106,7 +106,7 @@ function alma_settings_form() { // this during reservation. $periods = alma_get_interest_periods(); $default = variable_get('alma_default_interest_period', 180); - $form['alma'] += ding_reservation_interest_period_selector('', 'alma_default_interest_period', $default, $periods); + $form['alma'] += ding_reservation_interest_period_selector('alma_default_interest_period', $default, $periods); $form['alma']['alma_enable_reservation_deletion'] = array( '#type' => 'checkbox', From 3ed9c02f997990cc7a6ccd65131ee16d93e9c544 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 8 Oct 2013 15:48:00 +0200 Subject: [PATCH 106/158] Added missing clear cache that is called after dibs payment is accepted --- includes/alma.user.inc | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/includes/alma.user.inc b/includes/alma.user.inc index 4700a34..d1f7738 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -4,12 +4,11 @@ * Handles user authentication with the alma provider. */ - /** * Implements hook_user_authenticate(). * - * @param $name - * @param $pass + * @param string $uid + * @param string $pass */ function alma_user_authenticate($uid, $pass) { $return = array( @@ -65,8 +64,11 @@ function alma_user_authenticate($uid, $pass) { /** * Check if the user creds is set correctly. * - * @param type $creds - * @return type + * @param array $creds + * Array with the user credentials. + * + * @return bool + * TRUE if user is authenticated else FALSE */ function alma_user_is_authenticated($creds) { return (isset($creds['name']) && isset($creds['pass'])); @@ -83,11 +85,12 @@ function alma_user_profile_form_validate($form, $form_state) { * Update pin code at alma. * * @param object $account - * User account object or the user provider profile2. + * User account object or the user provider profile2. * @param string $new_pincode - * The users new pincode. + * The users new pin-code. + * * @return array - * Updated credential array. + * Updated credential array. */ function alma_user_update_pincode($account, $new_pincode) { $creds = ding_user_get_creds($account); @@ -106,4 +109,16 @@ function alma_user_update_pincode($account, $new_pincode) { return $result; } } -} \ No newline at end of file +} + +/** + * Implements clear_cache(). + * + * This hook is only called from ding_dibs after a payment have been accepted. + * + * @param stdClass $account + * Drupal user account object. + */ +function alma_user_clear_cache($account) { + // As the ALMA currently only uses a static cache for debt... do nothing. +} From 28526f52075d6bacd90587e27e7be32bb84f4c5f Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 8 Oct 2013 15:58:17 +0200 Subject: [PATCH 107/158] Display name in debts from alma is not always mat. no. and title --- includes/alma.debt.inc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/alma.debt.inc b/includes/alma.debt.inc index bdb3383..5bf93b8 100644 --- a/includes/alma.debt.inc +++ b/includes/alma.debt.inc @@ -29,8 +29,10 @@ function alma_debt_list($account, $reset = FALSE) { foreach ($debts['debts'] as $debt) { // Get the material number from the display name and remove it form it. preg_match('/^(\w+)\s+(.+)/', $debt['display_name'], $matchs); - $debt['display_name'] = $matchs[2]; - $debt['material_number'] = $matchs[1]; + if (count($matchs) == 3) { + $debt['display_name'] = $matchs[2]; + $debt['material_number'] = $matchs[1]; + } // Translate the fee type code into an text string. $debt['type'] = alma_debt_translate_debt_type($debt['type']); From d17c60ad21d2c36cb69130d231dfedf9280287bd Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 16 Oct 2013 09:24:13 +0200 Subject: [PATCH 108/158] Added cache expire to alma organisation information --- alma.module | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/alma.module b/alma.module index 2746632..7ef711f 100644 --- a/alma.module +++ b/alma.module @@ -13,16 +13,19 @@ define('ALMA_DATE_LONG', 'Y-m-d m:i:s'); /** * Get list of pickup branches. */ -function alma_reservation_pickup_branches() { +function alma_reservation_pickup_branches($reset = FALSE) { // Cache alma pickup branches - they are not likely to change. static $alma_pickup_branches; if (!isset($alma_pickup_branches)) { - if ($cache = cache_get('alma_pickup_branches')) { + $cache = cache_get('alma_pickup_branches'); + if (!$reset && $cache && $cache->expire > REQUEST_TIME) { $alma_pickup_branches = $cache->data; } else { $alma_pickup_branches = alma_client_invoke('get_reservation_branches'); - cache_set('alma_pickup_branches', $alma_pickup_branches, 'cache'); + + // Cache output for 24 hours. + cache_set('alma_pickup_branches', $alma_pickup_branches, 'cache', REQUEST_TIME + 86400); } } return $alma_pickup_branches; @@ -191,7 +194,8 @@ function alma_get_organisation($reset = FALSE) { // Return data from cache if available. static $organisation; if (!$organisation || $reset) { - if (($cache = cache_get('alma_organisation')) && !empty($cache->data) && !$reset) { + $cache = cache_get('alma_organisation'); + if (!$reset && $cache && isset($cache->data) && $cache->expire > REQUEST_TIME) { $organisation = $cache->data; } else { @@ -208,7 +212,7 @@ function alma_get_organisation($reset = FALSE) { if ($organisation['branch'] && $organisation['department'] && $organisation['location'] && $organisation['sublocation'] && $organisation['collection'] && $organisation['reservation']) { - cache_set('alma_organisation', $organisation, 'cache'); + cache_set('alma_organisation', $organisation, 'cache', REQUEST_TIME + 86400); } } } From 1c583300d6925480087a8eed3777db4656c2cd7c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Sun, 20 Oct 2013 15:19:30 +0200 Subject: [PATCH 109/158] Speeded up holdings on page reloads --- includes/alma.availability.inc | 89 ++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index b43da96..f114145 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -19,44 +19,59 @@ function alma_availability_items($provider_ids) { /** * Implements provider availability, holdings. */ -function alma_availability_holdings($provider_ids) { - $ids = implode(',', $provider_ids); - $details = alma_client_invoke('catalogue_record_detail', $ids); - $result = array(); - - if ($details && isset($details['records'])) { - foreach ($details['records'] as $alma_id => $record) { - $holding = array( - 'local_id' => $alma_id, - 'title' => $record['titles'][0], - 'available' => ($record['available_count'] > 0), - 'reservable' => $record['show_reservation_button'], - 'show_reservation_button' => $record['show_reservation_button'], - 'holdings' => $record['holdings'], - 'reserved_count' => (int) $record['reservation_count'], - 'deferred_period' => FALSE, - 'issues' => FALSE, - 'is_periodical' => ($record['media_class'] == 'periodical'), - 'is_internet' => ($record['media_class'] == 'internet'), - ); - - // If periodical render issue information. - if ($holding['is_periodical']) { - $holding['issues'] = _alma_populate_issues($record['holdings']); - } +function alma_availability_holdings($provider_ids, $reset = FALSE) { + // Create cache id. + $cid = md5(serialize($provider_ids)); + + // Check the check to speed up the process, it's only cached for 10 min. to + // ensure freshness. + $cache = cache_get($cid, 'cache'); + if (!$reset && $cache && $cache->expire > REQUEST_TIME) { + $result = $cache->data; + } + else { + $ids = implode(',', $provider_ids); + $details = alma_client_invoke('catalogue_record_detail', $ids); + $result = array(); - // If it's an internet holding, don't display holdings information. - if ($holding['is_internet']) { - $holding['holdings'] = FALSE; - } + if ($details && isset($details['records'])) { + foreach ($details['records'] as $alma_id => $record) { + $holding = array( + 'local_id' => $alma_id, + 'title' => $record['titles'][0], + 'available' => ($record['available_count'] > 0), + 'reservable' => $record['show_reservation_button'], + 'show_reservation_button' => $record['show_reservation_button'], + 'holdings' => $record['holdings'], + 'reserved_count' => (int) $record['reservation_count'], + 'deferred_period' => FALSE, + 'issues' => FALSE, + 'is_periodical' => ($record['media_class'] == 'periodical'), + 'is_internet' => ($record['media_class'] == 'internet'), + ); + + // If periodical render issue information. + if ($holding['is_periodical']) { + $holding['issues'] = _alma_populate_issues($record['holdings']); + } + + // If it's an internet holding, don't display holdings information. + if ($holding['is_internet']) { + $holding['holdings'] = FALSE; + } + + $result[$alma_id] = $holding; - $result[$alma_id] = $holding; + $result[$alma_id]['html'] = _alma_get_holdings($details, $holding['is_periodical']); + } - $result[$alma_id]['html'] = _alma_get_holdings($details, $holding['is_periodical']); + // Cache the result for 10 min. This will speed up materials with many + // copies and loans. + cache_set($cid, $result, 'cache', REQUEST_TIME + 600); } } - return $result; + return $result; } /** @@ -143,7 +158,7 @@ function _alma_set_table_html($holdings, $r_count) { // Set a classname for styling the table. $variables['attributes'] = array( 'class' => array( - drupal_html_class('availability_holdings_table') + drupal_html_class('availability_holdings_table'), ), ); @@ -336,14 +351,6 @@ function _alma_populate_issues($input) { $output = array(); $prev_hash = ''; - // Numeric info about the issue. - $ordered_count = 0; - $checked_out_count = 0; - $reference_count = 0; - $total_count = 0; - $available_count = 0; - - $i = -1; // Loop through volumes. foreach ($input as $year => $volume) { // Loop through issues. From 2a89e681157672e7f6b54475e0817b3cb4ff1bb0 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Sun, 20 Oct 2013 15:47:01 +0200 Subject: [PATCH 110/158] Added a total count to the holdings information --- includes/alma.availability.inc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index f114145..13f6344 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -60,8 +60,12 @@ function alma_availability_holdings($provider_ids, $reset = FALSE) { $holding['holdings'] = FALSE; } + // Count total materials. + $holding['total_count'] = _alma_holdings_total_count($holding['holdings']); + $result[$alma_id] = $holding; + // Generate holdings as HTML. @todo: this really need to be changed. $result[$alma_id]['html'] = _alma_get_holdings($details, $holding['is_periodical']); } @@ -74,6 +78,21 @@ function alma_availability_holdings($provider_ids, $reset = FALSE) { return $result; } +/** + * Summeries total number of materials from holdings information. + * + * @param array $holdings + * Holdings information return form alma. + */ +function _alma_holdings_total_count($holdings) { + $total = 0; + foreach ($holdings as $holding) { + $total += (int) $holding['total_count']; + } + + return $total; +} + /** * Get holdings base information from alma and base on if it's a periodical or * not. From 31b691059a50a6212d561e08008dd8ea856bd760 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 22 Oct 2013 19:11:40 +0200 Subject: [PATCH 111/158] Ensured that total_count key exists in alma responce --- includes/alma.availability.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index 13f6344..69e2bf4 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -87,7 +87,9 @@ function alma_availability_holdings($provider_ids, $reset = FALSE) { function _alma_holdings_total_count($holdings) { $total = 0; foreach ($holdings as $holding) { - $total += (int) $holding['total_count']; + if (isset($holding['total_count'])) { + $total += (int) $holding['total_count']; + } } return $total; From 927c07b8f7ca54c2e457dacc2a0792a53eeea6da Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 30 Oct 2013 18:10:13 +0100 Subject: [PATCH 112/158] Removed HTML holdings table generation - moved to ding availability --- includes/alma.availability.inc | 295 +++++---------------------------- 1 file changed, 38 insertions(+), 257 deletions(-) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index 69e2bf4..de5363a 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -60,13 +60,39 @@ function alma_availability_holdings($provider_ids, $reset = FALSE) { $holding['holdings'] = FALSE; } + // Get pretty location name (placement) as an array. + if (isset($holding['holdings'])) { + $org = alma_get_organisation(); + foreach ($holding['holdings'] as $index => $data) { + $holding['holdings'][$index]['placement'] = array(); + + if (!empty($data['branch_id'])) { + $holding['holdings'][$index]['placement'][] = $org['branch'][$data['branch_id']]; + } + + if (!empty($data['department_id'])) { + $holding['holdings'][$index]['placement'][] = $org['department'][$data['department_id']]; + } + + if (!empty($data['location_id'])) { + $holding['holdings'][$index]['placement'][] = $org['location'][$data['location_id']]; + } + + if (!empty($data['sublocation_id'])) { + $holding['holdings'][$index]['placement'][] = $org['sublocation'][$data['sublocation_id']]; + } + + if (!empty($data['shelf_mark'])) { + $holding['holdings'][$index]['placement'][] = $data['shelf_mark']; + } + } + } + // Count total materials. $holding['total_count'] = _alma_holdings_total_count($holding['holdings']); + // Set holdings. $result[$alma_id] = $holding; - - // Generate holdings as HTML. @todo: this really need to be changed. - $result[$alma_id]['html'] = _alma_get_holdings($details, $holding['is_periodical']); } // Cache the result for 10 min. This will speed up materials with many @@ -79,10 +105,13 @@ function alma_availability_holdings($provider_ids, $reset = FALSE) { } /** - * Summeries total number of materials from holdings information. + * Sums the total number of materials from holdings information. * * @param array $holdings * Holdings information return form alma. + * + * @return int + * Total number of materials in the holding. */ function _alma_holdings_total_count($holdings) { $total = 0; @@ -95,264 +124,16 @@ function _alma_holdings_total_count($holdings) { return $total; } -/** - * Get holdings base information from alma and base on if it's a periodical or - * not. - * - * @todo: Rewrite this to have the provider create the holdings tables and not - * return HTML from inside the provides them self. - * - * @param array $res - * Returned array from alma_client class - * @param bool $is_periodical - * Indicates whether the shown record is a periodical or not - * - * @return string - * HTML to be shown or FALSE if no data is received from alma. - */ -function _alma_get_holdings($res, $is_periodical = FALSE) { - if (isset($res['records'])) { - if ($is_periodical) { - return _alma_set_holdings_periodical($res); - } - else { - return _alma_set_holdings($res); - } - } - else { - return FALSE; - } -} - -/** - * Set holdings for all kinds of material except periodicals. - * - * @param array $res - * - * @return array $result; - */ -function _alma_set_holdings($res) { - $holdings = array(); - $reservation_count = 0; - foreach ($res['records'] as $alma_id => $records) { - $reservation_count += (int) $records['reservation_count']; - foreach ($records['holdings'] as $holding) { - $holdings[] = $holding; - } - } - - $result = _alma_set_table_html($holdings, $reservation_count); - return $result; -} - -/** - * Set holdings if material is periodical only. - * - * @param array $res - * @return array $result - */ -function _alma_set_holdings_periodical($res) { - $holdings = array(); - $reservation_count = 0; - foreach ($res['records'] as $alma_id => $records) { - $reservation_count += (int) $records['reservation_count']; - foreach ($records['holdings'] as $holding => $issue_year) { - foreach ($issue_year as $key) { - $holdings[] = $key[0]; - } - } - } - - $result = _alma_set_table_html($holdings, $reservation_count); - return $result; -} - -/** - * Make the html-table. - * - * @param array $holding - * Holding information for a given material. - * - * @return html-table - */ -function _alma_set_table_html($holdings, $r_count) { - // Set a classname for styling the table. - $variables['attributes'] = array( - 'class' => array( - drupal_html_class('availability_holdings_table'), - ), - ); - - // Set table header. - $variables['header'] = array( - 'placement' => t('Placement'), - 'copies' => t('Copies'), - 'home' => t('At home'), - 'not_for_loan' => t('Not for loan'), - 'checked_out' => t('Checked out'), - ); - - // Set table rows. - $variables['rows'] = _alma_set_rows($holdings); - - // Set last row with reservation count. - $row = array(); - $row['data']['Library'] = t('Reservations'); - $row['data']['Copies'] = array('data' => $r_count, 'colspan' => 4); - $variables['rows'][] = $row; - - // Disable sticky headers. - $variables['sticky'] = FALSE; - - // Theme the table. - $html = theme('table', $variables); - - return $html; -} - -/** - * Set rows in table for given holdings. - * - * @param $holdings - * Holding information for a given material - * - * @return array; - */ -function _alma_set_rows($holdings) { - $rows = array(); - $org = alma_get_organisation(); - - $copies_total = 0; - $home_total = 0; - $not_for_loan_total = 0; - $checked_out_total = 0; - - foreach ($holdings as $key => $data) { - $row = array(); - - if (!empty($data['branch_id'])) { - $row['placement'][] = $org['branch'][$data['branch_id']]; - } - - if (!empty($data['department_id'])) { - $row['placement'][] = $org['department'][$data['department_id']]; - } - - if (!empty($data['location_id'])) { - $row['placement'][] = $org['location'][$data['location_id']]; - } - - if (!empty($data['sublocation_id'])) { - $row['placement'][] = $org['sublocation'][$data['sublocation_id']]; - } - - if (!empty($data['shelf_mark'])) { - $row['placement'][] = $data['shelf_mark']; - } - - $row['placement'] = implode(' > ', $row['placement']); - - $row['copies'] = isset($data['total_count']) ? (int) $data['total_count'] : 0; - $copies_total += $row['copies']; - - $row['home'] = isset($data['available_count']) ? (int) $data['available_count'] : 0; - $home_total += $row['home']; - - $row['not_for_loan'] = isset($data['reference_count']) ? (int) $data['reference_count'] : 0; - $not_for_loan_total += $row['not_for_loan']; - - $row['checked_out'] = isset($data['checked_out_count']) ? (int) $data['checked_out_count'] : 0; - $checked_out_total += $row['checked_out']; - - $rows[] = $row; - } - - if (count($rows) >= 1) { - $rows = _clean_up_rows($rows); - } - // Adding row - totals. - $row = array(); - $row['data']['Library'] = t('Total'); - $row['data']['Copies'] = $copies_total; - $row['data']['Home'] = $home_total; - $row['data']['Not for loan'] = $not_for_loan_total; - $row['data']['Checked out'] = $checked_out_total; - $row['class'] = array(drupal_html_class('availability_holdings_last_row')); - $rows[] = $row; - - return $rows; -} - -/** - * If the same placement exists several times collect them in one line. - * - * @param array - * - * @return array - */ -function _clean_up_rows($_rows) { - $rows = array(); - $placements = array(); - - foreach ($_rows as $row) { - $currkey = $row['placement']; - if (!in_array($currkey, $placements)) { - $placements[] = $currkey; - $placementsarr = _get_placements_with_key($_rows, $currkey); - $this_row = _sum_placement($placementsarr); - $rows[] = $this_row; - } - } - return $rows; -} - -/** - * Collect materials with the same placement. - * - * @param array $_rows - * @param String $currkey - * - * @return array $rows; - */ -function _get_placements_with_key($_rows, $currkey) { - $rows = array(); - foreach ($_rows as $key) { - if ($key['placement'] == $currkey) { - $rows[] = $key; - } - } - return $rows; -} - -/** - * Sum material for same placement in one row. - * - * @param array $placementsarr - * All instances of the same placement - ie. 'Hovedbiblioteket'. - * - * @return array $row - */ -function _sum_placement($placementsarr) { - $row = $placementsarr[0]; - for ($i = 1; $i < count($placementsarr); $i++) { - $next_row = $placementsarr[$i]; - $row['copies'] += $next_row['copies']; - $row['home'] += $next_row['home']; - $row['not_for_loan'] += $next_row['not_for_loan']; - $row['checked_out'] += $next_row['checked_out']; - } - return $row; -} - /** * Fill in the issues data, useful for periodical availability. * * This method takes into consideration the repeating placements, - * and aggregates them, suming the numeric data. + * and aggregates them, summing the numeric data. + * + * @param array $input + * Holdings data, as returned from the web-service. * - * @param $input - * Holdings data, as returned from the web-servce. - * @return + * @return array * An array, with the following keys: * - Issue year. * - Issue number. From e444526b164d3a5c799fe28993502c77ca417008 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 30 Oct 2013 22:35:56 +0100 Subject: [PATCH 113/158] Show periodicals reservation button based on showReservationButton --- includes/alma.availability.inc | 2 +- lib/AlmaClient/AlmaClient.class.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index de5363a..3351d3e 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -226,7 +226,7 @@ function _alma_populate_issues($input) { 'reference_count' => $reference_count, 'total_count' => $total_count, 'available_count' => $available_count, - 'reservable' => ($copy['status'] === 'availableForLoan') ? TRUE : FALSE, + 'reservable' => ($copy['show_reservation_button'] === 'yes') ? TRUE : FALSE, ); } } diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index 0b1c1dc..6fff6e6 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -717,13 +717,20 @@ private static function process_catalogue_record_details($elem) { if ($record['media_class'] != 'periodical') { $record['holdings'] = AlmaClient::process_catalogue_record_holdings($elem); } - // Periodicals are nested holdings, which we want to keep that way. else { + // Periodicals are nested holdings, which we want to keep that way. foreach ($elem->getElementsByTagName('compositeHoldings') as $holdings) { foreach ($holdings->childNodes as $year_holdings) { $year = $year_holdings->getAttribute('value'); foreach ($year_holdings->childNodes as $issue_holdings) { $issue = $issue_holdings->getAttribute('value'); + + // If this is a yearly publication it do not have issues. + if (empty($issue)) { + // So we set the issue to index as a single element. + $issue = 0; + } + $holdings = AlmaClient::process_catalogue_record_holdings($issue_holdings); $record['holdings'][$year][$issue] = $holdings; $issue_list = array( @@ -744,7 +751,6 @@ private static function process_catalogue_record_details($elem) { } } } - $record['issues'][$year][$issue] = $issue_list; } } @@ -764,6 +770,7 @@ private static function process_catalogue_record_holdings($elem) { $holdings[] = array( 'reservable' => $item->getAttribute('reservable'), 'status' => $item->getAttribute('status'), + 'show_reservation_button' => $item->getAttribute('showReservationButton'), 'ordered_count' => (int) $item->getAttribute('nofOrdered'), 'checked_out_count' => (int) $item->getAttribute('nofCheckedOut'), 'reference_count' => (int) $item->getAttribute('nofReference'), From a91abc3e9441a4252f9f1ee7b25147ff60b2f844 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 1 Nov 2013 12:39:20 +0100 Subject: [PATCH 114/158] Added collection to holdings data --- includes/alma.availability.inc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/alma.availability.inc b/includes/alma.availability.inc index 3351d3e..d194662 100644 --- a/includes/alma.availability.inc +++ b/includes/alma.availability.inc @@ -82,6 +82,10 @@ function alma_availability_holdings($provider_ids, $reset = FALSE) { $holding['holdings'][$index]['placement'][] = $org['sublocation'][$data['sublocation_id']]; } + if (!empty($data['collection_id'])) { + $holding['holdings'][$index]['placement'][] = $org['collection'][$data['collection_id']]; + } + if (!empty($data['shelf_mark'])) { $holding['holdings'][$index]['placement'][] = $data['shelf_mark']; } From 89f22a624c29aa8900576fcc082a88d0531df317 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 4 Nov 2013 21:20:45 +0100 Subject: [PATCH 115/158] Updated makefile to point to tag 7.x-1.0-beta2 --- alma.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alma.make b/alma.make index 17b4a6d..385ed18 100644 --- a/alma.make +++ b/alma.make @@ -23,9 +23,9 @@ projects[virtual_field][version] = "1.1" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][branch] = "development" +projects[ding_provider][download][tag] = "7.x-1.0-beta2" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" -projects[ding_reservation][download][branch] = "development" +projects[ding_reservation][download][tag] = "7.x-1.0-beta2" From 5f12f344b2f0d74fcab20191b747fc785df38ec4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 26 Nov 2013 12:44:59 +0100 Subject: [PATCH 116/158] Updated makefile to point to tag 7.x-1.0-beta3 --- alma.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alma.make b/alma.make index 385ed18..6ce063c 100644 --- a/alma.make +++ b/alma.make @@ -23,9 +23,9 @@ projects[virtual_field][version] = "1.1" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-beta2" +projects[ding_provider][download][tag] = "7.x-1.0-beta3" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" -projects[ding_reservation][download][tag] = "7.x-1.0-beta2" +projects[ding_reservation][download][tag] = "7.x-1.0-beta3" From 1a1212fd07ffe340ff2e5f1be81cadcabc704424 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 28 Nov 2013 12:52:10 +0100 Subject: [PATCH 117/158] Updated coding style --- alma.module | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/alma.module b/alma.module index 7ef711f..d8282e4 100644 --- a/alma.module +++ b/alma.module @@ -10,6 +10,8 @@ define('ALMA_AUTH_BLOCKED', '4e5531951f55ab8f6895684999c69c2'); define('ALMA_DATE', 'Y-m-d'); define('ALMA_DATE_LONG', 'Y-m-d m:i:s'); +include_once 'alma.features.inc'; + /** * Get list of pickup branches. */ @@ -153,7 +155,7 @@ function alma_client() { /** * Calls the Alma backend, possibly caching the result. * - * @param $method + * @param string $method * The desired method. * * @return array @@ -421,12 +423,12 @@ function alma_update_provider($changes, $entity) { } // Update reservation pause (absentPeriod). - if (!empty( $changes['absent_id']) && - !empty($changes['reservation_pause_start']) && - !empty($changes['reservation_pause_stop'])) { + if (!empty($changes['absent_id']) && + !empty($changes['reservation_pause_start']) && + !empty($changes['reservation_pause_stop'])) { try { - $res = alma_client_invoke('change_absent_period', $creds['name'], $creds['pass'], $changes['absent_id'], $changes['reservation_pause_start'], $changes['reservation_pause_stop']); + $res = alma_client_invoke('change_absent_period', $creds['name'], $creds['pass'], $changes['absent_id'], $changes['reservation_pause_start'], $changes['reservation_pause_stop']); } catch (Exception $exception) { watchdog_exception('Alma provider', $exception); @@ -643,6 +645,3 @@ function alma_ding_session_cache_defaults() { 'expire' => 3600, ); } - -// Include the feature code. -include_once 'alma.features.inc'; From 59b1b02b82c661c0dc444b0ce58d1d33737d238c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 2 Dec 2013 11:30:56 +0100 Subject: [PATCH 118/158] Added support for the new datawell 3 PIDs --- includes/alma.loan.inc | 2 +- includes/alma.reservation.inc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index 3ab9b93..dd57fed 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -36,7 +36,7 @@ function alma_loan_list($account, $reset = FALSE) { $results = array(); foreach ($loans as $loan) { $results[$loan['id']] = new DingProviderLoan($loan['id'], array( - 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $loan['record_id'], + 'ding_entity_id' => ding_provider_build_entity_id($loan['record_id']), 'loan_date' => $loan['loan_date'], 'expiry' => $loan['due_date'], 'renewable' => $loan['is_renewable'], diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 078d20b..74cf2b8 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -143,7 +143,7 @@ function alma_reservation_list($account, $type = NULL) { // Build standard array which matches all types of reservations. $data = array( 'order_id' => $reservation['id'], - 'ding_entity_id' => variable_get('ting_agency', '') . ':' . $reservation['record_id'], + 'ding_entity_id' => ding_provider_build_entity_id($reservation['record_id']), 'pickup_branch_id' => $reservation['pickup_branch'], 'order_arrived' => NULL, 'pickup_order_id' => NULL, From 5390dbc30ef02f0e9320a0b7caaa829725640565 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 3 Dec 2013 12:39:57 +0100 Subject: [PATCH 119/158] Removed extra function call on cache reset --- includes/alma.loan.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index 3ab9b93..0da4d6b 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -18,7 +18,7 @@ function alma_loan_list($account, $reset = FALSE) { $results = &drupal_static(__FUNCTION__, FALSE); if (!$results || $reset) { // Check if ding_session_cache is available. - if (module_exists('ding_session_cache')) { + if (module_exists('ding_session_cache') && !$reset) { $results = ding_session_cache_get('alma', 'loans'); } From 1498ced68cdde5ae188db794e0911bee657a2ad8 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 3 Dec 2013 21:58:52 +0100 Subject: [PATCH 120/158] Added reservation type to reservation to have more information in ding_reservation lists --- includes/alma.reservation.inc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 078d20b..e90fd4f 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -109,8 +109,9 @@ function alma_reservation_options_submit($account, $values) { * @param stdClass $account * Drupal user account object. * @param string $type - * Reservation type to return. The sting should be one of 'ready_for_pickup', - * 'not_ready_for_pickup' or 'interlibrary_loans'. + * Reservation type to return. The sting should be one of + * 'DING_RESERVATION_READY', 'DING_RESERVATION_NOT_READY' or + * 'DING_RESERVATION_INTERLIBRARY_LOANS'. * * @return array * An empty array or an array of DingProviderReservation objects. @@ -130,9 +131,9 @@ function alma_reservation_list($account, $type = NULL) { if (empty($result)) { // Set default reservation types. $result = array( - 'ready_for_pickup' => array(), - 'not_ready_for_pickup' => array(), - 'interlibrary_loans' => array(), + DING_RESERVATION_READY => array(), + DING_RESERVATION_NOT_READY => array(), + DING_RESERVATION_INTERLIBRARY_LOANS => array(), ); // Get reservations from ALMA for the current account. @@ -154,6 +155,7 @@ function alma_reservation_list($account, $type = NULL) { 'queue_number' => $reservation['queue_number'], 'ill_status' => FALSE, 'notes' => isset($reservation['notes']) ? $reservation['notes'] : '', + 'reservation_type' => DING_RESERVATION_NOT_READY, ); // If the reservation is ready for pick-up, we fill in that data. @@ -162,6 +164,7 @@ function alma_reservation_list($account, $type = NULL) { $data['pickup_order_id'] = $reservation['pickup_number']; $data['pickup_date'] = $reservation['pickup_expire_date']; $data['ready_for_pickup'] = TRUE; + $data['reservation_type'] = DING_RESERVATION_READY; // Ready for pick-up can also be a inter-library loan. if ($reservation['id'] < 0) { @@ -171,19 +174,20 @@ function alma_reservation_list($account, $type = NULL) { } // Create reservation object. - $result['ready_for_pickup'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data); + $result[DING_RESERVATION_READY][$reservation['id']] = new DingProviderReservation($reservation['id'], $data); } elseif ($reservation['id'] < 0) { // Inter-library loan reservations have negative IDs (undocumented // Axiell "feature"). $data['ill_status'] = TRUE; + $data['reservation_type'] = DING_RESERVATION_INTERLIBRARY_LOANS; // Create reservation object. - $result['interlibrary_loans'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data);; + $result[DING_RESERVATION_INTERLIBRARY_LOANS][$reservation['id']] = new DingProviderReservation($reservation['id'], $data); } else { // Default case with, so just create the reservation object. - $result['not_ready_for_pickup'][$reservation['id']] = new DingProviderReservation($reservation['id'], $data);; + $result[DING_RESERVATION_NOT_READY][$reservation['id']] = new DingProviderReservation($reservation['id'], $data); } } From 24881f073c7dd49be2dbf684cc5dc9de5c86ed82 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 10 Dec 2013 16:02:52 +0100 Subject: [PATCH 121/158] Added support for WAYF in alma --- alma.module | 4 ++++ includes/alma.wayf.inc | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 includes/alma.wayf.inc diff --git a/alma.module b/alma.module index d8282e4..b0a791d 100644 --- a/alma.module +++ b/alma.module @@ -80,6 +80,10 @@ function alma_ding_provider() { 'prefix' => 'user', 'file' => $path . '/includes/alma.user.inc', ), + 'wayf' => array( + 'prefix' => 'wayf', + 'file' => $path . '/includes/alma.wayf.inc', + ), ), ); } diff --git a/includes/alma.wayf.inc b/includes/alma.wayf.inc new file mode 100644 index 0000000..a057bc3 --- /dev/null +++ b/includes/alma.wayf.inc @@ -0,0 +1,42 @@ + $authentication_attributes['schacPersonalUniqueID'], + 'pass' => $hash, + ); + } + else { + // Set message that hash value was not found. + watchdog('alma', 'The WAYF hash value has not been set in setting.php as $conf[\'alma_wayf_hash\'] and WAYF login will fail', WATCHDOG_ERROR); + } + + return $credentials; +} + +/** + * Implements hook_wayf_attributes(). + * + * Used to define which attribute to use as login name. + */ +function alma_wayf_attributes() { + return array( + 'schacPersonalUniqueID' => array( + 'field' => 'CPR', + ), + ); +} From 0854e542f6a4d296ae98bc8d48343929a91fecab Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 12 Dec 2013 11:18:28 +0100 Subject: [PATCH 122/158] Removed version number from info file as it do not match release --- alma.info | 1 - 1 file changed, 1 deletion(-) diff --git a/alma.info b/alma.info index 9c63c75..4c69ca5 100644 --- a/alma.info +++ b/alma.info @@ -3,7 +3,6 @@ description = Implementation of Axiell’s Alma API for DDELibra. core = 7.x package = Providers php = 5.2.4 -version = 7.x-1.0-beta2 project = alma dependencies[] = date dependencies[] = ding_provider From a68dbd1e836be90fc2d16f2d333fbd2c96418f07 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 12 Dec 2013 13:12:20 +0100 Subject: [PATCH 123/158] Updated makefile to point to tag 7.x-1.0-beta4 --- alma.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alma.make b/alma.make index 6ce063c..68fd103 100644 --- a/alma.make +++ b/alma.make @@ -23,9 +23,9 @@ projects[virtual_field][version] = "1.1" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-beta3" +projects[ding_provider][download][tag] = "7.x-1.0-beta4" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" -projects[ding_reservation][download][tag] = "7.x-1.0-beta3" +projects[ding_reservation][download][tag] = "7.x-1.0-beta4" From 1b419b71ecec160c2dd67e69ad7b1fd00f39a35c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 13 Dec 2013 10:10:14 +0100 Subject: [PATCH 124/158] Added requirements to alma in relation to WAYF --- alma.install | 23 +++++++++++++++++++++++ includes/alma.wayf.inc | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/alma.install b/alma.install index 356ebc2..a37b560 100644 --- a/alma.install +++ b/alma.install @@ -16,6 +16,29 @@ function alma_requirements($phase) { ); } + if ($phase == 'runtime') { + $requirements['alma'] = array( + 'title' => $t('Alma'), + 'value' => $t('Alma configured'), + 'severity' => REQUIREMENT_OK, + ); + if (!variable_get('alma_base_url', FALSE) || !variable_get('ting_agency', FALSE)) { + $requirements['alma']['value'] = $t('Alma not configured'); + $requirements['alma']['description'] = $t('Alma is not properly configured, please visit the settings page.', array('@link' => url('admin/config/ding/provider/alma'))); + $requirements['alma']['severity'] = REQUIREMENT_ERROR; + } + $requirements['alma_wayf'] = array( + 'title' => $t('Alma WAYF'), + 'value' => $t('Alma WAYF configured'), + 'severity' => REQUIREMENT_OK, + ); + if (!variable_get('wayf_hash', FALSE)) { + $requirements['alma']['value'] = $t('Alma WAYF not configured'); + $requirements['alma']['description'] = $t('Alma WAYF is not properly configured, you need to set $conf[\'wayf_hash\'] in setttings.php.'); + $requirements['alma']['severity'] = REQUIREMENT_ERROR; + } + } + return $requirements; } diff --git a/includes/alma.wayf.inc b/includes/alma.wayf.inc index a057bc3..fa477a4 100644 --- a/includes/alma.wayf.inc +++ b/includes/alma.wayf.inc @@ -11,7 +11,7 @@ * login. */ function alma_wayf_login_credentials($authentication_attributes) { - $hash = variable_get('alma_wayf_hash', ''); + $hash = variable_get('wayf_hash', ''); $credentials = array(); if ($hash) { @@ -22,7 +22,7 @@ function alma_wayf_login_credentials($authentication_attributes) { } else { // Set message that hash value was not found. - watchdog('alma', 'The WAYF hash value has not been set in setting.php as $conf[\'alma_wayf_hash\'] and WAYF login will fail', WATCHDOG_ERROR); + watchdog('alma', 'The WAYF hash value has not been set in setting.php as $conf[\'wayf_hash\'] and WAYF login will fail.', WATCHDOG_ERROR); } return $credentials; From 5080654d9d6312e4c0027371d434d4ac4973987e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 18 Dec 2013 05:02:14 +0100 Subject: [PATCH 125/158] Updated makefile to point to tag 7.x-1.0-beta5 --- alma.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alma.make b/alma.make index 68fd103..a88bede 100644 --- a/alma.make +++ b/alma.make @@ -23,9 +23,9 @@ projects[virtual_field][version] = "1.1" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-beta4" +projects[ding_provider][download][tag] = "7.x-1.0-beta5" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" -projects[ding_reservation][download][tag] = "7.x-1.0-beta4" +projects[ding_reservation][download][tag] = "7.x-1.0-beta5" From e9c4a239a48142ccf0b0fb06a34b195d3a8e819d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 20 Dec 2013 15:38:34 +0100 Subject: [PATCH 126/158] Updated makefile to point to tag 7.x-1.0-rc1 --- alma.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alma.make b/alma.make index a88bede..10bde51 100644 --- a/alma.make +++ b/alma.make @@ -23,9 +23,9 @@ projects[virtual_field][version] = "1.1" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-beta5" +projects[ding_provider][download][tag] = "7.x-1.0-rc1" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" -projects[ding_reservation][download][tag] = "7.x-1.0-beta5" +projects[ding_reservation][download][tag] = "7.x-1.0-rc1" From 923123a202563082d9adc2a6085f56786793d503 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 8 Jan 2014 21:56:55 +0100 Subject: [PATCH 127/158] Updated makefile to point to tag 7.x-1.0-rc2 --- alma.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alma.make b/alma.make index 10bde51..f206bfa 100644 --- a/alma.make +++ b/alma.make @@ -23,9 +23,9 @@ projects[virtual_field][version] = "1.1" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-rc1" +projects[ding_provider][download][tag] = "7.x-1.0-rc2" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" -projects[ding_reservation][download][tag] = "7.x-1.0-rc1" +projects[ding_reservation][download][tag] = "7.x-1.0-rc2" From 7dbab311b36255184f1babe541c9c1635f3f7057 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 15 Jan 2014 12:12:38 +0100 Subject: [PATCH 128/158] Updated coding style in alma client --- lib/AlmaClient/AlmaClient.class.php | 121 +++++++++++++++------------- 1 file changed, 66 insertions(+), 55 deletions(-) diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index 6fff6e6..f552f47 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -26,7 +26,7 @@ class AlmaClient { /** * Constructor, checking if we have a sensible value for $base_url. */ - function __construct($base_url) { + public function __construct($base_url) { if (stripos($base_url, 'http') === 0 && filter_var($base_url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)) { $this->base_url = $base_url; } @@ -46,28 +46,30 @@ function __construct($base_url) { * are required for all request related to library patrons. * @param array $params * Query string parameters in the form of key => value. - * @param boolean $check_status + * @param bool $check_status * Check the status element, and throw an exception if it is not ok. + * * @return DOMDocument * A DOMDocument object with the response. */ public function request($method, $params = array(), $check_status = TRUE) { - $startTime = explode(' ', microtime()); + $start_time = explode(' ', microtime()); // For use with a non-Drupal-system, we should have a way to swap // the HTTP client out. $request = drupal_http_request(url($this->base_url . $method, array('query' => $params)), array('secure_socket_transport' => 'sslv3')); - $stopTime = explode(' ', microtime()); + $stop_time = explode(' ', microtime()); // For use with a non-Drupal-system, we should have a way to swap // logging and logging preferences out. if (variable_get('alma_enable_logging', FALSE)) { - $seconds = floatval(($stopTime[1] + $stopTime[0]) - ($startTime[1] + $startTime[0])); + $seconds = floatval(($stop_time[1] + $stop_time[0]) - ($start_time[1] + $start_time[0])); // Filter params to avoid logging sensitive data. - // This can be disabled by setting alma_logging_filter_params = 0. There is no UI for setting this variable + // This can be disabled by setting alma_logging_filter_params = 0. There + // is no UI for setting this variable // It is intended for settings.php in development environments only. $params = (variable_get('alma_logging_filter_params', 1)) ? self::filter_request_params($params) : $params; - // Log the request + // Log the request. watchdog('alma', 'Sent request: @url (@seconds s)', array('@url' => url($this->base_url . $method, array('query' => $params)), '@seconds' => $seconds), WATCHDOG_DEBUG); } @@ -86,10 +88,10 @@ public function request($method, $params = array(), $check_status = TRUE) { case '': case 'borrCardNotFound': throw new AlmaClientBorrCardNotFound('Invalid borrower credentials'); - break; + case 'reservationNotFound': throw new AlmaClientReservationNotFound('Reservation not found'); - break; + default: throw new AlmaClientCommunicationError('Status is not okay: ' . $message); } @@ -101,23 +103,31 @@ public function request($method, $params = array(), $check_status = TRUE) { } /** - * Filters sensitive information in request parameters allowing the values to be logged + * Filters sensitive information in request parameters allowing the values to + * be logged. * - * @param array $params An array of request information + * @param array $params + * An array of request information * * @return array - * An array of filtered request information + * An array of filtered request information */ private static function filter_request_params($params) { // Scramble sensitive information - $sensitive = array('borrCard', 'pinCode', 'pinCodeChange', 'address', 'emailAddress'); + $sensitive = array( + 'borrCard', + 'pinCode', + 'pinCodeChange', + 'address', + 'emailAddress', + ); $log_params = array(); foreach ($params as $key => $value) { if (in_array($key, $sensitive)) { // Replace the value with a scrambled version generated using md5() and // the static salt. This way all requests generated by the same page - // load can be grouped + // load can be grouped. $value = substr(md5($value . self::$salt), 0, strlen($value)); } $log_params[$key] = $value; @@ -132,7 +142,7 @@ private static function filter_request_params($params) { * Formats the list of branches in an array usable for form API selects. * * @return array - * List of branches, keyed by branch_id + * List of branches, keyed by branch_id. */ public function get_branches() { $branches = array(); @@ -151,7 +161,7 @@ public function get_branches() { * Formats the list of branches in an array usable for form API selects. * * @return array - * List of branches, keyed by branch_id + * List of branches, keyed by branch_id */ public function get_reservation_branches() { $branches = array(); @@ -169,7 +179,7 @@ public function get_reservation_branches() { * Formats the list of branches in an array usable for form API selects. * * @return array - * List of departments, keyed by department id. + * List of departments, keyed by department id. */ public function get_departments() { $departments = array(); @@ -188,7 +198,7 @@ public function get_departments() { * Formats the list of branches in an array usable for form API selects. * * @return array - * List of locations, keyed by location id. + * List of locations, keyed by location id. */ public function get_locations() { $locations = array(); @@ -202,12 +212,12 @@ public function get_locations() { } /** - * Get sublocation names from Alma. + * Get sub location names from Alma. * * Formats the list of branches in an array usable for form API selects. * * @return array - * List of sublocations, keyed by sublocation id. + * List of sub locations, keyed by sub location id. */ public function get_sublocations() { $sublocations = array(); @@ -226,7 +236,7 @@ public function get_sublocations() { * Formats the list of branches in an array usable for form API selects. * * @return array - * List of collections, keyed by collection id. + * List of collections, keyed by collection id. */ public function get_collections() { $collections = array(); @@ -520,8 +530,8 @@ public function renew_loan($borr_card, $pin_code, $loan_ids) { $doc = $this->request('patron/loans/renew', $params); - //Built return array as specified by Ding loan provider. - //See ding_provider_example_loan_renew_loans(). + // Built return array as specified by Ding loan provider. + // See ding_provider_example_loan_renew_loans(). $reservations = array(); foreach ($doc->getElementsByTagName('loan') as $loan) { $id = $loan->getAttribute('id'); @@ -529,9 +539,10 @@ public function renew_loan($borr_card, $pin_code, $loan_ids) { if ($renewable = $loan->getElementsByTagName('loanIsRenewable')->item(0)) { $message = $renewable->getAttribute('message'); $renewable = $renewable->getAttribute('value'); - //If message is "isRenewedToday" we assumme that the renewal is successful. - //Even if this is not the case any error in the current renewal is irrelevant - //as the loan has previously been renewed so don't report it as such + // If message is "isRenewedToday" we assume that the renewal is + // successful. Even if this is not the case any error in the current + // renewal is irrelevant as the loan has previously been renewed so + // don't report it as such. if ($message == 'isRenewedToday' || $renewable == 'yes') { $reservations[$id] = TRUE; } @@ -823,12 +834,12 @@ public function add_payment($debt_ids, $order_id = NULL) { * Change user’s preferred branch. * * @param string $borr_card - * Library patron's borrowing card number. Either just an arbitrary - * number printed on their library card or their CPR-code. + * Library patron's borrowing card number. Either just an arbitrary + * number printed on their library card or their CPR-code. * @param string $pin_code - * Library patron's current four digit PIN code. + * Library patron's current four digit PIN code. * @param string $branch_code - * New preferred branch. + * New preferred branch. */ public function change_patron_preferences($borr_card, $pin_code, $branch_code) { $params = array( @@ -845,14 +856,14 @@ public function change_patron_preferences($borr_card, $pin_code, $branch_code) { * Add an Alma absent period. * * @param string $borr_card - * Library patron's borrowing card number. Either just an arbitrary - * number printed on their library card or their CPR-code. + * Library patron's borrowing card number. Either just an arbitrary + * number printed on their library card or their CPR-code. * @param string $pin_code - * Library patron's current four digit PIN code. + * Library patron's current four digit PIN code. * @param string $from_date - * Absent period start date. + * Absent period start date. * @param string $to_date - * Absent period start date. + * Absent period start date. */ public function add_absent_period($borr_card, $pin_code, $from_date, $to_date) { $params = array( @@ -870,16 +881,16 @@ public function add_absent_period($borr_card, $pin_code, $from_date, $to_date) { * Change existing absent period. * * @param string $borr_card - * Library patron's borrowing card number. Either just an arbitrary - * number printed on their library card or their CPR-code. + * Library patron's borrowing card number. Either just an arbitrary + * number printed on their library card or their CPR-code. * @param string $pin_code - * Library patron's current four digit PIN code. + * Library patron's current four digit PIN code. * @param string $absent_id - * ID for existing period. + * ID for existing period. * @param string $from_date - * Absent period start date. + * Absent period start date. * @param string $to_date - * Absent period start date. + * Absent period start date. */ public function change_absent_period($borr_card, $pin_code, $absent_id, $from_date, $to_date) { $params = array( @@ -898,12 +909,12 @@ public function change_absent_period($borr_card, $pin_code, $absent_id, $from_da * Remove existing absent period. * * @param string $borr_card - * Library patron's borrowing card number. Either just an arbitrary - * number printed on their library card or their CPR-code. + * Library patron's borrowing card number. Either just an arbitrary + * number printed on their library card or their CPR-code. * @param string $pin_code - * Library patron's current four digit PIN code. + * Library patron's current four digit PIN code. * @param string $absent_id - * ID for existing period. + * ID for existing period. */ public function remove_absent_period($borr_card, $pin_code, $absent_id) { $params = array( @@ -920,14 +931,14 @@ public function remove_absent_period($borr_card, $pin_code, $absent_id) { * Add a messaging service. * * @param string $borr_card - * Library patron's borrowing card number. Either just an arbitrary - * number printed on their library card or their CPR-code. + * Library patron's borrowing card number. Either just an arbitrary + * number printed on their library card or their CPR-code. * @param string $pin_code - * Library patron's current four digit PIN code. + * Library patron's current four digit PIN code. * @param $method - * The method for sending messages e.g. SMS + * The method for sending messages e.g. SMS * @param $type - * The message type e.g. due date alerts + * The message type e.g. due date alerts */ public function add_message_service($borr_card, $pin_code, $method, $type) { $params = array( @@ -945,14 +956,14 @@ public function add_message_service($borr_card, $pin_code, $method, $type) { * Removes a messaging service. * * @param string $borr_card - * Library patron's borrowing card number. Either just an arbitrary - * number printed on their library card or their CPR-code. + * Library patron's borrowing card number. Either just an arbitrary + * number printed on their library card or their CPR-code. * @param string $pin_code - * Library patron's current four digit PIN code. + * Library patron's current four digit PIN code. * @param $method - * The method for sending messages e.g. SMS + * The method for sending messages e.g. SMS * @param $type - * The message type e.g. due date alerts + * The message type e.g. due date alerts */ public function remove_message_service($borr_card, $pin_code, $method, $type) { $params = array( From 08ed20c1363e1226455f38d464464f96eae16032 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 20 Jan 2014 12:24:27 +0100 Subject: [PATCH 129/158] Updated makefile to point to tag 7.x-1.0-rc3 --- alma.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alma.make b/alma.make index f206bfa..8d196f9 100644 --- a/alma.make +++ b/alma.make @@ -23,9 +23,9 @@ projects[virtual_field][version] = "1.1" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-rc2" +projects[ding_provider][download][tag] = "7.x-1.0-rc3" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" -projects[ding_reservation][download][tag] = "7.x-1.0-rc2" +projects[ding_reservation][download][tag] = "7.x-1.0-rc3" From b0cb9158e4c8da7e4655125d42c987bc078e5eb8 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Feb 2014 11:12:21 +0100 Subject: [PATCH 130/158] Updated makefile to point to ding2 master branches --- alma.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/alma.make b/alma.make index 8d196f9..338c203 100644 --- a/alma.make +++ b/alma.make @@ -22,10 +22,10 @@ projects[virtual_field][version] = "1.1" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" -projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-rc3" +projects[ding_provider][download][url] = "git@github.com:ding2/ding_provider.git" +projects[ding_provider][download][branch] = "master" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" -projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" -projects[ding_reservation][download][tag] = "7.x-1.0-rc3" +projects[ding_reservation][download][url] = "git@github.com:ding2/ding_reservation.git" +projects[ding_reservation][download][tag] = "master" From 1612421d7d21648e1b3a09e00df2ee37c1bd9be0 Mon Sep 17 00:00:00 2001 From: Thomas Johansen Date: Mon, 17 Mar 2014 13:55:23 +0100 Subject: [PATCH 131/158] Added check to see if not is FALSE --- includes/alma.user.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/alma.user.inc b/includes/alma.user.inc index d1f7738..893e271 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -17,7 +17,9 @@ function alma_user_authenticate($uid, $pass) { try { $res = alma_client_invoke('get_patron_info', $uid, $pass, TRUE); - $return['success'] = TRUE; + if ($res) { + $return['success'] = TRUE; + } } catch (Exception $e) { return $return; From 1577406d40df461b1f82d059702e0d6a32e437d2 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 29 Apr 2014 12:17:08 +0200 Subject: [PATCH 132/158] Removed WAYF requirement (move to ding_wayf) --- alma.install | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/alma.install b/alma.install index a37b560..c456560 100644 --- a/alma.install +++ b/alma.install @@ -1,4 +1,8 @@ the settings page.', array('@link' => url('admin/config/ding/provider/alma'))); $requirements['alma']['severity'] = REQUIREMENT_ERROR; } - $requirements['alma_wayf'] = array( - 'title' => $t('Alma WAYF'), - 'value' => $t('Alma WAYF configured'), - 'severity' => REQUIREMENT_OK, - ); - if (!variable_get('wayf_hash', FALSE)) { - $requirements['alma']['value'] = $t('Alma WAYF not configured'); - $requirements['alma']['description'] = $t('Alma WAYF is not properly configured, you need to set $conf[\'wayf_hash\'] in setttings.php.'); - $requirements['alma']['severity'] = REQUIREMENT_ERROR; - } } return $requirements; From c3be61242d538cd7d3b3d1afc0e5ba2332bd5b89 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 29 Apr 2014 13:41:21 +0200 Subject: [PATCH 133/158] Fixed makefile with right branch name --- alma.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alma.make b/alma.make index 338c203..9f805bd 100644 --- a/alma.make +++ b/alma.make @@ -28,4 +28,4 @@ projects[ding_provider][download][branch] = "master" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" projects[ding_reservation][download][url] = "git@github.com:ding2/ding_reservation.git" -projects[ding_reservation][download][tag] = "master" +projects[ding_reservation][download][branch] = "master" From 8360489b8f5ab61050b95cda5f6608a3e9012fd4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 29 Apr 2014 13:46:23 +0200 Subject: [PATCH 134/158] Fixed typo in results variable name in alma_debt_list --- includes/alma.debt.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/alma.debt.inc b/includes/alma.debt.inc index 5bf93b8..4cf3405 100644 --- a/includes/alma.debt.inc +++ b/includes/alma.debt.inc @@ -18,14 +18,14 @@ function alma_debt_list($account, $reset = FALSE) { $creds = ding_user_get_creds($account); - // Use session cache to speed up communication with Alma. + // Use static cache to speed up communication with Alma. $results = &drupal_static(__FUNCTION__, FALSE); if (!$results || $reset) { // Get debts from Alma. $debts = alma_client_invoke('get_debts', $creds['name'], $creds['pass']); // Create DingProviderDebt instances from Alma's list. - $result = array(); + $results = array(); foreach ($debts['debts'] as $debt) { // Get the material number from the display name and remove it form it. preg_match('/^(\w+)\s+(.+)/', $debt['display_name'], $matchs); @@ -38,11 +38,11 @@ function alma_debt_list($account, $reset = FALSE) { $debt['type'] = alma_debt_translate_debt_type($debt['type']); $debt_object = new DingProviderDebt($debt['id'], $debt); - $result[$debt['id']] = $debt_object; + $results[$debt['id']] = $debt_object; } } - return $result; + return $results; } /** From 4e0f865d9fba8263c73f0d25829527bd9a902a0c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 29 Apr 2014 13:51:33 +0200 Subject: [PATCH 135/158] Updated debt status texts to work better with module such as potx --- includes/alma.debt.inc | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/includes/alma.debt.inc b/includes/alma.debt.inc index 4cf3405..ca62dc9 100644 --- a/includes/alma.debt.inc +++ b/includes/alma.debt.inc @@ -78,69 +78,69 @@ function alma_debt_translate_debt_type($debt_type) { switch ($debt_type) { case 'overdueFeeInvoiceDebt': - $str = 'Overdue fee invoice'; + $str = t('Overdue fee invoice'); break; case 'overdueFeeDebt': - $str = 'Overdue fee'; + $str = t('Overdue fee'); break; case 'loanFeeDebt': - $str = 'Loan fee'; + $str = t('Loan fee'); break; case 'reservationPickupFeeDebt': - $str = 'Reservation pick-up fee'; + $str = t('Reservation pick-up fee'); break; case 'reservationFeeDebt': - $str = 'Reservation fee'; + $str = t('Reservation fee'); break; case 'deleteReservationFeeDebt': - $str = 'Delete reservation fee'; + $str = t('Delete reservation fee'); break; case 'illFeeDebt': - $str = 'Interlibrary fee'; + $str = t('Interlibrary fee'); break; case 'smsReservationFeeDebt': - $str = 'SMS reservation fee'; + $str = t('SMS reservation fee'); break; case 'smsReminderFeeDebt': - $str = 'SMS reminder fee'; + $str = t('SMS reminder fee'); break; case 'smsRecall1FeeDebt': - $str = 'SMS first recall fee'; + $str = t('SMS first recall fee'); break; case 'smsRecall2FeeDebt': - $str = 'SMS second recall fee'; + $str = t('SMS second recall fee'); break; case 'smsRecall3FeeDebt': - $str = 'SMS third recall fee'; + $str = t('SMS third recall fee'); break; case 'smsRecall4FeeDebt': - $str = 'SMS fourth recall fee'; + $str = t('SMS fourth recall fee'); break; case 'smsRecall5FeeDebt': - $str = 'SMS fifth recall fee'; + $str = t('SMS fifth recall fee'); break; case 'emailReminderFeeDebt': - $str = 'E-mail reminder fee'; + $str = t('E-mail reminder fee'); break; case 'otherFeeDebt': - $str = 'Unknown or other fee'; + $str = t('Unknown or other fee'); break; }; - return t($str); + return $str; } From a726da38c2f17af48bb158ff0d8f66ca204ff123 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 29 Apr 2014 13:54:24 +0200 Subject: [PATCH 136/158] Updated comment about inter library loans --- includes/alma.loan.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/alma.loan.inc b/includes/alma.loan.inc index 1cfe34d..a349d9c 100644 --- a/includes/alma.loan.inc +++ b/includes/alma.loan.inc @@ -109,7 +109,8 @@ function alma_loan_populate_pseudo_entity($ting_entity) { $ting_entity->reply->record['dc:creator']['dkdcplus:aut'] = $source['authors']; } - // If it a ill Alma record isbn are not always available. + // If it is an inter library loan (ill) Alma record isbn are not always + // available. if (isset($source['isbns'][0])) { $ting_entity->reply->record['dc:identifier']['dkdcplus:ISBN'][0] = str_replace(array('-', ' ', 'ISBN'), '', $source['isbns'][0]); } From e9df7b0910b4af928c77e1d77441c261ca7335fb Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 29 Apr 2014 15:01:58 +0200 Subject: [PATCH 137/158] Added check for ding_session cache in alma reservation cache clear --- includes/alma.reservation.inc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index fd4c921..b560c6c 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -442,7 +442,10 @@ function alma_reservation_get_reservations($account, $reset = FALSE) { * Clear reservations stored in the current session cache. */ function alma_reservation_clear_cache() { - ding_session_cache_clear('alma', 'reservations'); + // Check if ding_session_cache is available. + if (module_exists('ding_session_cache')) { + ding_session_cache_clear('alma', 'reservations'); + } } /** From 5f349aedbf2eebbbcbcc4924a888dd3bf306d1b5 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 6 May 2014 12:22:56 +0200 Subject: [PATCH 138/158] Updated virtual field to version 1.2 --- alma.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alma.make b/alma.make index 17b4a6d..6c5ffdb 100644 --- a/alma.make +++ b/alma.make @@ -16,7 +16,7 @@ projects[profile2][subdir] = "contrib" projects[profile2][version] = "1.3" projects[virtual_field][subdir] = "contrib" -projects[virtual_field][version] = "1.1" +projects[virtual_field][version] = "1.2" ; Ding! modules From 1cb5f80445f4854ec76a817b045cf335931e32e3 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 6 May 2014 13:46:04 +0200 Subject: [PATCH 139/158] Updated features to version 2.0 --- alma.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alma.make b/alma.make index 6c5ffdb..980378b 100644 --- a/alma.make +++ b/alma.make @@ -10,7 +10,7 @@ projects[email][subdir] = "contrib" projects[email][version] = "1.2" projects[features][subdir] = "contrib" -projects[features][version] = "2.0-beta2" +projects[features][version] = "2.0" projects[profile2][subdir] = "contrib" projects[profile2][version] = "1.3" From 02cc6f4f3d64b8e790de814182c4434e18f870ea Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 6 May 2014 13:56:31 +0200 Subject: [PATCH 140/158] Updated email to version 1.3 --- alma.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alma.make b/alma.make index 980378b..effa41e 100644 --- a/alma.make +++ b/alma.make @@ -7,7 +7,7 @@ projects[date][subdir] = "contrib" projects[date][version] = "2.6" projects[email][subdir] = "contrib" -projects[email][version] = "1.2" +projects[email][version] = "1.3" projects[features][subdir] = "contrib" projects[features][version] = "2.0" From 03ad8080534e4a74591e2b6f7c61dcb9b7e20649 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 6 May 2014 13:59:10 +0200 Subject: [PATCH 141/158] Updated date to version 2.7 --- alma.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alma.make b/alma.make index effa41e..1b02f91 100644 --- a/alma.make +++ b/alma.make @@ -4,7 +4,7 @@ core = 7.x ; Contrib projects[date][subdir] = "contrib" -projects[date][version] = "2.6" +projects[date][version] = "2.7" projects[email][subdir] = "contrib" projects[email][version] = "1.3" From c4460bbf470afd4ee5264a90f094cf92853f08bc Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 19 May 2014 15:39:56 +0200 Subject: [PATCH 142/158] Issue #140 cableman: Added block status vaiable on user authentication --- includes/alma.user.inc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/includes/alma.user.inc b/includes/alma.user.inc index 893e271..9407530 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -25,8 +25,6 @@ function alma_user_authenticate($uid, $pass) { return $return; } - // @todo Check block status. - // Set creds. $return['creds'] = array( 'name' => $uid, @@ -60,6 +58,11 @@ function alma_user_authenticate($uid, $pass) { ); } + $return['user']['blocked'] = FALSE; + if (!empty($res['blocks'])) { + $return['user']['blocked'] = TRUE; + } + return $return; } From c24d9f9e01b34ab8be1769d583bac416c7333d1c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 20 May 2014 14:01:33 +0200 Subject: [PATCH 143/158] Issue #339 cableman: Added SMS and phone number to alma --- alma.features.field_base.inc | 82 +++++++++++++++++++++++++++++++ alma.features.field_instance.inc | 84 ++++++++++++++++++++++++++++---- alma.info | 7 ++- alma.module | 80 +++++++++++++++++++++++++++--- 4 files changed, 236 insertions(+), 17 deletions(-) diff --git a/alma.features.field_base.inc b/alma.features.field_base.inc index fd8dc6f..f8a527f 100644 --- a/alma.features.field_base.inc +++ b/alma.features.field_base.inc @@ -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, diff --git a/alma.features.field_instance.inc b/alma.features.field_instance.inc index 149a19f..6d03c53 100644 --- a/alma.features.field_instance.inc +++ b/alma.features.field_instance.inc @@ -21,7 +21,7 @@ function alma_field_default_field_instances() { 'label' => 'hidden', 'settings' => array(), 'type' => 'hidden', - 'weight' => 9, + 'weight' => 10, ), ), 'entity_type' => 'profile2', @@ -36,7 +36,7 @@ function alma_field_default_field_instances() { 'module' => 'virtual_field', 'settings' => array(), 'type' => 'hidden', - 'weight' => 9, + 'weight' => 10, ), ); @@ -118,7 +118,7 @@ function alma_field_default_field_instances() { 'module' => 'list', 'settings' => array(), 'type' => 'list_default', - 'weight' => 8, + 'weight' => 9, ), ), 'entity_type' => 'profile2', @@ -182,7 +182,7 @@ function alma_field_default_field_instances() { 'module' => 'text', 'settings' => array(), 'type' => 'text_default', - 'weight' => 5, + 'weight' => 6, ), ), 'entity_type' => 'profile2', @@ -200,7 +200,7 @@ function alma_field_default_field_instances() { 'size' => 12, ), 'type' => 'text_textfield', - 'weight' => 8, + 'weight' => 9, ), ); @@ -215,7 +215,7 @@ function alma_field_default_field_instances() { 'label' => 'hidden', 'settings' => array(), 'type' => 'hidden', - 'weight' => 10, + 'weight' => 11, ), ), 'entity_type' => 'profile2', @@ -230,7 +230,7 @@ function alma_field_default_field_instances() { 'module' => 'virtual_field', 'settings' => array(), 'type' => 'hidden', - 'weight' => 10, + 'weight' => 12, ), ); @@ -277,7 +277,7 @@ function alma_field_default_field_instances() { 'module' => 'list', 'settings' => array(), 'type' => 'list_default', - 'weight' => 6, + 'weight' => 7, ), ), 'entity_type' => 'profile2', @@ -313,7 +313,7 @@ function alma_field_default_field_instances() { 'multiple_to' => '', ), 'type' => 'date_default', - 'weight' => 7, + 'weight' => 8, ), ), 'entity_type' => 'profile2', @@ -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', @@ -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.'); diff --git a/alma.info b/alma.info index 4c69ca5..cc822cd 100644 --- a/alma.info +++ b/alma.info @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/alma.module b/alma.module index b0a791d..e81d2a6 100644 --- a/alma.module +++ b/alma.module @@ -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())) { @@ -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); @@ -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); @@ -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']) && @@ -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); From a83bdb48ff56f588b1c8c55770b727d62ff24491 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 20 May 2014 14:06:42 +0200 Subject: [PATCH 144/158] Added alma code about sms number from ding_user --- alma.module | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/alma.module b/alma.module index e81d2a6..2f92b8c 100644 --- a/alma.module +++ b/alma.module @@ -704,6 +704,20 @@ function alma_profile2_load($entities) { } } +/** + * Implements hook_field_attach_view_alter(). + * + * Alter user profile view with SMS TAX. + */ +function alma_field_attach_view_alter(&$output, $context) { + if (isset($output['field_alma_sms'][0]['#markup'])) { + $ding_user_tax_sms = variable_get('ding_user_tax_sms', t('Notice that there is a fee for receiving a SMS')); + if ($ding_user_tax_sms) { + $output['field_alma_sms'][0]['#markup'] .= '(' . $ding_user_tax_sms . ')'; + } + } +} + /** * Implements hook_ding_session_cache_defaults(). * From 490373bbeb546bcb40c99e755504cc05aabcdb4c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 20 May 2014 16:33:43 +0200 Subject: [PATCH 145/158] Issue #354 cableman: Updated alma reservations to display the status from alma on inter libaray loans --- includes/alma.reservation.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index b560c6c..906d4d8 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -179,7 +179,7 @@ function alma_reservation_list($account, $type = NULL) { elseif ($reservation['id'] < 0) { // Inter-library loan reservations have negative IDs (undocumented // Axiell "feature"). - $data['ill_status'] = TRUE; + $data['ill_status'] = $reservation['status']; $data['reservation_type'] = DING_RESERVATION_INTERLIBRARY_LOANS; // Create reservation object. From 5d34657ed83144f7eaf142c2cfd2351febe40b94 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 22 May 2014 10:37:50 +0200 Subject: [PATCH 146/158] Updated SMS tax naming to SMS fee --- alma.module | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/alma.module b/alma.module index 2f92b8c..4f6ae8e 100644 --- a/alma.module +++ b/alma.module @@ -707,13 +707,13 @@ function alma_profile2_load($entities) { /** * Implements hook_field_attach_view_alter(). * - * Alter user profile view with SMS TAX. + * Alter user profile view with SMS fee. */ function alma_field_attach_view_alter(&$output, $context) { if (isset($output['field_alma_sms'][0]['#markup'])) { - $ding_user_tax_sms = variable_get('ding_user_tax_sms', t('Notice that there is a fee for receiving a SMS')); - if ($ding_user_tax_sms) { - $output['field_alma_sms'][0]['#markup'] .= '(' . $ding_user_tax_sms . ')'; + $ding_user_fee_sms = variable_get('ding_user_fee_sms', t('Notice that there is a fee for receiving a SMS')); + if ($ding_user_fee_sms) { + $output['field_alma_sms'][0]['#markup'] .= '(' . $ding_user_fee_sms . ')'; } } } From dbbe6841bee17f3974d36f2cdbd6e6d68a3d39f2 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 25 Jun 2014 15:37:44 +0200 Subject: [PATCH 147/158] Ensured that alma parton cache is refreshed on save --- alma.module | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/alma.module b/alma.module index 4f6ae8e..d4dccde 100644 --- a/alma.module +++ b/alma.module @@ -162,6 +162,9 @@ function alma_client() { * @param string $method * The desired method. * + * @throws Exception + * Provider exception if communication fails. + * * @return array * NULL on error, or the result of the method call. */ @@ -569,6 +572,11 @@ function alma_update_provider($changes, $entity) { user_save($user); } } + + // Update patron information and update cache. + if (!empty($changes)) { + alma_get_patron($creds, TRUE); + } } /** From cf97641dca3ef4875a85e3bdc751752cef0401fe Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 8 Sep 2014 11:17:16 +0200 Subject: [PATCH 148/158] Updated date to 2.8 --- alma.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alma.make b/alma.make index 1b02f91..814def9 100644 --- a/alma.make +++ b/alma.make @@ -4,7 +4,7 @@ core = 7.x ; Contrib projects[date][subdir] = "contrib" -projects[date][version] = "2.7" +projects[date][version] = "2.8" projects[email][subdir] = "contrib" projects[email][version] = "1.3" From fae4ec8c5edc5f57251add08a262ddd626ee1adb Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 23 Sep 2014 15:58:12 +0200 Subject: [PATCH 149/158] Added user category and blocks code to the user information --- includes/alma.user.inc | 7 +++++++ lib/AlmaClient/AlmaClient.class.php | 1 + 2 files changed, 8 insertions(+) diff --git a/includes/alma.user.inc b/includes/alma.user.inc index 9407530..98addb4 100644 --- a/includes/alma.user.inc +++ b/includes/alma.user.inc @@ -58,8 +58,15 @@ function alma_user_authenticate($uid, $pass) { ); } + // Set the users categories. + if (!empty($res['category'])) { + $return['user']['category'] = $res['category']; + } + $return['user']['blocked'] = FALSE; if (!empty($res['blocks'])) { + // Send block codes back with the user. + $return['user']['blocks'] = $res['blocks']; $return['user']['blocked'] = TRUE; } diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index f552f47..fd1a1b2 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -266,6 +266,7 @@ public function get_patron_info($borr_card, $pin_code, $extended = FALSE) { 'addresses' => array(), 'mails' => array(), 'phones' => array(), + 'category' => $info->getAttribute('patronCategory'), ); foreach ($info->getElementsByTagName('address') as $address) { From 44f6a0bf85476a437f8142b43023843696be181d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 6 Oct 2014 11:06:42 +0200 Subject: [PATCH 150/158] Updated makefile to point to development branch --- alma.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/alma.make b/alma.make index 140f067..814def9 100644 --- a/alma.make +++ b/alma.make @@ -22,10 +22,10 @@ projects[virtual_field][version] = "1.2" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" -projects[ding_provider][download][url] = "git@github.com:ding2/ding_provider.git" -projects[ding_provider][download][branch] = "master" +projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" +projects[ding_provider][download][branch] = "development" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" -projects[ding_reservation][download][url] = "git@github.com:ding2/ding_reservation.git" -projects[ding_reservation][download][branch] = "master" +projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" +projects[ding_reservation][download][branch] = "development" From e22dcd6acb766092dd4415b510763357a711ec6d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 6 Oct 2014 14:30:59 +0200 Subject: [PATCH 151/158] Updated make file to point to master branch --- alma.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/alma.make b/alma.make index 814def9..140f067 100644 --- a/alma.make +++ b/alma.make @@ -22,10 +22,10 @@ projects[virtual_field][version] = "1.2" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" -projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][branch] = "development" +projects[ding_provider][download][url] = "git@github.com:ding2/ding_provider.git" +projects[ding_provider][download][branch] = "master" projects[ding_reservation][type] = "module" projects[ding_reservation][download][type] = "git" -projects[ding_reservation][download][url] = "git@github.com:ding2tal/ding_reservation.git" -projects[ding_reservation][download][branch] = "development" +projects[ding_reservation][download][url] = "git@github.com:ding2/ding_reservation.git" +projects[ding_reservation][download][branch] = "master" From 00a8576049d4f1f17791b45b5f1261ae6722c12e Mon Sep 17 00:00:00 2001 From: pjohans Date: Fri, 10 Oct 2014 07:09:03 +0200 Subject: [PATCH 152/158] Issue #534 by pjohans: Make interest_period required to avoid --none-- selection. --- alma.features.field_instance.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alma.features.field_instance.inc b/alma.features.field_instance.inc index 6d03c53..3ff302b 100644 --- a/alma.features.field_instance.inc +++ b/alma.features.field_instance.inc @@ -124,7 +124,7 @@ function alma_field_default_field_instances() { 'entity_type' => 'profile2', 'field_name' => 'field_alma_interest_period', 'label' => 'Interest period', - 'required' => 0, + 'required' => 1, 'settings' => array( 'user_register_form' => FALSE, ), From 794e19d68bb48571aab8590a048be60f571311f7 Mon Sep 17 00:00:00 2001 From: pjohans Date: Fri, 10 Oct 2014 07:53:21 +0200 Subject: [PATCH 153/158] Issue #534 by pjohans: Get default_interest period for reservations --- includes/alma.reservation.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 906d4d8..8f244ac 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -33,7 +33,7 @@ function alma_reservation_options($account, $default_value = '') { // Get values. $preferred_branch = $wrapper->field_alma_preferred_branch->value(); - $interest_period = $wrapper->field_alma_interest_period->value(); + $interest_period = (variable_get('alma_default_interest_period',FALSE)) ? variable_get('alma_default_interest_period') :$wrapper->field_alma_interest_period->value(); } // Set default value in the selection box if given else use preferred_branch. From 8c1155c7870934c459856b987114ccafb9ba4433 Mon Sep 17 00:00:00 2001 From: pjohans Date: Fri, 10 Oct 2014 08:43:07 +0200 Subject: [PATCH 154/158] Issue #534 by pjohans: More correct use method alma_reservation_default_interest_period to get interest period. --- includes/alma.reservation.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/alma.reservation.inc b/includes/alma.reservation.inc index 8f244ac..8f1eeae 100644 --- a/includes/alma.reservation.inc +++ b/includes/alma.reservation.inc @@ -33,7 +33,7 @@ function alma_reservation_options($account, $default_value = '') { // Get values. $preferred_branch = $wrapper->field_alma_preferred_branch->value(); - $interest_period = (variable_get('alma_default_interest_period',FALSE)) ? variable_get('alma_default_interest_period') :$wrapper->field_alma_interest_period->value(); + $interest_period = alma_reservation_default_interest_period($profile); } // Set default value in the selection box if given else use preferred_branch. From 678a5f975b0400ae09eac50b168e7c7b50e8fd92 Mon Sep 17 00:00:00 2001 From: pjohans Date: Fri, 10 Oct 2014 08:46:51 +0200 Subject: [PATCH 155/158] Issue #534 by pjohans: Undo make interest_period field required. --- alma.features.field_instance.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alma.features.field_instance.inc b/alma.features.field_instance.inc index 3ff302b..6d03c53 100644 --- a/alma.features.field_instance.inc +++ b/alma.features.field_instance.inc @@ -124,7 +124,7 @@ function alma_field_default_field_instances() { 'entity_type' => 'profile2', 'field_name' => 'field_alma_interest_period', 'label' => 'Interest period', - 'required' => 1, + 'required' => 0, 'settings' => array( 'user_register_form' => FALSE, ), From 80b08644ad41c572cf6c51530b65c56e043b904f Mon Sep 17 00:00:00 2001 From: Kasper Garnaes Date: Mon, 23 Mar 2015 11:08:11 +0100 Subject: [PATCH 156/158] Support pickup numbers which are not integers. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some Alma installations e.g. the Copenhagen libraries return strings e.g. “Nr. 56”. --- lib/AlmaClient/AlmaClient.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index fd1a1b2..9b0a89c 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -347,7 +347,7 @@ public function get_reservations($borr_card, $pin_code) { } if ($reservation['status'] == 'fetchable') { - $reservation['pickup_number'] = (integer) $item->getAttribute('pickUpNo'); + $reservation['pickup_number'] = $item->getAttribute('pickUpNo'); $reservation['pickup_expire_date'] = $item->getAttribute('pickUpExpireDate'); } From 9912f4b7130bb360fd0c0ac3b629b0cf38b73f97 Mon Sep 17 00:00:00 2001 From: amd_k8 Date: Fri, 4 Sep 2015 14:50:26 +0300 Subject: [PATCH 157/158] Issue #761 by Inlead: Consider denial of deniedRenewal a success. --- lib/AlmaClient/AlmaClient.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index 9b0a89c..d1800cb 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -544,7 +544,9 @@ public function renew_loan($borr_card, $pin_code, $loan_ids) { // successful. Even if this is not the case any error in the current // renewal is irrelevant as the loan has previously been renewed so // don't report it as such. - if ($message == 'isRenewedToday' || $renewable == 'yes') { + // Also renewalIsDenied marked as 'no' is considered a successful + // renewal. + if ($message == 'isRenewedToday' || $renewable == 'yes' || ($message == 'renewalIsDenied' && $renewable == 'no')) { $reservations[$id] = TRUE; } elseif ($message == 'maxNofRenewals') { From 6b39311bf7c645788265c7fee71e4bd8888c0714 Mon Sep 17 00:00:00 2001 From: AM Date: Wed, 18 Nov 2015 13:02:58 +0200 Subject: [PATCH 158/158] Issue #1337 by Inlead: Encode special characters in item id. --- lib/AlmaClient/AlmaClient.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AlmaClient/AlmaClient.class.php b/lib/AlmaClient/AlmaClient.class.php index d1800cb..060bcf0 100644 --- a/lib/AlmaClient/AlmaClient.class.php +++ b/lib/AlmaClient/AlmaClient.class.php @@ -438,7 +438,7 @@ public function add_reservation($borr_card, $pin_code, $reservation) { $params = array( 'borrCard' => $borr_card, 'pinCode' => $pin_code, - 'reservable' => $reservation['id'], + 'reservable' => rawurlencode($reservation['id']), 'reservationPickUpBranch' => $reservation['pickup_branch'], 'reservationValidFrom' => $reservation['valid_from'], 'reservationValidTo' => $reservation['valid_to'],