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 [];
} }
return \Pressbooks\Metadata\get_institutions(); return \Pressbooks\Metadata\get_institutions_flattened();
} }
/** /**
* Get institutions currently in use. * Get institutions currently in use.
* *
* @param array $catalog_data Catalog data * @param array $catalog_data Catalog data
* @param array $institutions Institutions
* *
* @return array * @return array
*/ */
function get_available_institutions( array $catalog_data, array $institutions = [] ): array { function get_available_institutions( array $catalog_data ): array {
$institutions = $institutions ?? get_institutions(); $institution_list = get_institutions();
$book_institutions = array_reduce( $catalog_data['books'], static function( $carry, $book ) { $book_institutions = array_reduce( $catalog_data['books'], static function( $carry, $book ) {
$names = array_reduce( $book['metadata']['institutions'] ?? [], static function( $carry, $institution ) { $names = array_reduce( $book['metadata']['institutions'] ?? [], static function( $carry, $institution ) {
return array_merge( $carry, [ $institution['name'] ] ); 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_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(); $licenses = get_catalog_licenses();
$available_licenses = get_available_licenses( $catalog_data ); $available_licenses = get_available_licenses( $catalog_data );
$institutions = get_institutions(); $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() : []; $subjects = ( defined( 'PB_PLUGIN_VERSION' ) ) ? \Pressbooks\Metadata\get_thema_subjects() : [];
$available_subjects = get_available_subjects( $catalog_data ); $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']; return $item['code'];
}, $book['metadata']['institutions'] ?? [] ); }, $book['metadata']['institutions'] ?? [] );
$institution_names = array_map( static function ( $item ) { $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'] ?? [] ); }, $book['metadata']['institutions'] ?? [] );
?> ?>
<li class="book" <li class="book"

Loading…
Cancel
Save