ppound
2 years ago
commit
3df89736bf
5 changed files with 161 additions and 0 deletions
@ -0,0 +1,82 @@
|
||||
<?php |
||||
|
||||
namespace Drupal\upei_roblib_reserves\Plugin\Block; |
||||
|
||||
use Drupal\Core\Block\BlockBase; |
||||
|
||||
/** |
||||
* Provides a Reserves Block base on Evergreen bookbags. |
||||
* |
||||
* @Block( |
||||
* id = "upei_roblib_reserves_block", |
||||
* admin_label = @Translation("Roblib Reserves Block"), |
||||
* category = @Translation("UPEI Roblib"), |
||||
* ) |
||||
*/ |
||||
class ReserveBlock extends BlockBase { |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function build() { |
||||
$html = $this->getReserves(); |
||||
if (empty($html)) { |
||||
return ''; |
||||
} |
||||
|
||||
return [ |
||||
'#theme' => 'upei_roblib_reserves_block', |
||||
'#atom_to_html' => [ |
||||
'#markup' => $html, |
||||
], |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function getCacheMaxAge() { |
||||
//Reading dynamic content from external source so no caching. |
||||
return 0; |
||||
} |
||||
|
||||
/** |
||||
* Queries Evergreen for an Atom XML feed based on book bag list. |
||||
* |
||||
* @return string |
||||
* HTML created from Atom XML feed. |
||||
*/ |
||||
protected function getReserves() { |
||||
$node = \Drupal::routeMatch()->getParameter('node'); |
||||
|
||||
$html = ''; |
||||
if ($node && $node instanceof \Drupal\node\NodeInterface && $node->bundle() == 'course_reserve') { |
||||
$book_bag_id = (string) $node->field_bookbag_id->value; |
||||
if (empty($book_bag_id)) { |
||||
return ''; |
||||
} |
||||
//The evergreen ILS base URL. |
||||
$book_bag_base_url = 'http://islandpines.roblib.upei.ca/opac/extras/feed/bookbag/atom-full/'; |
||||
try { |
||||
$response = \Drupal::httpClient()->get($book_bag_base_url . $book_bag_id); |
||||
$atom = (string) $response->getBody(); |
||||
if (empty($atom)) { |
||||
return ''; |
||||
} |
||||
} |
||||
catch (RequestException $e) { |
||||
return ''; |
||||
} |
||||
$path = \Drupal::service('extension.list.module')->getPath('upei_roblib_reserves'); |
||||
$xslt = new \XSLTProcessor(); |
||||
$xsl = new \DOMDocument(); |
||||
$xsl->load($path . '/xsl/atom2html.xsl'); |
||||
$xslt->importStylesheet($xsl); |
||||
$xml = new \DomDocument(); |
||||
$xml->loadXML($atom); |
||||
$html = $xslt->transformToXML($xml); |
||||
} |
||||
return $html; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,5 @@
|
||||
|
||||
{% if atom_to_html %} |
||||
<h3>Materials Available from the Service Desk</h3> |
||||
<div class="upei-roblib-reserves">{{ atom_to_html }}</div> |
||||
{% endif %} |
@ -0,0 +1,4 @@
|
||||
name: UPEI Robertson Library Reserves Module |
||||
type: module |
||||
core_version_requirement: ^9 || ^10 |
||||
description: A module to consume a bookbag from evergreen and display the results in Drupal |
@ -0,0 +1,14 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* Implements hook_theme(). |
||||
*/ |
||||
function upei_roblib_reserves_theme($existing, $type, $theme, $path): array { |
||||
return [ |
||||
'upei_roblib_reserves_block' => [ |
||||
'variables' => [ |
||||
'atom_to_html' => NULL, |
||||
], |
||||
], |
||||
]; |
||||
} |
@ -0,0 +1,56 @@
|
||||
|
||||
<xsl:stylesheet |
||||
version="1.0" |
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
||||
xmlns:atom="http://www.w3.org/2005/Atom" |
||||
xmlns:v1="http://open-ils.org/spec/holdings/v1" |
||||
exclude-result-prefixes="atom v1" |
||||
> |
||||
<xsl:output encoding="utf-8" indent="yes" method="html"/> |
||||
<xsl:variable name="opac_link" |
||||
select="/atom:feed/atom:entry/atom:link[@rel='opac']"/> |
||||
<xsl:template match="/"> |
||||
<xsl:apply-templates select="atom:feed/atom:entry"/> |
||||
</xsl:template> |
||||
|
||||
<xsl:template match="atom:entry"> |
||||
<xsl:for-each select="."> |
||||
<div class="atom-entry"> |
||||
<div class="atom-title"> |
||||
<a> |
||||
<xsl:attribute name='href'> |
||||
<xsl:value-of |
||||
select="atom:link[@rel='opac']/@href"/> |
||||
</xsl:attribute> |
||||
<xsl:value-of select="atom:title"/> |
||||
</a> |
||||
</div> |
||||
<div class="atom-publication-date"> |
||||
Publication date: |
||||
<xsl:value-of select="atom:published"/> |
||||
</div> |
||||
<div class="atom-author">Authors: |
||||
<ul class="atom-list"> |
||||
<xsl:for-each select="atom:author/atom:name"> |
||||
<li class="atom-list-item"> |
||||
<xsl:value-of select="."/> |
||||
</li> |
||||
</xsl:for-each> |
||||
</ul> |
||||
</div> |
||||
<div class="atom-holdings">Holdings: |
||||
<ul class="atom-list"> |
||||
<xsl:for-each select="v1:holdings/v1:volumes/v1:volume/v1:copies/v1:copy"> |
||||
<li class="atom-available"> |
||||
<xsl:value-of select="v1:location"/><xsl:text> </xsl:text> |
||||
(<xsl:value-of select="v1:status"/>) |
||||
</li> |
||||
|
||||
</xsl:for-each> |
||||
</ul> |
||||
</div> |
||||
</div> |
||||
<br/> |
||||
</xsl:for-each> |
||||
</xsl:template> |
||||
</xsl:stylesheet> |
Loading…
Reference in new issue