Rename method for the website GetLoans and recreate GetCirculations for internal tools

master
Gilles Crettenand 11 years ago
parent d25f4f7ceb
commit 7ac2b107dc

@ -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');
}
/**

@ -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));
}

Loading…
Cancel
Save