also add date to books when not already set, also try to keep files from solr when available
This commit is contained in:
@@ -254,9 +254,47 @@ class NetBiblio extends WebService
|
|||||||
return reset($result);
|
return reset($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ids = array_map(function($b) { return $b['code']; }, $books);
|
// add complementary data to each book
|
||||||
|
$books = array_map(function($b) {
|
||||||
|
// add files if we already have them
|
||||||
|
$files = array();
|
||||||
|
$samples = array();
|
||||||
|
foreach(array('mp3', 'ogg') as $ext) {
|
||||||
|
$k = 'sample_'.$ext;
|
||||||
|
if(isset($b[$k]) && strlen($b[$k]) > 0) {
|
||||||
|
$samples[] = $b[$k];
|
||||||
|
}
|
||||||
|
unset($b[$k]);
|
||||||
|
}
|
||||||
|
if(! empty($samples)) {
|
||||||
|
$files['samples'] = $samples;
|
||||||
|
}
|
||||||
|
if(isset($b['zip']) && strlen($b['zip']) > 0) {
|
||||||
|
$files['zip'] = $b['zip'];
|
||||||
|
unset($b['zip']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(! empty($files)) {
|
||||||
|
$b['files'] = $files;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add date if we have an availabilityDate for Mobile apps compatibility
|
||||||
|
if(! isset($b['date']) && isset($b['availabilityDate'])) {
|
||||||
|
$b['date'] = date('Y.m.d', strtotime($b['availabilityDate']));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $b;
|
||||||
|
}, $books);
|
||||||
|
|
||||||
|
// retrieve files information for the book that don't have any at this time
|
||||||
|
$booksWithoutFiles = array_filter($books, function($b) {
|
||||||
|
return ! isset($b['files']);
|
||||||
|
});
|
||||||
|
|
||||||
|
$ids = array_map(function($b) { return $b['code']; }, $booksWithoutFiles);
|
||||||
$files = $this->GetFiles($ids);
|
$files = $this->GetFiles($ids);
|
||||||
foreach($books as $k => $b) {
|
|
||||||
|
foreach($booksWithoutFiles as $k => $b) {
|
||||||
if(isset($files[$b['code']])) {
|
if(isset($files[$b['code']])) {
|
||||||
$books[$k]['files'] = $files[$b['code']];
|
$books[$k]['files'] = $files[$b['code']];
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user