Skip to content
This repository was archived by the owner on May 2, 2018. It is now read-only.

Commit 5898133

Browse files
committed
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 1919aa3. Conflicts: includes/alma.availability.inc
1 parent 4199bb2 commit 5898133

File tree

3 files changed

+95
-197
lines changed

3 files changed

+95
-197
lines changed

alma.module

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,18 @@ function alma_client_invoke($method) {
174174
$args = func_get_args();
175175
array_shift($args); // Lose the method.
176176
$client = alma_client();
177+
177178
try {
178179
$result = call_user_func_array(array($client, $method), $args);
179180
}
180181
catch (Exception $e) {
181182
watchdog('alma', '@method error: “@message”', array('@method' => $method, '@message' => $e->getMessage()), WATCHDOG_ERROR);
182183
throw $e;
183184
}
185+
184186
return $result;
185187
}
188+
186189
/**
187190
* Get the complete organisation info from Alma.
188191
*

includes/alma.availability.inc

Lines changed: 91 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -1,230 +1,125 @@
11
<?php
2-
32
/**
43
* Implements provider availability, holdings.
54
*/
6-
75
function alma_availability_holdings($provider_ids) {
86
$ids = join(',', $provider_ids);
9-
7+
8+
$holding_parts = array('branch', 'department', 'location', 'sublocation', 'collection');
109
$details = alma_client_invoke('catalogue_record_detail', $ids);
10+
$org = alma_get_organisation();
1111
$result = array();
12-
1312
if ($details && isset($details['records'])) {
1413
foreach ($details['records'] as $alma_id => $record) {
1514
$holding = array(
1615
'local_id' => $alma_id,
1716
'available' => ($record['available_count'] > 0),
1817
'reservable' => $record['show_reservation_button'],
1918
'show_reservation_button' => $record['show_reservation_button'],
20-
'holdings' => array(),
21-
'holdings_available' => array(),
2219
'reserved_count' => (int) $record['reservation_count'],
23-
'total_count' => _alma_count_total($record['holdings'], $record['media_class'] == 'periodical'),
2420
'deferred_period' => FALSE,
25-
'issues' => array(),
26-
'is_periodical' => ($record['media_class'] == 'periodical'),
21+
22+
'is_periodical' => ($record['media_class'] == 'periodical'),
2723
);
28-
29-
$result[$alma_id] = $holding;
30-
31-
if($holding['is_periodical']){
32-
$result[$alma_id]['html'] = _alma_get_holdings($details, TRUE);
33-
}
34-
else{
35-
$result[$alma_id]['html'] = _alma_get_holdings($details, FALSE);
36-
}
37-
}
38-
}
39-
return $result;
40-
41-
}
4224

43-
/**
44-
* @param type $holdings; array containing holding informations
45-
* @param type $is_periodical; Boolean that indicates whether the shown record is a periodical or not
46-
* @return sum of all total_count in $holdings
47-
*/
48-
function _alma_count_total($holdings, $is_periodical) {
49-
$total = 0;
50-
if ($is_periodical) {
51-
foreach ($holdings as $year => $issues) {
52-
foreach ($issues as $issue) {
53-
foreach ($issue as $holding) {
54-
$total += $holding['total_count'];
25+
$total = $total_reservable = 0;
26+
27+
// START periodicals
28+
if( $holding['is_periodical'] ) {
29+
$parts = array();
30+
$holding['holdings'] = array();
31+
foreach( $record['holdings'] as $volume => $issues ) {
32+
foreach($issues as $issue_no => $holds){
33+
$issue = array();
34+
$issue['branches'] = array();
35+
foreach( $holds as $key => $branch_holding) {
36+
37+
if( !in_array( $branch_holding['branch_id'], $issue['branches'] ) ) {
38+
$issue['branches'][] = $branch_holding['branch_id'];
39+
}
40+
41+
$issue['local_id'] = $branch_holding['reservable'];
42+
$issue['reservable'] = (($branch_holding['status'] == 'availableForLoan') &&
43+
((int) $branch_holding['total_count'] - (int) $branch_holding['reference_count']));
44+
$issues_array[$volume][$issue_no] = $issue;
45+
46+
if (in_array($branch_holding['collection_id'], array('karens', 'karens-'))) {
47+
$holding['deferred_period'] = TRUE;
48+
}
49+
50+
$parts = array();
51+
$total += (int) $branch_holding['total_count'];
52+
// Reservable is total items minus reference (which cannot be
53+
// loaned).
54+
$reservable = (int) $branch_holding['total_count'] - (int) $branch_holding['reference_count'];
55+
$total_reservable += $reservable;
56+
foreach ($holding_parts as $part) {
57+
if (!empty($branch_holding[$part . '_id'])) {
58+
$parts[] = $org[$part][$branch_holding[$part . '_id']];
59+
}
60+
}
61+
62+
if (!empty($branch_holding['shelf_mark'])) {
63+
// Shelf mark might have leading >, strip any and replace the rest
64+
// with the proper arrow.
65+
$parts[] = strtr(trim($branch_holding['shelf_mark'], " >\n\t"), array('>' => ''));
66+
}
67+
68+
$parts = array_filter($parts);
69+
70+
if ($parts && $branch_holding['total_count'] > $branch_holding['checked_out_count']) {
71+
$branch_string = join('', $parts);
72+
$holding['holdings_available'][] = $branch_string;
73+
if( !in_array($branch_string,$holding['holdings']) ) {
74+
$holding['holdings'][] = $branch_string;
75+
}
76+
}
5577
}
5678
}
5779
}
58-
}
59-
else {
60-
foreach ($holdings as $holding) {
61-
$total += $holding['total_count'];
80+
if( is_array($holding['holdings']) ) {
81+
asort($holding['holdings']);
6282
}
63-
}
64-
return $total;
65-
}
83+
$holding['issues'] = $issues_array;
84+
} // END periodicals
6685

67-
/**
68-
* @param type $res; returned array from alma_client class
69-
* @param type $is_periodical; Boolean that indicates whether the shown record is a periodical or not
70-
* @return html to be shown. Returns FALSE if no data is received from alma_client class
71-
*/
72-
function _alma_get_holdings($res, $is_periodical = FALSE) {
73-
if(isset($res['records'])) {
74-
if($is_periodical){
75-
return _alma_set_holdings_periodical($res);
76-
}
77-
else {
78-
return _alma_set_holdings($res);
79-
}
80-
}
81-
else {
82-
return FALSE;
83-
}
84-
}
86+
else {
87+
foreach ($record['holdings'] as $branch_holding) {
88+
if (in_array($branch_holding['collection_id'], array('karens', 'karens-'))) {
89+
$holding['deferred_period'] = TRUE;
90+
}
8591

86-
/**
87-
* set holdings for all kinds of material except periodicals
88-
* @param array $res
89-
* @return array $result;
90-
*/
91-
function _alma_set_holdings($res) {
92-
$holdings = array();
93-
foreach ($res['records'] as $alma_id => $records) {
94-
foreach ($records['holdings'] as $holding) {
95-
$holdings[] = $holding;
96-
}
97-
}
98-
99-
$result = _alma_set_table_html($holdings);
100-
return $result;
101-
}
92+
$parts = array();
93+
$total += (int) $branch_holding['total_count'];
94+
// Reservable is total items minus reference (which cannot be
95+
// loaned).
96+
$reservable = (int) $branch_holding['total_count'] - (int) $branch_holding['reference_count'];
97+
$total_reservable += $reservable;
98+
foreach ($holding_parts as $part) {
99+
if (!empty($branch_holding[$part . '_id'])) {
100+
$parts[] = $org[$part][$branch_holding[$part . '_id']];
101+
}
102+
}
102103

103-
/**
104-
* set holdings if material is periodical only
105-
* @param array $res
106-
* @return array $result
107-
*/
108-
function _alma_set_holdings_periodical($res){
109-
$holdings = array();
110-
foreach ($res['records'] as $alma_id => $records) {
111-
foreach ($records['holdings'] as $holding => $issue_year) {
112-
foreach ($issue_year as $key) {
113-
$holdings[] = $key[0];
104+
if (!empty($branch_holding['shelf_mark'])) {
105+
// Shelf mark might have leading >, strip any and replace the rest
106+
// with the proper arrow.
107+
$parts[] = strtr(trim($branch_holding['shelf_mark'], " >\n\t"), array('>' => ''));
114108
}
115-
}
116-
}
117-
118-
$result = _alma_set_table_html($holdings);
119-
return $result;
120-
}
121-
/**
122-
* Make the html-table
123-
* @params $h; holding information for a given material
124-
* @return html-table
125-
*/
126-
function _alma_set_table_html(&$h) {
127-
// set a classname for styling the table
128-
$variables['attributes']=
129-
array('class'=>array(drupal_html_class('availability_holdings_table')));
130-
// set table header
131-
$variables['header'] =
132-
array('placement'=>t('Placement'), 'copies'=>t('Copies'), 'Home'=>t('At home'),'reservations'=>t('Reservations'));
133-
// set table rows
134-
$variables['rows'] = _alma_set_rows($h);
135-
// theme the table
136-
// @TODO; move this to ding_availability ??
137-
$html = theme('table',$variables );
138-
139-
return $html;
140-
}
141109

142-
/**
143-
* set rows in table for given holdings
144-
* @param $h; holding information for a given material
145-
* @return array;
146-
*/
147-
function _alma_set_rows($h) {
148-
$rows = array();
149-
$org = alma_get_organisation();
150-
151-
$copies_total = 0;
152-
$home_total = 0;
153-
$reservations_total = 0;
154-
foreach ($h as $key => $data) {
155-
$row = array();
156-
$row['placement'] = $org['branch'][$data['branch_id']];
157-
$row['copies'] = (int) $data['total_count'];
158-
$copies_total += $row['copies'];
159-
$row['home'] = (int) $data['available_count'];
160-
$home_total += $row['home'];
161-
$row['reservations'] = (int) $data['ordered_count'];
162-
$reservations_total += $row['reservations'];
163-
$rows[] = $row;
164-
}
165-
166-
if(count($rows) >= 1){
167-
$rows = _clean_up_rows($rows);
168-
}
169-
//Adding last row - totals
170-
$row = array();
171-
$row['data']['Library'] = t('Total');
172-
$row['data']['Copies'] = $copies_total;
173-
$row['data']['Home'] = $home_total;
174-
$row['data']['Reservations'] = $reservations_total;
175-
$row['class'] = array(drupal_html_class('availability_holdings_last_row'));
176-
$rows[] = $row;
177-
return $rows;
178-
}
110+
$parts = array_filter($parts);
179111

180-
/**
181-
* if the same placement exists several times collect them in one line
182-
* @param array
183-
* @return array;
184-
*/
185-
function _clean_up_rows($_rows) {
186-
$rows = array();
187-
$placements = array();
188-
189-
foreach ($_rows as $row) {
190-
$currkey = $row['placement'];
191-
if(!in_array($currkey, $placements)){
192-
$placements[] = $currkey;
193-
$placementsarr = _get_placements_with_key($_rows, $currkey);
194-
$this_row = _sum_placement($placementsarr);
195-
$rows[] = $this_row;
112+
if ($parts && $branch_holding['total_count'] > $branch_holding['checked_out_count']) {
113+
$holding['holdings'][] = join('', $parts);
114+
}
196115
}
197-
}
198-
return $rows;
199-
}
116+
}
200117

201-
/**
202-
* collect materials with the same placement
203-
* @param array $_rows
204-
* @param String $currkey
205-
* @return array $rows;
206-
*/
207-
function _get_placements_with_key($_rows, $currkey){
208-
$rows = array();
209-
foreach ($_rows as $key) {
210-
if($key['placement'] == $currkey){
211-
$rows[] = $key;
118+
$holding['reservable_count'] = $total_reservable;
119+
$holding['total_count'] = $total;
120+
$result[$alma_id] = $holding;
212121
}
213122
}
214-
return $rows;
215-
}
216-
/**
217-
* sum material for same placement in one row
218-
* @param $placementsarr; array with all instances of the same placement - ie. 'Hovedbiblioteket'
219-
* @return array; $row
220-
*/
221-
function _sum_placement($placementsarr){
222-
$row = $placementsarr[0];
223-
for($i = 1; $i < count($placementsarr);$i++){
224-
$next_row = $placementsarr[$i];
225-
$row['copies'] += $next_row['copies'];
226-
$row['home'] += $next_row['home'];
227-
$row['reservations'] += $next_row['reservations'];
228-
}
229-
return $row;
123+
124+
return $result;
230125
}

lib/AlmaClient/AlmaClient.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ public function catalogue_record_detail($alma_ids) {
656656
'request_status' => $doc->getElementsByTagName('status')->item(0)->getAttribute('value'),
657657
'records' => array(),
658658
);
659+
659660
foreach ($doc->getElementsByTagName('detailCatalogueRecord') as $elem) {
660661
$record = AlmaClient::process_catalogue_record_details($elem);
661662
$data['records'][$record['alma_id']] = $record;
@@ -776,7 +777,6 @@ private static function process_catalogue_record_holdings($elem) {
776777
);
777778
}
778779

779-
780780
return $holdings;
781781
}
782782

0 commit comments

Comments
 (0)