From 51688c48ee2d6b5fdc3f02a924feb9893e47fea0 Mon Sep 17 00:00:00 2001 From: Felipe Dalcin Date: Tue, 15 Feb 2022 15:13:21 -0300 Subject: [PATCH] feat: support institutions changes (#316) --- inc/helpers/namespace.php | 9 ++++----- page-catalog.php | 2 +- partials/book.php | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/inc/helpers/namespace.php b/inc/helpers/namespace.php index 8b74d33..4a97d51 100644 --- a/inc/helpers/namespace.php +++ b/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 ); } /** diff --git a/page-catalog.php b/page-catalog.php index 43b8582..8ad195b 100644 --- a/page-catalog.php +++ b/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 ); diff --git a/partials/book.php b/partials/book.php index cd920b7..99724d4 100644 --- a/partials/book.php +++ b/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'] ?? [] ); ?>