From 1c5dc40d6de6b21598ca11dd02aae4515dc384cc Mon Sep 17 00:00:00 2001 From: Jason Cooper <scrapheap@heckrothindustries.co.uk> Date: Wed, 6 Sep 2017 15:01:10 +0100 Subject: [PATCH] Added `getAccountBlocks` functionalit to the KohaILSDI ILS Driver. (#1028) --- config/vufind/KohaILSDI.ini | 18 +++++ .../src/VuFind/ILS/Driver/KohaILSDI.php | 73 +++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/config/vufind/KohaILSDI.ini b/config/vufind/KohaILSDI.ini index fcb401786a4..bc5095df685 100755 --- a/config/vufind/KohaILSDI.ini +++ b/config/vufind/KohaILSDI.ini @@ -61,3 +61,21 @@ pickupLocations[] = MAIN ;availableLocations[] = REFERENCEAREA ;availableLocations[] = INTERNET ;availableLocations[] = ONLINE + + +; This section translates Koha's internal block types into strings for on-screen +; display. +[Blocks] +;SUSPENSION = "Account Suspended" +;OVERDUES = "Account Blocked (Overdue Items)" +;MANUAL = "Account Blocked" +;DISCHARGE = "Account Blocked for Discharge" + +; This section lets you choose whether to display block comments based upon the +; blocks type (defaults to false, meaning that the name of the block type will +; be displayed, but not any additional comment information from the database). +[Show_Block_Comments] +;SUSPENSION = false +;OVERDUES = false +;MANUAL = false +;DISCHARGE = false diff --git a/module/VuFind/src/VuFind/ILS/Driver/KohaILSDI.php b/module/VuFind/src/VuFind/ILS/Driver/KohaILSDI.php index 52213208d63..1764a8b8ccc 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/KohaILSDI.php +++ b/module/VuFind/src/VuFind/ILS/Driver/KohaILSDI.php @@ -167,6 +167,32 @@ class KohaILSDI extends \VuFind\ILS\Driver\AbstractBase implements $this->debug("ILS URL: " . $this->ilsBaseUrl); $this->debug("Locations: " . $this->locations); $this->debug("Default Location: " . $this->defaultLocation); + + // Set our default terms for block types + $this->blockTerms = [ + 'SUSPENSION' => 'Account Suspended', + 'OVERDUES' => 'Account Blocked (Overdue Items)', + 'MANUAL' => 'Account Blocked', + 'DISCHARGE' => 'Account Blocked for Discharge', + ]; + + // Now override the default with any defined in the `KohaILSDI.ini` config + // file + foreach (['SUSPENSION','OVERDUES','MANUAL','DISCHARGE'] as $blockType) { + if (!empty($this->config['Blocks'][$blockType])) { + $this->blockTerms[$blockType] = $this->config['Blocks'][$blockType]; + } + } + + // Allow the users to set if an account block's comments should be included + // by setting the block type to true or false () in the `KohaILSDI.ini` + // config file (defaults to false if not present) + $this->showBlockComments = []; + + foreach (['SUSPENSION','OVERDUES','MANUAL','DISCHARGE'] as $blockType) { + $this->showBlockComments[$blockType] + = !empty($this->config['Show_Block_Comments'][$blockType]); + } } /** @@ -1269,6 +1295,53 @@ class KohaILSDI extends \VuFind\ILS\Driver\AbstractBase implements } } + /** + * Check whether the patron has any blocks on their account. + * + * @param array $patron Patron data from patronLogin + * + * @throws ILSException + * + * @return mixed A boolean false if no blocks are in place and an array + * of block reasons if blocks are in place + */ + public function getAccountBlocks($patron) + { + $blocks = []; + + try { + if (!$this->db) { + $this->initDb(); + } + $id = $patron['id']; + $sql = "select type as TYPE, comment as COMMENT " . + "from borrower_debarments " . + "where (expiration is null or expiration >= NOW()) " . + "and borrowernumber = :id"; + $sqlStmt = $this->db->prepare($sql); + $sqlStmt->execute([':id' => $id]); + + foreach ($sqlStmt->fetchAll() as $row) { + $block = empty($this->blockTerms[$row['TYPE']]) + ? [$row['TYPE']] + : [$this->blockTerms[$row['TYPE']]]; + + if (!empty($this->showBlockComments[$row['TYPE']]) + && !empty($row['COMMENT']) + ) { + $block[] = $row['COMMENT']; + } + + $blocks[] = implode(' - ', $block); + } + } + catch (PDOException $e) { + throw new ILSException($e->getMessage()); + } + + return count($blocks) ? $blocks : false; + } + /** * Get Patron Transactions * -- GitLab