From 38d93866717757f0cd88023d782db36fe560f52e Mon Sep 17 00:00:00 2001 From: Felipe Dalcin Date: Thu, 20 Jan 2022 18:30:31 -0300 Subject: [PATCH] Support new institution structure --- partials/book.php | 15 +++++++++------ partials/content-page-catalog.php | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/partials/book.php b/partials/book.php index 47bc02a..cd920b7 100644 --- a/partials/book.php +++ b/partials/book.php @@ -10,9 +10,12 @@ use function \Pressbooks\Metadata\is_bisac; $subject = ( isset( $book['subject'] ) && ! is_bisac( $book['subject'] ) ) ? substr( $book['subject'], 0, 2 ) : ''; $date = ( isset( $book['metadata']['datePublished'] ) ) ? str_replace( '-', '', $book['metadata']['datePublished'] ) : ''; -$institutions = array_reduce( $book['metadata']['institutions'] ?? [], static function ( $carry, $item ) { - return array_merge( $carry, [ $item['name'] ] ); -}, [] ); +$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'] ); +}, $book['metadata']['institutions'] ?? [] ); ?>
  • data-date-published="" data-license="getLicenseFromUrl( $book['metadata']['license']['url'] ); ?>" - data-institution="" + data-institution="" @@ -45,9 +48,9 @@ if ( $date ) { ">

    - +

    - +

    diff --git a/partials/content-page-catalog.php b/partials/content-page-catalog.php index 79bfb29..8396ff5 100644 --- a/partials/content-page-catalog.php +++ b/partials/content-page-catalog.php @@ -41,7 +41,7 @@ $value ) : - if ( in_array( $key, $available_institutions, true ) ) : + if ( array_key_exists( $key, $available_institutions ) ) : ?> >