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');
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ use BSR\Lib\WebService;
|
||||
class NetBiblio extends WebService
|
||||
{
|
||||
/** @var string $version version number */
|
||||
public static $version = '1.1.3';
|
||||
public static $version = '1.1.4';
|
||||
|
||||
private $login = '';
|
||||
private $client = 'website';
|
||||
@@ -473,6 +473,30 @@ class NetBiblio extends WebService
|
||||
return array_values($this->AddBookData($circulations));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method return information for the user dashboard :
|
||||
*
|
||||
* ° 'loans' : number of current loans
|
||||
* ° 'oldLoans' : number of past loans
|
||||
* ° 'wishes' : number of wishes
|
||||
* ° 'novelties' : new books
|
||||
* ° 'recommendations' : recommended books
|
||||
*
|
||||
* @return array
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
public function GetDashboardData()
|
||||
{
|
||||
$user = $this->getUser();
|
||||
return array(
|
||||
'loans' => $user->GetLoans(true),
|
||||
'oldLoans' => $user->GetOldLoans(true),
|
||||
'wishes' => $user->getWishes(true),
|
||||
'novelties' => $this->LastBooksByType('', 15),
|
||||
'recommendations' => $this->MoreLikeLoans(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method adds a book to the currently authenticated user wishlist
|
||||
* based on its code.
|
||||
|
||||
Reference in New Issue
Block a user