Skip to content
Snippets Groups Projects
Commit 89f7b64b authored by Arthur Suzuki's avatar Arthur Suzuki
Browse files

Merge branch 'hotline#194248_koha_fix_loans_history' into 'master'

[RTfixed] hotline#194248: SIGB Koha, fixes loans history display

See merge request !4927
parents 2601aa84 acfa6cd4
Branches
Tags
1 merge request!4927[RTfixed] hotline#194248: SIGB Koha, fixes loans history display
Pipeline #30610 canceled with stage
in 5 minutes and 38 seconds
- correctif #194248 : SIGB Koha : Meilleur affichage de l'historique de prêts, tri par ordre de date d'emprunt décroissant, les prêts les plus récents sont affichés en premier. L'affichage est limité à 4 mois ou 50 prêts pour des questions de performances.
......@@ -219,24 +219,17 @@ class Class_User_Cards extends Storm_Model_Collection {
public function getLoansHistory() :Storm_Collection {
/* see forge #137459 and koha library/Class/WebService/SIGB/Koha/RestfulService loanHistory($borrower) */
try {
return
$this->_decorateOperationFrom(function($card)
{
return $card->getLoansHistory();
});
$loans = $this->_decorateOperationFrom(fn($card) => $card->getLoansHistory());
$loans->uasort(fn($a, $b) => strcmp(Class_Date::frToIso($b->getIssueDate()),
Class_Date::frToIso($a->getIssueDate())));
return $loans;
} catch (Exception $exception) {
return new Storm_Collection;
}
}
public function getHistoryLoansCount() :int {
return $this->getLoansHistory()->count();
}
protected function _decorateOperationFrom(Closure $closure) :Storm_Collection {
$operations = new Storm_Collection();
......
......@@ -1198,25 +1198,10 @@ class Class_Users extends Storm_Model_Abstract {
continue;
$value = $params[$key];
$loans = $loans->select(function($loan) use ($key, $value)
{
return $loan->filterBy($key, $value);
});
$loans = $loans->select(fn($loan) => $loan->filterBy($key, $value));
}
$loans = $loans->select(
function($loan) {
$loan->setRenewable(false);
return $loan->getDateRetour();
});
$loans->uasort(function($a, $b)
{
return strcmp(Class_Date::frToIso($a->getIssueDate()),
Class_Date::frToIso($b->getIssueDate()));
});
return $loans;
return $loans->select(fn($loan) => $loan->setRenewable(false)->getDateRetour());
}
......
......@@ -20,7 +20,7 @@
*/
abstract class Class_WebService_SIGB_AbstractService {
use Trait_Translator, Trait_Errors;
use Trait_Translator, Trait_Errors, Trait_TimeSource;
const
COMMUNICATION_OK = 'ok',
......
......@@ -21,7 +21,6 @@
class Class_Webservice_SIGB_CdScript_Service extends Class_WebService_SIGB_AbstractService {
use Trait_TimeSource;
protected
$_server_url,
......@@ -150,4 +149,4 @@ class Class_Webservice_SIGB_CdScript_Service extends Class_WebService_SIGB_Abstr
return null;
}
}
?>
\ No newline at end of file
?>
......@@ -361,8 +361,11 @@ class Class_WebService_SIGB_Koha_CommunityService
$this->addError($this->_('Échec de l\'authentification par le webservice'));
$url = $this->_buildUrlForEndpointWithParams('checkouts',
['q'=> $this->_buildFilterQuery(['item_id' => ['-not_like' => 'null']]),
['q'=> $this->_buildFilterQuery(['item_id' => ['-not_like' => 'null'],
'checkin_date' => ['>' => $this->substractMonthToCurrentDate(4)]]),
'_match' => 'exact',
'_page' => 1,
'_per_page' => 50,
'checked_in' => 1,
'patron_id' => $patron_id]);
......
......@@ -62,6 +62,11 @@ trait Trait_TimeSource {
}
public static function substractMonthToCurrentDate($month) {
return date('Y-m-d', strtotime('-' . (string)$month . ' month', self::getTimeSource()->time()));
}
public static function addDaysToCurrentDate($days) {
return date('Y-m-d', static::addIntervalToDate((string)$days.' day', null));
}
......
......@@ -74,10 +74,11 @@ class Intonation_View_Abonne_AjaxLoans extends ZendAfi_View_Helper_BaseHelper {
protected function _loansHistory(Intonation_Library_LoansSettings $settings, Class_User_Cards $cards) :string {
$history = $cards->getLoansHistory();
return $this->view
->abonne_HistoryLoansList((clone $settings)
->setLoans( $cards->getLoansHistory())
->setLoansCount($cards->getHistoryLoansCount()));
->setLoans( $history )
->setLoansCount($history->count()));
}
......
......@@ -191,12 +191,14 @@ class AbonneControllerLoansHistoryWithoutHistoryTest extends AbonneControllerLoa
public function setUp() {
parent::setUp();
$time_source = new TimeSourceForTest('2024-04-01');
Class_WebService_SIGB_Koha_CommunityService::setTimeSource($time_source);
$this->mock_web_client
->whenCalled('open_url')
->with(static::BASE_URL . 'checkouts?q='
. urlencode('{"item_id":{"-not_like":"null"}}')
. '&_match=exact&checked_in=1&patron_id=32007',
. urlencode('{"item_id":{"-not_like":"null"},"checkin_date":{">":"2023-12-01"}}')
. '&_match=exact&_page=1&_per_page=50&checked_in=1&patron_id=32007',
['auth' => ['user' => 'koha_admin', 'password' => 'k0h@_P455']])
->answers('[]');
......@@ -228,12 +230,14 @@ class AbonneControllerLoansHistoryWithErrorTest extends AbonneControllerLoansHi
public function setUp() {
parent::setUp();
$time_source = new TimeSourceForTest('2024-04-01');
Class_WebService_SIGB_Koha_CommunityService::setTimeSource($time_source);
$this->mock_web_client
->whenCalled('open_url')
->with(static::BASE_URL . 'checkouts?q='
. urlencode('{"item_id":{"-not_like":"null"}}')
. '&_match=exact&checked_in=1&patron_id=32007',
. urlencode('{"item_id":{"-not_like":"null"},"checkin_date":{">":"2023-12-01"}}')
. '&_match=exact&_page=1&_per_page=50&checked_in=1&patron_id=32007',
['auth' => ['user' => 'koha_admin', 'password' => 'k0h@_P455']])
->answers('{"errors":"error"}');
......
......@@ -342,11 +342,14 @@ class KohaCommunityFixtures {
public static function mockWebClientForLoansHistory($base_url, $controller) {
$mock_web_client = $controller->mock()
$time_source = new TimeSourceForTest('2024-04-01');
Class_WebService_SIGB_Koha_CommunityService::setTimeSource($time_source);
$mock_web_client = $controller->mock()
->whenCalled('open_url')
->with($base_url . 'checkouts?q='
. urlencode('{"item_id":{"-not_like":"null"}}')
. '&_match=exact&checked_in=1&patron_id=32007',
. urlencode('{"item_id":{"-not_like":"null"},"checkin_date":{">":"2023-12-01"}}')
. '&_match=exact&_page=1&_per_page=50&checked_in=1&patron_id=32007',
['auth'=> ['user' => 'koha_admin', 'password' => 'k0h@_P455']])
->answers(file_get_contents(__DIR__ . '/koha_issues_history.json'))
->whenCalled('open_url')
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment