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

This commit is contained in:
Gilles Crettenand
2015-06-04 10:50:12 +02:00
parent d25f4f7ceb
commit 7ac2b107dc
2 changed files with 74 additions and 10 deletions

View File

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