Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code review #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ims.info
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ core = "7.x"
dependencies[] = ding_provider
dependencies[] = fbs
configure = admin/config/ding/ims
files[] = lib/ims-client/ImsPlacement.php
files[] = lib/ims-client/ImsException.php
files[] = lib/ims-client/ImsService.php

13 changes: 4 additions & 9 deletions ims.module
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,10 @@ function ims_ding_provider() {
*/
function ims_placements(array $provider_ids) {
// Call the IMS Webservice.
try {
$service = new ImsService(variable_get('ims_wsdl_url'), variable_get('ims_username'), variable_get('ims_password'));
$service = new ImsService(variable_get('ims_wsdl_url'), variable_get('ims_username'), variable_get('ims_password'));

// Retrieve placements for multiple ting object ids.
$retrieved = $service->getByFaustNumber($provider_ids);

// Retrieve placements for multiple ting object ids.
$retrieved = $service->getByFaustNumber($provider_ids);
}
catch (ImsException $e) {
// Re-throw Ims specific exception.
throw new ImsServiceException($e->getMessage());
}
return $retrieved;
}
69 changes: 33 additions & 36 deletions inc/ims.availability.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,44 @@ function ims_availability_holdings(array $provider_ids) {
module_load_include('inc', 'fbs', 'includes/fbs.availability');
$fbs_results = fbs_availability_holdings($provider_ids);

// If the ims module is enabled we try to fetch ims placements.
if (module_exists('ims')) {
try {
// Fetch ims placements for all $provider_ids.
$ims_results = ims_placements($provider_ids);
}
catch (Exception $e) {
watchdog_exception('ims', $e);
// Could't get data from IMS. Just quietly return results from fbs.
return $fbs_results;
}
try {
// Fetch ims placements for all $provider_ids.
$ims_results = ims_placements($provider_ids);
}
catch (Exception $e) {
watchdog_exception('ims', $e);
// Could't get data from IMS. Just quietly return results from fbs.
return $fbs_results;
}

// Loop each faust-number.
foreach ($fbs_results as $faust => $fbs_result) {
// Ims placements for current faust.
$ims_result = $ims_results[$faust];
// Periodicals have holdings pr. volume for each issue
// Requires extra iterations.
if ($fbs_result['is_periodical']) {
$issues = $fbs_result['issues'];
// We need to adjust holdings for each volume in each issue.
foreach ($issues as $issue_key => $volumes) {
foreach ($volumes as $volume_key => $volume) {
// Create and ajust holdings to fit in ims_placements.
$fbs_adjusted_holdings = _ims_merge_ims_placements($volume['placement'], $ims_result);
$fbs_results[$faust]['issues'][$issue_key][$volume_key]['placement'] = $fbs_adjusted_holdings;
}
// Loop each faust-number.
foreach ($fbs_results as $faust => $fbs_result) {
// Ims placements for current faust.
$ims_result = $ims_results[$faust];
// Periodicals have holdings pr. volume for each issue
// Requires extra iterations.
if ($fbs_result['is_periodical']) {
$issues = $fbs_result['issues'];
// We need to adjust holdings for each volume in each issue.
foreach ($issues as $issue_key => $volumes) {
foreach ($volumes as $volume_key => $volume) {
// Create and ajust holdings to fit in ims_placements.
$fbs_adjusted_holdings = _ims_merge_ims_placements($volume['placement'], $ims_result);
$fbs_results[$faust]['issues'][$issue_key][$volume_key]['placement'] = $fbs_adjusted_holdings;
}
}
// Monography.
else {
// Adjust Fbs holdings for a monography.
$fbs_holdings = $fbs_result['holdings'];
// Create and ajust holdings to fit in ims_placements.
$fbs_adjusted_holdings = _ims_merge_ims_placements($fbs_holdings, $ims_result);
$fbs_results[$faust]['holdings'] = $fbs_adjusted_holdings;
}
}

return $fbs_results;
// Monography.
else {
// Adjust Fbs holdings for a monography.
$fbs_holdings = $fbs_result['holdings'];
// Create and ajust holdings to fit in ims_placements.
$fbs_adjusted_holdings = _ims_merge_ims_placements($fbs_holdings, $ims_result);
$fbs_results[$faust]['holdings'] = $fbs_adjusted_holdings;
}
}

return $fbs_results;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/ims-client/ImsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
/**
* Exception related to communication with the IMS SOAP Webservice.
*/
class ImsServiceException extends Exception {}
class ImsException extends Exception {}
7 changes: 3 additions & 4 deletions lib/ims-client/ImsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getByFaustNumber($faust_numbers) {
* @return object
* SOAP Response object.
*
* @throws ImsServiceException
* @throws ImsException
*/
protected function sendRequest($faust_number) {
$auth_info = array(
Expand All @@ -98,7 +98,7 @@ protected function sendRequest($faust_number) {
}
catch (Exception $e) {
// Re-throw Ims specific exception.
throw new ImsServiceException($e->getMessage());
throw new ImsException($e->getMessage(), $e->getCode(), $e);
}

$stop_time = explode(' ', microtime());
Expand All @@ -113,8 +113,7 @@ protected function sendRequest($faust_number) {
'%response' => print_r($response, TRUE),
'%time' => round($time, 3),
),
WATCHDOG_DEBUG,
$link = NULL
WATCHDOG_DEBUG
);
}

Expand Down