Commit cde267ad authored by Laurent's avatar Laurent
Browse files

dev #68187 PNB Dilicom fix RT

parent 0dc456ff
Pipeline #4936 failed with stage
in 45 minutes and 23 seconds
...@@ -1011,7 +1011,6 @@ class AbonneController extends ZendAfi_Controller_Action { ...@@ -1011,7 +1011,6 @@ class AbonneController extends ZendAfi_Controller_Action {
$this->_helper->viewRenderer->setNoRender(); $this->_helper->viewRenderer->setNoRender();
$datas = []; $datas = [];
$cards = new Class_User_Cards($this->_user); $cards = new Class_User_Cards($this->_user);
$emprunts = $cards $emprunts = $cards
->getLoansWithOutPNB($this->_request->getParams()) ->getLoansWithOutPNB($this->_request->getParams())
......
...@@ -75,6 +75,14 @@ class Class_Loan_PnbLoader extends Storm_Model_Loader { ...@@ -75,6 +75,14 @@ class Class_Loan_PnbLoader extends Storm_Model_Loader {
} }
public function findFirstReturningLoanForItem($item) {
return Class_Loan_Pnb::findFirstBy(['order_line_id' => $item->getOrderLineId(),
'order' => 'expected_return_date',
'where' => sprintf('expected_return_date > "%s"', $this->_getDate())]);
}
protected function _applyOngoingAndDo($params, $closure) { protected function _applyOngoingAndDo($params, $closure) {
$prefix = isset($params['where']) ? '(' . $params['where'] . ') and ' : ''; $prefix = isset($params['where']) ? '(' . $params['where'] . ') and ' : '';
$params['where'] = $prefix . 'expected_return_date > "' . $this->_getDate() . '"'; $params['where'] = $prefix . 'expected_return_date > "' . $this->_getDate() . '"';
......
...@@ -236,13 +236,6 @@ class Class_WebService_BibNumerique_Dilicom_Hub extends Class_WebService_Abstrac ...@@ -236,13 +236,6 @@ class Class_WebService_BibNumerique_Dilicom_Hub extends Class_WebService_Abstrac
} }
protected function _getNextExpectedSimultaneousLoanDate($item) {
if (!$loan = current(Class_Loan_Pnb::findLastPastLoansForItem($item)))
return $this->_('"date inconnue"');
return Class_Date::humanDate($loan->getExpectedReturnDate(), $this->_('d MMMM yyyy à HH:mm'));
}
protected function _getFirstLoanableItemOrLast($album) { protected function _getFirstLoanableItemOrLast($album) {
$items = $album->getItems(); $items = $album->getItems();
foreach($items as $item) { foreach($items as $item) {
...@@ -323,13 +316,11 @@ class Class_WebService_BibNumerique_Dilicom_Hub extends Class_WebService_Abstrac ...@@ -323,13 +316,11 @@ class Class_WebService_BibNumerique_Dilicom_Hub extends Class_WebService_Abstrac
if (!$item = $this->_getFirstLoanableItemOrLast($album)) if (!$item = $this->_getFirstLoanableItemOrLast($album))
return $this->_error($this->_('Album invalide')); return $this->_error($this->_('Album invalide'));
if (!$item->isAvailable()) if (!$item->isAvailable())
return $this->_error($this->_('Emprunt impossible. La ressource n\'est plus disponible.')); return $this->_error($this->_('Emprunt impossible. La ressource n\'est plus disponible.'));
if (!$item->getUsageConstraints()->hasSimultaneousLoanRemaining()) if (!$item->getUsageConstraints()->hasSimultaneousLoanRemaining())
return $this->_error($this->_('Emprunt impossible. Le nombre d\'emprunts simultanés pour ce document est atteint. Le prochain emprunt sera possible le %s.', return $this->_notAvailableError($item);
$this->_getNextExpectedSimultaneousLoanDate($item)));
if (!$item->getUsageConstraints()->hasAvailableQuantity()) if (!$item->getUsageConstraints()->hasAvailableQuantity())
return $this->_error($this->_('Emprunt impossible. Le nombre d\'emprunts disponible est épuisé.')); return $this->_error($this->_('Emprunt impossible. Le nombre d\'emprunts disponible est épuisé.'));
...@@ -341,6 +332,20 @@ class Class_WebService_BibNumerique_Dilicom_Hub extends Class_WebService_Abstrac ...@@ -341,6 +332,20 @@ class Class_WebService_BibNumerique_Dilicom_Hub extends Class_WebService_Abstrac
} }
protected function _notAvailableError($item) {
$message = $this->_('Emprunt impossible. Le nombre d\'emprunts simultanés pour ce document est atteint.');
if (!$loan = Class_Loan_Pnb::findFirstReturningLoanForItem($item))
return $this->_error($message);
$message .= ' ' . $this->_('Le prochain emprunt sera possible le %s',
strftime($this->_('%A %d %B à %Hh%M'),
strtotime($loan->getExpectedReturnDate())));
return $this->_error($message);
}
protected function _isAlbumCurrentlyLoanedByUser($album, $user) { protected function _isAlbumCurrentlyLoanedByUser($album, $user) {
if (!$user) if (!$user)
return $this->_error($this->_('L\'emprunt est impossible car vous n\'êtes pas connecté.')); return $this->_error($this->_('L\'emprunt est impossible car vous n\'êtes pas connecté.'));
......
...@@ -102,7 +102,7 @@ class ZendAfi_View_Helper_TagDilicomWidget extends ZendAfi_View_Helper_BaseHelpe ...@@ -102,7 +102,7 @@ class ZendAfi_View_Helper_TagDilicomWidget extends ZendAfi_View_Helper_BaseHelpe
$hub = new Class_WebService_BibNumerique_Dilicom_Hub(); $hub = new Class_WebService_BibNumerique_Dilicom_Hub();
$loanable = $hub->isAlbumLoanableBy($this->_album, $this->_user); $loanable = $hub->isAlbumLoanableBy($this->_album, $this->_user);
return ($error = $loanable->returnMessage) return ($error = $loanable->returnMessage)
? $this->_errorButton($error) ? $this->_errorButton($error[0])
: $loanBookAnchor; : $loanBookAnchor;
} }
...@@ -110,9 +110,8 @@ class ZendAfi_View_Helper_TagDilicomWidget extends ZendAfi_View_Helper_BaseHelpe ...@@ -110,9 +110,8 @@ class ZendAfi_View_Helper_TagDilicomWidget extends ZendAfi_View_Helper_BaseHelpe
protected function _errorButton($message) { protected function _errorButton($message) {
return $this->_tag('div', return $this->_tag('div',
$this->_tag('span' , $this->_tag('span' ,
$this->_('Emprunter le livre au format EPUB'), $message,
['title' => $message, ['class' => 'error']),
'class' => 'error']),
['class' => 'dilicom-action']); ['class' => 'dilicom-action']);
} }
......
...@@ -1808,8 +1808,8 @@ class PnbDilicomViewHelperRenderAlbumPNBGetLoanStatusTest extends PnbDilicomView ...@@ -1808,8 +1808,8 @@ class PnbDilicomViewHelperRenderAlbumPNBGetLoanStatusTest extends PnbDilicomView
$this->_html = $this->_helper->renderAlbum($this->book); $this->_html = $this->_helper->renderAlbum($this->book);
$this->assertXPathContentContains($this->_html, $this->assertXPathContentContains($this->_html,
'//div//span[contains(@title,"La ressource n\'est plus disponible.")]', '//div//span[@class="error"]',
'Emprunter le livre au format EPUB'); 'La ressource n\'est plus disponible.');
} }
...@@ -1831,26 +1831,46 @@ class PnbDilicomViewHelperRenderAlbumPNBGetLoanStatusTest extends PnbDilicomView ...@@ -1831,26 +1831,46 @@ class PnbDilicomViewHelperRenderAlbumPNBGetLoanStatusTest extends PnbDilicomView
$this->_html = $this->_helper->renderAlbum($this->book); $this->_html = $this->_helper->renderAlbum($this->book);
$this->assertXPathContentContains($this->_html, $this->assertXPathContentContains($this->_html,
'//div//span[@class="error"][contains(@title,"Emprunt impossible. Vous avez atteint votre quota de 3 emprunts.")]', '//div//span[@class="error"]',
'Emprunter le livre au format EPUB'); 'Emprunt impossible. Vous avez atteint votre quota de 3 emprunts');
} }
/** @test */ /** @test */
public function htmlShouldContainsNextAvailableJetonAtDate() { public function htmlShouldContainsNextAvailableLoanDate() {
Class_Album_UsageConstraint::find(1)->setMaxNumberOfUsers(0)->assertSave(); Class_Album_UsageConstraint::find(1)->setMaxNumberOfUsers(0)->assertSave();
Class_AdminVar::set('DILICOM_PNB_LOAN_COUNT_LIMIT',0); Class_AdminVar::set('DILICOM_PNB_LOAN_COUNT_LIMIT',0);
$this->fixture('Class_Loan_Pnb', $this->fixture('Class_Loan_Pnb',
['id' => 1, ['id' => 1,
'user_id' => $this->logged_user->getId(), 'user_id' => $this->logged_user->getId(),
'record_origin_id' => 1, 'record_origin_id' => 1,
'expected_return_date' => '2022-06-01']); 'order_line_id' => 'x321',
'expected_return_date' => '2022-06-01 20:10:00']);
$this->_html = $this->_helper->renderAlbum($this->book); $this->_html = $this->_helper->renderAlbum($this->book);
$this->assertXPathContentContains($this->_html, $this->assertXPathContentContains($this->_html,
'//div//span[contains(@title,"Emprunt impossible. Le nombre d\'emprunts simultanés pour ce document est atteint. Le prochain emprunt sera possible le")]', '//div//span[@class="error"]',
'Emprunter le livre au format EPUB'); utf8_encode('Emprunt impossible. Le nombre d\'emprunts simultanés pour ce document est atteint. Le prochain emprunt sera possible le mercredi 01 juin à 20h10'));
}
/** @test */
public function onUnknownReturnDateHtmlShouldNotContainsNextAvailableLoanDate() {
Class_Album_UsageConstraint::find(1)->setMaxNumberOfUsers(0)->assertSave();
Class_AdminVar::set('DILICOM_PNB_LOAN_COUNT_LIMIT',0);
$this->fixture('Class_Loan_Pnb',
['id' => 1,
'user_id' => $this->logged_user->getId(),
'record_origin_id' => 1,
'order_line_id' => '???',
'expected_return_date' => '2022-06-01 20:10:00']);
$this->_html = $this->_helper->renderAlbum($this->book);
$this->assertNotXPathContentContains($this->_html,
'//div//span[@class="error"]',
utf8_encode('Le prochain emprunt sera possible'));
} }
} }
......
Markdown is supported
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