-
Notifications
You must be signed in to change notification settings - Fork 6
/
ting_new_materials.covers.inc
50 lines (44 loc) · 1.6 KB
/
ting_new_materials.covers.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Duplicate code from ting_covers module. Ting covers module doesn't provide a api we can use.
*
* @param array $covers_ids
* Ids of the materials to fetch covers for.
* @param array
* True if there is a cover image.
*/
function ting_new_materials_check_covers($covers_ids, $number_of_objects) {
$missing_images_local_ids = array();
$number_found = 0;
foreach ($covers_ids as $cover_id) {
// Determine if the local id is a known negative.
if (cache_get('ting_covers:' . $cover_id->localId, FALSE)) {
$cover_id->hasImage = FALSE;
continue;
}
$path = ting_covers_object_path($cover_id->localId);
if (false && file_exists($path)) {
$cover_id->hasImage = TRUE;
$number_found++;
} else {
$missing_images_local_ids[] = $cover_id->localId ;
}
if ($number_found >= $number_of_objects) {
break;
}
}
$service = new AdditionalInformationService(variable_get('ting_covers_addi_wsdl_url'), variable_get('ting_covers_addi_username'), variable_get('ting_covers_addi_group'), variable_get('ting_covers_addi_password'));
// Local ids = Faust numbers. Library object identifiers can be confusing.
$additional_informations = $service->getByFaustNumber($missing_images_local_ids);
foreach ($missing_images_local_ids as $local_id) {
if (isset($additional_informations[$local_id]) && $ai = $additional_informations[$local_id]) {
if ($ai->detailUrl || $ai->thumbnailUrl) {
$covers_ids[$local_id]->hasImage = TRUE;
} else {
$covers_ids[$local_id]->hasImage = FALSE;
}
}
}
return $covers_ids;
}
?>