add a specific method to speed up Dashboard display
This commit is contained in:
@@ -139,12 +139,16 @@ class User extends DbMapping
|
||||
return Connection::execute($sql)->to_array();
|
||||
}
|
||||
|
||||
private function _getLoans($table, $sort = "ItemNr ASC")
|
||||
private function _getLoans($table, $count, $sort)
|
||||
{
|
||||
$circulations = $this->getLoansData($table, $sort);
|
||||
// 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));
|
||||
if($count) {
|
||||
return count($circulations);
|
||||
}
|
||||
|
||||
$books = count($codes) > 0 ? BookSearch::GetBooks($codes) : array();
|
||||
|
||||
foreach($circulations as $c) {
|
||||
@@ -160,20 +164,22 @@ class User extends DbMapping
|
||||
|
||||
/**
|
||||
* Loans (Circulations) as needed on the website
|
||||
* @param boolean $count return only the count
|
||||
* @return array
|
||||
*/
|
||||
public function GetLoans()
|
||||
public function GetLoans($count = false)
|
||||
{
|
||||
return $this->_getLoans('Circulations');
|
||||
return $this->_getLoans('Circulations', $count, "ItemNr ASC");
|
||||
}
|
||||
|
||||
/**
|
||||
* Old loans (OldCirculations) as needed on the website
|
||||
* @param boolean $count return only the count
|
||||
* @return array
|
||||
*/
|
||||
public function GetOldLoans()
|
||||
public function GetOldLoans($count = false)
|
||||
{
|
||||
return $this->_getLoans('OldCirculations', 'CheckOutDate DESC');
|
||||
return $this->_getLoans('OldCirculations', $count, 'CheckOutDate DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,10 +233,11 @@ class User extends DbMapping
|
||||
|
||||
/**
|
||||
* Wishes are all the books that this user want to read.
|
||||
* @param boolean $count return only the count
|
||||
* @param int $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getWishes($limit = 50)
|
||||
public function getWishes($count = false, $limit = 50)
|
||||
{
|
||||
$sql = sprintf("SELECT TOP $limit
|
||||
NoticeID
|
||||
@@ -240,6 +247,9 @@ class User extends DbMapping
|
||||
|
||||
$result = Connection::execute($sql);
|
||||
$ids = array_map(function($r) { return $r['NoticeID']; }, $result->to_array());
|
||||
if($count) {
|
||||
return count($ids);
|
||||
}
|
||||
return BookSearch::GetBooks($ids, 'id');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user