This commit is contained in:
SIMON_\Simon
2018-09-05 17:34:53 +02:00
parent ddaf517579
commit 34acb97743
7 changed files with 79 additions and 27 deletions

View File

@@ -1,8 +1,10 @@
<?php
namespace BSR\Lib\db;
use BSR\Lib\Configuration;
use BSR\Lib\Search\BookSearch;
use BSR\Lib\Logger;
/**
* User is mapped on the UserAccounts table. Contains user information : id, login, firstName, lastName, displayName.
@@ -76,7 +78,7 @@ class User extends DbMapping
REPLACE(UserAccountNr, ' ', '') AS login
FROM [UserAccounts] AS u
LEFT JOIN [Addresses] AS a ON a.[AddressID] = u.[ActualAddressID]
WHERE LTRIM(RTRIM(UserAccountNr)) = '%s' AND disabled = 1 %s;",
WHERE LTRIM(RTRIM(UserAccountNr)) = '%s' AND disabled = 1 %s AND CategoryCode in ('A', 'M', 'G', 'D', 'I', 'EMP');",
$login, $cond);
$results = Connection::execute($sql, $raiseError);
@@ -122,18 +124,36 @@ class User extends DbMapping
return $result ? $result->to_array() : array();
}
public function getLoansData($table, $sort = "ItemNr ASC")
public function GetOldLoansNrs()
{
$sql = sprintf("SELECT
n.NoticeId,
n.NoticeNr,
CheckOutDate,
ItemNr
FROM %s AS c
n.NoticeNr
FROM OldCirculations AS c
INNER JOIN Items AS i ON i.ItemId = c.ItemId
INNER JOIN Notices AS n ON n.NoticeID = i.NoticeID
WHERE
c.UserAccountID = %s
c.UserAccountID = %s AND
n.MediaType1Code in ('CDD', 'CDA', 'DVD', 'CDS') AND n.deleted=1
ORDER BY ItemNr ASC", $this->id);
$result = Connection::execute($sql);
return $result ? $result->to_array() : array();
}
public function getLoansData($table, $sort = "acquisitiondate DESC")
{
$sql = sprintf("SELECT top 50
realn.NoticeId as NoticeID,
realn.NoticeNr,
CheckOutDate,
c.Remark,
ItemNr
FROM %s AS c
INNER JOIN Items AS i ON i.ItemId = c.ItemId
INNER JOIN Notices AS lentn ON lentn.NoticeID = i.NoticeID
INNER JOIN Notices AS realn ON REPLACE(ltrim(rtrim(lentn.noticenr)), 'V', '') = ltrim(rtrim(realn.noticenr))
WHERE
c.UserAccountID = %s
ORDER BY %s", $table, $this->id, $sort);
return Connection::execute($sql)->to_array();
@@ -142,20 +162,23 @@ class User extends DbMapping
private function _getLoans($table, $count, $sort)
{
$circulations = $this->getLoansData($table, $sort);
//Logger::log(print_r($circulations, true));
// getting the intval of the NoticeNr will remove any 'V' or 'T' and thus we will have no issues with
// the virtual books that are used for Downloads and so.
$codes = array_unique(array_map(function($c) { return intval(trim($c['NoticeNr'])); }, $circulations));
$codes = array_unique(array_map(function($c) {
return trim($c['NoticeNr']); }, $circulations));
if($count) {
return count($circulations);
}
$books = count($codes) > 0 ? BookSearch::GetBooks($codes) : array();
//Logger::log(print_r($books, true));
foreach($circulations as $c) {
$id = $c['NoticeID'];
if(isset($books[$id])) {
$books[$id]['date'] = $c['CheckOutDate'];
$books[$id]['itemNr'] = $c['ItemNr'];
$books[$id]['checkoutDate'] = $c['CheckOutDate'];
$books[$id]['remark'] = $c['Remark'];
}
}
@@ -194,7 +217,6 @@ class User extends DbMapping
INNER JOIN Notices AS n ON n.NoticeID = i.NoticeID
WHERE
c.UserAccountID = %s
AND DATEDIFF(week, CheckOutDate, GETDATE()) > 1
AND DATEDIFF(month, CheckOutDate, GETDATE()) < 5
", $this->id);