Commit 0a1414b2 authored by Patrick Barroca's avatar Patrick Barroca 🐧

Merge branch 'hotline#108377_urgent_compte_invite_et_pnb' into 'hotline'

hotline #108377 : fix Dilicom hold quota of guest users

See merge request !3452
parents c7bdcc5c 8c781df9
Pipeline #9765 passed with stage
in 46 minutes and 47 seconds
- ticket #108377 : Ressources numériques : Correction du calcul du quota de réservation pour les invités
\ No newline at end of file
...@@ -24,12 +24,18 @@ class Class_Hold_PnbLoader extends Storm_Model_Loader { ...@@ -24,12 +24,18 @@ class Class_Hold_PnbLoader extends Storm_Model_Loader {
if (!$user) if (!$user)
return []; return [];
return array_unique( $by_user_id = $this->findAllOngoingBy(['user_id' => $user->getId()]);
array_merge( if (!$user->isAbonne())
Class_Hold_Pnb::findAllBy(['user_id' => $user->getId(), return $by_user_id;
'order' => 'hold_date']),
Class_Hold_Pnb::findAllBy(['subscriber_id' => $user->getIdabon(), return array_unique(array_merge($by_user_id,
'order' => 'hold_date']))); $this->findAllOngoingBy(['subscriber_id' => $user->getIdabon()])));
}
public function findAllOngoingBy($params) {
return Class_Hold_Pnb::findAllBy(array_merge(['order' => 'hold_date'],
$params));
} }
...@@ -160,17 +166,19 @@ class Class_Hold_Pnb extends Storm_Model_Abstract { ...@@ -160,17 +166,19 @@ class Class_Hold_Pnb extends Storm_Model_Abstract {
public function getUser() { public function getUser() {
$user = parent::_get('user'); if ($user = parent::_get('user'))
return $user return $user;
return $this->hasSubscriberId() && ($user = Class_Users::findFirstBy(['idabon' => $this->getSubscriberId()]))
? $user ? $user
: Class_Users::findFirstBy(['idabon' => $this->getSubscriberId()]); : null;
} }
public function getUserId() { public function getUserId() {
return ($user = $this->getUser()) return ($user = $this->getUser())
? $user->getId() ? $user->getId()
: null; : parent::_get('user_id');
} }
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
class Class_Loan_PnbLoader extends Storm_Model_Loader { class Class_Loan_PnbLoader extends Storm_Model_Loader {
public function findAllOngoingOfUser($user) { public function findAllOngoingOfUser($user) {
if (!$user)
return [];
$loans = $this->_ongoingOf($user); $loans = $this->_ongoingOf($user);
(new Class_WebService_BibNumerique_Dilicom_Hub())->updateLoansReturnDate($loans); (new Class_WebService_BibNumerique_Dilicom_Hub())->updateLoansReturnDate($loans);
......
...@@ -24,7 +24,7 @@ class Class_User_Cards extends Storm_Model_Collection { ...@@ -24,7 +24,7 @@ class Class_User_Cards extends Storm_Model_Collection {
use Trait_Translator; use Trait_Translator;
public function __construct($user) { public function __construct($user) {
if ($user->isAbonne()) if ($user->isAbonne() || $user->hasPnbLoans() || $user->hasPnbHolds())
$this->append($user); $this->append($user);
$this->addAll($user->getChildCards()); $this->addAll($user->getChildCards());
......
...@@ -381,6 +381,7 @@ class Class_Users extends Storm_Model_Abstract { ...@@ -381,6 +381,7 @@ class Class_Users extends Storm_Model_Abstract {
protected protected
$_fiche_sigb, $_fiche_sigb,
$_loans, $_loans,
$_ongoing_pnb_holds,
$_table_name = 'bib_admin_users', $_table_name = 'bib_admin_users',
$_table_primary = 'ID_USER', $_table_primary = 'ID_USER',
$_loader_class = 'UsersLoader', $_loader_class = 'UsersLoader',
...@@ -1236,6 +1237,11 @@ class Class_Users extends Storm_Model_Abstract { ...@@ -1236,6 +1237,11 @@ class Class_Users extends Storm_Model_Abstract {
} }
public function hasPnbLoans() {
return !$this->getEmprunts()->selectPNB()->isEmpty();
}
public function getPanierCourant() { public function getPanierCourant() {
return ($panier_courant = parent::getPanierCourant()) return ($panier_courant = parent::getPanierCourant())
? $panier_courant ? $panier_courant
...@@ -1290,10 +1296,21 @@ class Class_Users extends Storm_Model_Abstract { ...@@ -1290,10 +1296,21 @@ class Class_Users extends Storm_Model_Abstract {
* @return int * @return int
*/ */
public function getNbReservations() { public function getNbReservations() {
return $this->getEmprunteur()->getNbReservations() return $this->getEmprunteur()->getNbReservations() + $this->_getOngoingPnbHolds()->count();
+ (new Storm_Model_Collection(Class_Hold_Pnb::findAllOngoingOfUser($this))) }
->reject('isExpired')
->count();
public function hasPnbHolds() {
return 0 < $this->_getOngoingPnbHolds()->count();
}
protected function _getOngoingPnbHolds() {
if ($this->_ongoing_pnb_holds)
return $this->_ongoing_pnb_holds;
return $this->_ongoing_pnb_holds = (new Storm_Model_Collection(Class_Hold_Pnb::findAllOngoingOfUser($this)))
->reject('isExpired');
} }
......
...@@ -216,3 +216,132 @@ class AbonneControllerFicheActionWithLoggedUserTest extends AbstractAbonneContro ...@@ -216,3 +216,132 @@ class AbonneControllerFicheActionWithLoggedUserTest extends AbstractAbonneContro
} }
} }
abstract class AbonneControllerFicheActionLoggedGuestWithPnbTestCase extends AbstractAbonneControllerFicheTest {
public function setUp() {
parent::setUp();
$user = $this->fixture('Class_Users',
['id' => 88,
'login' => 'guest',
'password' => 'roxor',
'id_site' => 1,
'user_groups' => [Class_UserGroup::find(20)],
'role' => ZendAfi_Acl_AdminControllerRoles::INVITE,
]);
ZendAfi_Auth::getInstance()->logUser($user);
}
public function tearDown() {
Class_Loan_Pnb::setTimeSource(null);
Class_Hold_Pnb::setTimeSource(null);
Class_WebService_BibNumerique_Dilicom_Hub::setDefaultHttpClient(null);
parent::tearDown();
}
}
class AbonneControllerFicheActionLoggedGuestWithPnbNoHoldNorLoanTest
extends AbonneControllerFicheActionLoggedGuestWithPnbTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/abonne/fiche', true);
}
/** @test */
public function loansLinkShouldNotBePresent() {
$this->assertNotXPath('//div//a[contains(@href, "/abonne/prets")]');
}
/** @test */
public function holdsLinkShouldNotBePresent() {
$this->assertNotXPath('//div//a[contains(@href, "/abonne/reservations")]');
}
}
class AbonneControllerFicheActionLoggedGuestWithPnbHoldsTest
extends AbonneControllerFicheActionLoggedGuestWithPnbTestCase {
public function setUp() {
parent::setUp();
Class_Hold_Pnb::setTimeSource(new TimeSourceForTest('2022-06-10 10:23:10'));
Class_AdminVar::set('DILICOM_PNB_ENABLE_HOLDS', 1);
$second = $this->fixture('Class_Hold_Pnb',
['id' => 2,
'user_id' => 88,
'subscriber_id' => '',
'record_origin_id' => 'Dilicom-88817216',
'hold_date' => '2022-06-07 20:10:00',
'expiration_date' => '2022-06-15 20:10:00']);
$this->dispatch('/abonne/fiche', true);
}
/** @test */
public function loansLinkShouldBePresent() {
$this->assertXPath('//div//a[contains(@href, "/abonne/prets")]');
}
/** @test */
public function holdsLinkShouldBePresent() {
$this->assertXPath('//div//a[contains(@href, "/abonne/reservations")]');
}
}
class AbonneControllerFicheActionLoggedGuestWithPnbLoansTest
extends AbonneControllerFicheActionLoggedGuestWithPnbTestCase {
public function setUp() {
parent::setUp();
Class_Loan_Pnb::setTimeSource(new TimeSourceForTest('2017-11-14 10:23:10'));
Class_AdminVar::set('DILICOM_PNB_ENABLE_HOLDS', 1);
$http = $this->mock()->whenCalled('open_url')->answers(null);
Class_WebService_BibNumerique_Dilicom_Hub::setDefaultHttpClient($http);
$this->fixture('Class_Loan_Pnb',
['id' => 3,
'record_origin_id' => 'Dilicom-3663608260879',
'subscriber_id' => '',
'user_id' => 88,
'expected_return_date' => '2017-12-13 13:57:33',
'loan_date' => '2017-11-13 13:57:33',
'loan_link' => 'https://pnb-dilicom.centprod.com/v2//XXXXXXXX.do',
'order_line_id' => '584837a045ce56ef0a072a8b',]);
$this->dispatch('/abonne/fiche', true);
}
/** @test */
public function loansLinkShouldBePresent() {
$this->assertXPath('//div//a[contains(@href, "/abonne/prets")]');
}
/** @test */
public function holdsLinkShouldBePresent() {
$this->assertXPath('//div//a[contains(@href, "/abonne/reservations")]');
}
}
...@@ -4212,6 +4212,61 @@ class PnbDilicomAbonneHoldsTest extends PnbDilicomBibNumeriqueControllerTestCase ...@@ -4212,6 +4212,61 @@ class PnbDilicomAbonneHoldsTest extends PnbDilicomBibNumeriqueControllerTestCase
/** @see http://forge.afi-sa.fr/issues/108377 */
class PnbDilicomAbonneHoldsGuestTest extends PnbDilicomBibNumeriqueControllerTestCase {
public function setUp() {
parent::setUp();
$user = $this->fixture('Class_Users',
['id' => 88,
'login' => 'guest',
'password' => 'roxor',
'id_site' => 1,
'user_groups' => [Class_UserGroup::find(20)],
'role' => ZendAfi_Acl_AdminControllerRoles::INVITE,
]);
ZendAfi_Auth::getInstance()->logUser($user);
$timesource = new TimeSourceForTest('2022-06-10 10:23:10');
Class_Hold_Pnb::setTimeSource($timesource);
Class_AdminVar::set('DILICOM_PNB_ENABLE_HOLDS', 1);
$this->fixture('Class_Hold_Pnb',
['id' => 1,
'user_id' => 789,
'subscriber_id' => '',
'record_origin_id' => 'Dilicom-88817216',
'hold_date' => '2022-06-08 20:10:00']);
$this->fixture('Class_Hold_Pnb',
['id' => 2,
'user_id' => 88,
'subscriber_id' => '',
'record_origin_id' => 'Dilicom-88817216',
'hold_date' => '2022-06-07 20:10:00',
'expiration_date' => '2022-06-15 20:10:00']);
$this->dispatch('/abonne/reservations');
}
/** @test */
public function pageShouldContainsTableIdBorrowerHoldsPnb() {
$this->assertXPath('//table[@id="borrower_holds_pnb"]');
}
/** @test */
public function tableShouldContainsOneRow() {
$this->assertXPathCount('//table[@id="borrower_holds_pnb"]/tbody/tr', 1);
}
}
class PnbDilicomAbonneDeletePnbHoldTest extends PnbDilicomBibNumeriqueControllerTestCase { class PnbDilicomAbonneDeletePnbHoldTest extends PnbDilicomBibNumeriqueControllerTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
......
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