Browse Source

feat: support institutions changes (#316)

pull/318/head
Felipe Dalcin 3 years ago committed by GitHub
parent
commit
51688c48ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      inc/helpers/namespace.php
  2. 2
      page-catalog.php
  3. 2
      partials/book.php

9
inc/helpers/namespace.php

@ -158,19 +158,18 @@ function get_institutions(): array {
return [];
}
return \Pressbooks\Metadata\get_institutions();
return \Pressbooks\Metadata\get_institutions_flattened();
}
/**
* Get institutions currently in use.
*
* @param array $catalog_data Catalog data
* @param array $institutions Institutions
*
* @return array
*/
function get_available_institutions( array $catalog_data, array $institutions = [] ): array {
$institutions = $institutions ?? get_institutions();
function get_available_institutions( array $catalog_data ): array {
$institution_list = get_institutions();
$book_institutions = array_reduce( $catalog_data['books'], static function( $carry, $book ) {
$names = array_reduce( $book['metadata']['institutions'] ?? [], static function( $carry, $institution ) {
return array_merge( $carry, [ $institution['name'] ] );
@ -179,7 +178,7 @@ function get_available_institutions( array $catalog_data, array $institutions =
return array_merge( $carry, $names );
}, [] );
return array_intersect( $institutions, $book_institutions );
return array_intersect( $institution_list, $book_institutions );
}
/**

2
page-catalog.php

@ -27,7 +27,7 @@ $next_page = $current_page + 1;
$licenses = get_catalog_licenses();
$available_licenses = get_available_licenses( $catalog_data );
$institutions = get_institutions();
$available_institutions = get_available_institutions( $catalog_data, $institutions );
$available_institutions = get_available_institutions( $catalog_data );
$subjects = ( defined( 'PB_PLUGIN_VERSION' ) ) ? \Pressbooks\Metadata\get_thema_subjects() : [];
$available_subjects = get_available_subjects( $catalog_data );

2
partials/book.php

@ -14,7 +14,7 @@ $institution_codes = array_map( static function ( $item ) {
return $item['code'];
}, $book['metadata']['institutions'] ?? [] );
$institution_names = array_map( static function ( $item ) {
return \Pressbooks\Metadata\get_institution_by_code( $item['code'] );
return \Pressbooks\Metadata\get_institution_name( $item['code'] );
}, $book['metadata']['institutions'] ?? [] );
?>
<li class="book"

Loading…
Cancel
Save