Browse Source

Support new institution structure

pull/309/head
Felipe Dalcin 3 years ago
parent
commit
38d9386671
  1. 15
      partials/book.php
  2. 2
      partials/content-page-catalog.php

15
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 ) : ''; $subject = ( isset( $book['subject'] ) && ! is_bisac( $book['subject'] ) ) ? substr( $book['subject'], 0, 2 ) : '';
$date = ( isset( $book['metadata']['datePublished'] ) ) ? str_replace( '-', '', $book['metadata']['datePublished'] ) : ''; $date = ( isset( $book['metadata']['datePublished'] ) ) ? str_replace( '-', '', $book['metadata']['datePublished'] ) : '';
$institutions = array_reduce( $book['metadata']['institutions'] ?? [], static function ( $carry, $item ) { $institution_codes = array_map( static function ( $item ) {
return array_merge( $carry, [ $item['name'] ] ); 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'] ?? [] );
?> ?>
<li class="book" <li class="book"
<?php <?php
@ -20,7 +23,7 @@ if ( $date ) {
?> ?>
data-date-published="<?php echo $date; ?>"<?php } ?> data-date-published="<?php echo $date; ?>"<?php } ?>
data-license="<?php echo ( new \Pressbooks\Licensing() )->getLicenseFromUrl( $book['metadata']['license']['url'] ); ?>" data-license="<?php echo ( new \Pressbooks\Licensing() )->getLicenseFromUrl( $book['metadata']['license']['url'] ); ?>"
data-institution="<?php echo implode( ',', $institutions ); ?>" data-institution="<?php echo implode( ',', $institution_codes ); ?>"
<?php <?php
if ( ! empty( $subject ) ) { if ( ! empty( $subject ) ) {
?> ?>
@ -45,9 +48,9 @@ if ( $date ) {
<a href="<?php echo network_home_url( "/catalog/#$subject" ) ?>"><?php echo \Pressbooks\Metadata\get_subject_from_thema( $book['subject'] ); ?></a> <a href="<?php echo network_home_url( "/catalog/#$subject" ) ?>"><?php echo \Pressbooks\Metadata\get_subject_from_thema( $book['subject'] ); ?></a>
</p> </p>
<?php } ?> <?php } ?>
<?php if ( $institutions ) : ?> <?php if ( $institution_names ) : ?>
<p class="book__institutions"> <p class="book__institutions">
<?php echo implode( ', ', $institutions ); ?> <?php echo implode( ', ', $institution_names ); ?>
</p> </p>
<?php endif; ?> <?php endif; ?>
<p class="book__read-more"> <p class="book__read-more">

2
partials/content-page-catalog.php

@ -41,7 +41,7 @@
<label for="all-institutions"><?php _e( 'All Institutions', 'pressbooks-aldine' ); ?> <svg class="checked"><use xlink:href="#checkmark" /></svg></label> <label for="all-institutions"><?php _e( 'All Institutions', 'pressbooks-aldine' ); ?> <svg class="checked"><use xlink:href="#checkmark" /></svg></label>
<?php <?php
foreach ( $institutions as $key => $value ) : foreach ( $institutions as $key => $value ) :
if ( in_array( $key, $available_institutions, true ) ) : if ( array_key_exists( $key, $available_institutions ) ) :
?> ?>
<input type="radio" name="institution" id="<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( $institution, $key ); ?>> <input type="radio" name="institution" id="<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( $institution, $key ); ?>>
<label for="<?php echo $key; ?>"><?php echo $value; ?> <svg class="checked"><use xlink:href="#checkmark" /></svg></label> <label for="<?php echo $key; ?>"><?php echo $value; ?> <svg class="checked"><use xlink:href="#checkmark" /></svg></label>

Loading…
Cancel
Save