commit 3df89736bf118d08b048fd196a7cc3e9f6a342b9 Author: ppound Date: Fri Mar 3 09:56:01 2023 -0400 initial commit diff --git a/src/Plugin/Block/ReserveBlock.php b/src/Plugin/Block/ReserveBlock.php new file mode 100644 index 0000000..82956d0 --- /dev/null +++ b/src/Plugin/Block/ReserveBlock.php @@ -0,0 +1,82 @@ +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; + } + +} diff --git a/templates/upei-roblib-reserves-block.html.twig b/templates/upei-roblib-reserves-block.html.twig new file mode 100644 index 0000000..fdf6c2b --- /dev/null +++ b/templates/upei-roblib-reserves-block.html.twig @@ -0,0 +1,5 @@ + +{% if atom_to_html %} +

Materials Available from the Service Desk

+
{{ atom_to_html }}
+{% endif %} \ No newline at end of file diff --git a/upei_roblib_reserves.info.yml b/upei_roblib_reserves.info.yml new file mode 100644 index 0000000..1f4afe0 --- /dev/null +++ b/upei_roblib_reserves.info.yml @@ -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 diff --git a/upei_roblib_reserves.module b/upei_roblib_reserves.module new file mode 100644 index 0000000..c3456ce --- /dev/null +++ b/upei_roblib_reserves.module @@ -0,0 +1,14 @@ + [ + 'variables' => [ + 'atom_to_html' => NULL, + ], + ], + ]; +} diff --git a/xsl/atom2html.xsl b/xsl/atom2html.xsl new file mode 100644 index 0000000..0e3c41b --- /dev/null +++ b/xsl/atom2html.xsl @@ -0,0 +1,56 @@ + + + + + + + + + + +
+ +
+ Publication date: + +
+
Authors: +
    + +
  • + +
  • +
    +
+
+
Holdings: +
    + +
  • + + () +
  • + +
    +
+
+
+
+
+
+
\ No newline at end of file