From 7ac2b107dcbebef5d39b0c5d4f4ca3035326a73d Mon Sep 17 00:00:00 2001 From: Gilles Crettenand Date: Thu, 4 Jun 2015 10:50:12 +0200 Subject: [PATCH] Rename method for the website GetLoans and recreate GetCirculations for internal tools --- Lib/db/User.php | 61 +++++++++++++++++++++++++++++++++++++++++++++---- NetBiblio.php | 23 +++++++++++++++---- 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/Lib/db/User.php b/Lib/db/User.php index f546f03..998fd24 100644 --- a/Lib/db/User.php +++ b/Lib/db/User.php @@ -83,7 +83,50 @@ class User extends DbMapping return $results->current() !== false ? new User($results->current()) : null; } - private function _getCirculations($table, $sort = "ItemNr ASC") { + /** + * Circulations as needed for the BSR internal tools + */ + public function GetCirculations() + { + $sql = sprintf("SELECT + n.NoticeID, + ItemNr, + LTRIM(RTRIM(n.NoticeNr)) AS code, + LTRIM(RTRIM(n.Title)) AS Title, + LTRIM(RTRIM(n.Author)) AS author, + Fields.[300] AS media, + Fields.[901] AS readBy + FROM Circulations AS c + INNER JOIN Items AS i ON i.ItemId = c.ItemId + INNER JOIN Notices AS n ON n.NoticeID = i.NoticeID + LEFT OUTER JOIN ( + SELECT * + FROM ( + SELECT + NoticeID, + Tag AS Field, + LTRIM(RTRIM(COALESCE( + NULLIF(NoticeFields.ContentShortPart, ''), + NULLIF(NoticeFields.ContentLongPart, ''), + 'na' + ))) AS Data + FROM NoticeFields + WHERE Tag IN ('901', '300') + ) AS src + PIVOT ( + MIN(Data) + FOR Field IN ([901], [300]) + ) AS pvt + ) Fields ON n.NoticeID = Fields.NoticeID + WHERE + c.UserAccountID = %s + ORDER BY ItemNr ASC", $this->id); + + $result = Connection::execute($sql); + return $result ? $result->to_array() : array(); + } + + private function _getLoans($table, $sort = "ItemNr ASC") { $sql = sprintf("SELECT n.NoticeNr, CheckOutDate, @@ -114,14 +157,22 @@ class User extends DbMapping return $books; } - public function getCirculations() + /** + * Loans (Circulations) as needed on the website + * @return array + */ + public function GetLoans() { - return $this->_getCirculations('Circulations'); + return $this->_getLoans('Circulations'); } - public function getOldCirculations() + /** + * Old loans (OldCirculations) as needed on the website + * @return array + */ + public function GetOldLoans() { - return $this->_getCirculations('OldCirculations', 'CheckOutDate DESC'); + return $this->_getLoans('OldCirculations', 'CheckOutDate DESC'); } /** diff --git a/NetBiblio.php b/NetBiblio.php index f2d6a5f..d1535cb 100644 --- a/NetBiblio.php +++ b/NetBiblio.php @@ -411,15 +411,28 @@ class NetBiblio extends WebService } /** - * This method returns the list of books that are currently let to the - * authenticated user. + * This method returns the list of all Circulations for the currently + * authenticated user in a format suited for BSR internal tools + * (CD engraving for example). * * @return array * @throws AuthenticationException */ public function GetCirculations() { - $circulations = $this->getUser()->getCirculations(); + return $this->getUser()->GetCirculations(); + } + + /** + * This method returns the list of books that are currently lent to the + * authenticated user. + * + * @return array + * @throws AuthenticationException + */ + public function GetLoans() + { + $circulations = $this->getUser()->GetLoans(); return array_values($this->AddBookData($circulations)); } @@ -430,9 +443,9 @@ class NetBiblio extends WebService * @return array * @throws AuthenticationException */ - public function GetOldCirculations() + public function GetOldLoans() { - $circulations = $this->getUser()->getOldCirculations(); + $circulations = $this->getUser()->GetOldLoans(); return array_values($this->AddBookData($circulations)); }