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 {
$this->_helper->viewRenderer->setNoRender();
$datas = [];
$cards = new Class_User_Cards($this->_user);
$emprunts = $cards
->getLoansWithOutPNB($this->_request->getParams())
......
......@@ -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) {
$prefix = isset($params['where']) ? '(' . $params['where'] . ') and ' : '';
$params['where'] = $prefix . 'expected_return_date > "' . $this->_getDate() . '"';
......
......@@ -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) {
$items = $album->getItems();
foreach($items as $item) {
......@@ -323,13 +316,11 @@ class Class_WebService_BibNumerique_Dilicom_Hub extends Class_WebService_Abstrac
if (!$item = $this->_getFirstLoanableItemOrLast($album))
return $this->_error($this->_('Album invalide'));
if (!$item->isAvailable())
return $this->_error($this->_('Emprunt impossible. La ressource n\'est plus disponible.'));
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.',
$this->_getNextExpectedSimultaneousLoanDate($item)));
return $this->_notAvailableError($item);
if (!$item->getUsageConstraints()->hasAvailableQuantity())
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
}
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) {
if (!$user)
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
$hub = new Class_WebService_BibNumerique_Dilicom_Hub();
$loanable = $hub->isAlbumLoanableBy($this->_album, $this->_user);
return ($error = $loanable->returnMessage)
? $this->_errorButton($error)
? $this->_errorButton($error[0])
: $loanBookAnchor;
}
......@@ -110,9 +110,8 @@ class ZendAfi_View_Helper_TagDilicomWidget extends ZendAfi_View_Helper_BaseHelpe
protected function _errorButton($message) {
return $this->_tag('div',
$this->_tag('span' ,
$this->_('Emprunter le livre au format EPUB'),
['title' => $message,
'class' => 'error']),
$message,
['class' => 'error']),
['class' => 'dilicom-action']);
}
......
......@@ -1808,8 +1808,8 @@ class PnbDilicomViewHelperRenderAlbumPNBGetLoanStatusTest extends PnbDilicomView
$this->_html = $this->_helper->renderAlbum($this->book);
$this->assertXPathContentContains($this->_html,
'//div//span[contains(@title,"La ressource n\'est plus disponible.")]',
'Emprunter le livre au format EPUB');
'//div//span[@class="error"]',
'La ressource n\'est plus disponible.');
}
......@@ -1831,26 +1831,46 @@ class PnbDilicomViewHelperRenderAlbumPNBGetLoanStatusTest extends PnbDilicomView
$this->_html = $this->_helper->renderAlbum($this->book);
$this->assertXPathContentContains($this->_html,
'//div//span[@class="error"][contains(@title,"Emprunt impossible. Vous avez atteint votre quota de 3 emprunts.")]',
'Emprunter le livre au format EPUB');
'//div//span[@class="error"]',
'Emprunt impossible. Vous avez atteint votre quota de 3 emprunts');
}
/** @test */
public function htmlShouldContainsNextAvailableJetonAtDate() {
public function htmlShouldContainsNextAvailableLoanDate() {
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,
'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->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")]',
'Emprunter le livre au format EPUB');
'//div//span[@class="error"]',
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