Commit 5f9615cb authored by Laurent's avatar Laurent
Browse files

dev #48981 : hold with multi cards

parent 5282da71
......@@ -26,7 +26,7 @@ class AbonneController extends ZendAfi_Controller_Action {
if ('authenticate' == $this->getRequest()->getActionName())
return;
$this->_user = Class_Users::getLoader()->getIdentity();
$this->_user = Class_Users::getIdentity();
$this->clearEmprunteurCache();
......@@ -402,7 +402,7 @@ class AbonneController extends ZendAfi_Controller_Action {
}
protected function _renderExtendPopup($title,$message) {
protected function _renderExtendPopup($title, $message) {
$this->view->titre = $title;
$this->view->fiche = $this->_user->getFicheSigb();
$this->renderPopupResult($title,
......@@ -425,20 +425,24 @@ class AbonneController extends ZendAfi_Controller_Action {
public function reservationsAction() {
if (null !== ($delete = $this->_getParam('id_delete'))) {
$cls_comm = new Class_CommSigb();
$statut_suppr = $cls_comm->supprimerReservation($this->_user, $delete);
$cards = new Class_User_Cards($this->_user);
if ($delete = $this->_getParam('id_delete')) {
$title = $cards->getHoldTitle($delete);
$result = $cards->cancelHold($delete);
$message = array_key_exists('erreur', $result) && $result['erreur']
? $result['erreur']
: $this->_('Votre réservation du document %s a bien été supprimée.', $title);
return $this->_renderExtendPopup($this->_('Suppression de la réservation'), $message);
}
if (null !== ($delete = $this->_getParam('consultation_id_delete'))) {
if ($delete = $this->_getParam('consultation_id_delete'))
Class_CommSigb::getInstance()->onPlaceConsultationCancelBooking(Class_Users::getIdentity(), $delete);
}
$this->view->reservations = $this->_user->getReservations();
$this->view->consultations_reservations = $this->_user->getConsultations();
$this->view->fiche = $this->_user->getFicheSigb();
$this->view->user = $this->_user;
Class_ScriptLoader::getInstance()->loadTableSorter();
}
......
<?php
Class_ScriptLoader::getInstance()->loadTableSorter();
$this->openBoite($this->_('Réservations en cours'));
echo $this->tag('div', $this->user->getNomAff(), ['class' => 'abonneTitre']);
echo $this->abonne_ReservationsTable($this->reservations, $this->fiche);
$cards = new Class_User_Cards($this->user);
echo $this->abonne_ReservationsTable($cards->getHolds(), $this->fiche);
$this->closeBoite();
......
......@@ -32,26 +32,17 @@ class Class_User_Cards extends Storm_Model_Collection {
public function getLoansWithOutPNB() {
return $this->_decorateLoansFrom(function($card) { return $card->getLoansWithOutPNB(); });
return $this->_decorateOperationFrom(function($card) { return $card->getLoansWithOutPNB(); });
}
public function getLoans() {
return $this->_decorateLoansFrom(function($card) { return $card->getEmprunts(); });
return $this->_decorateOperationFrom(function($card) { return $card->getEmprunts(); });
}
public function getLateLoans() {
return $this->_decorateLoansFrom(function($card) { return $card->getEmprunts()->selectLates(); });
}
protected function _decorateLoansFrom($closure) {
$loans = new Storm_Collection();
foreach($this as $card)
$loans->addAll(Class_User_CardsOperationDecorator::decorateAll($closure($card), $card));
return $loans;
return $this->_decorateOperationFrom(function($card) { return $card->getEmprunts()->selectLates(); });
}
......@@ -66,4 +57,49 @@ class Class_User_Cards extends Storm_Model_Collection {
? $loan->renew()
: ['statut' => false, 'erreur' => $this->_('Prêt introuvable')];
}
public function cancelHold($id) {
$hold = $this->getHolds()
->detect(function($hold) use($id) { return $hold->getId() == $id; });
return $hold
? $hold->cancel()
: ['statut' => false, 'erreur' => $this->_('Réservation introuvable')];
}
public function getHoldsCount() {
return $this->injectInto(0,
function($current, $card)
{
$consultations = $card->getId() == Class_Users::getIdentity()->getId()
? $card->getNbConsultations()
: 0;
return $current + $card->getNbReservations() + $consultations;
});
}
public function getHolds() {
return $this->_decorateOperationFrom(function($card) { return new Storm_Collection($card->getReservations()); });
}
public function getHoldTitle($id) {
$hold = $this->getHolds()
->detect(function($hold) use($id) { return $hold->getId() == $id; });
return $hold ? $hold->getTitre() : '';
}
protected function _decorateOperationFrom($closure) {
$operations = new Storm_Collection();
foreach($this as $card)
$operations->addAll(Class_User_CardsOperationDecorator::decorateAll($closure($card), $card));
return $operations;
}
}
\ No newline at end of file
......@@ -56,4 +56,9 @@ class Class_User_CardsOperationDecorator {
public function renew() {
return Class_CommSigb::getInstance()->prolongerPret($this->_user, $this->_operation->getId());
}
public function cancel() {
return Class_CommSigb::getInstance()->supprimerReservation($this->_user, $this->_operation->getId());
}
}
\ No newline at end of file
......@@ -1300,10 +1300,14 @@ class Class_Users extends Storm_Model_Abstract {
public function getConsultations() {
if (!$this->isAbonne())
return[];
$consultations = Class_CommSigb::getInstance()->getOnPlaceConsultationBookings($this);
if (isset($consultations['erreur']))
return [];
return $consultations;
return isset($consultations['erreur'])
? []
: $consultations;
}
......
......@@ -25,7 +25,6 @@ class ZendAfi_View_Helper_Abonne_Prets extends ZendAfi_View_Helper_Abonne_Abstra
if ($cards->isEmpty())
return '';
$nb_prets = $cards->getLoans()->count();
$str_prets = $this->view->_plural($nb_prets,
"Vous n'avez aucun prêt en cours.",
......@@ -42,7 +41,7 @@ class ZendAfi_View_Helper_Abonne_Prets extends ZendAfi_View_Helper_Abonne_Abstra
'action' => 'prets']);
$action_history_url = $this->view->url(['controller' => 'abonne',
'action' => 'loans-history']);
'action' => 'loans-history']);
$history_link = $user->providesLoansHistory()
? '<br/><br/>' . $this->_tag('a', $this->_('Voir mon historique de prêts'),
......
......@@ -18,27 +18,28 @@
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_View_Helper_Abonne_Reservations extends ZendAfi_View_Helper_Abonne_Abstract {
public function abonne_reservations($user) {
if (!$user->isAbonne())
$cards = new Class_User_Cards($user);
if ($cards->isEmpty())
return '';
$nb_resas = $user->getNbReservations() + $user->getNbConsultations();
$nb_resas = $cards->getHoldsCount();
$str_resas = $this->view->_plural($nb_resas,
"Vous n'avez aucune réservation en cours.",
"Vous avez %d réservation en cours",
"Vous avez %d réservations en cours",
$nb_resas);
"Vous n'avez aucune réservation en cours.",
"Vous avez %d réservation en cours",
"Vous avez %d réservations en cours",
$nb_resas);
$action_url = $this->view->url(['controller' => 'abonne',
'action' => 'reservations']);
return $this->tagFicheAbonne(sprintf("<a href='%s'>%s</a>",
$action_url,
$str_resas),
'reservations',
$action_url);
}
}
?>
}
\ No newline at end of file
......@@ -37,7 +37,7 @@ class ZendAfi_View_Helper_Abonne_ReservationsTable extends ZendAfi_View_Helper_B
return $this->_tag('th', $title);
},
[$this->_(''),
[$this->_('Réservé par'),
$this->_('Titre'),
$this->_('Auteur'),
$this->_('Bibliothèque'),
......@@ -67,8 +67,7 @@ class ZendAfi_View_Helper_Abonne_ReservationsTable extends ZendAfi_View_Helper_B
protected function _renderReservation($reservation) {
return
$this->_tag('tr',
$this->_tag('td',
$this->_line_no++)
$this->_tag('td', $reservation->getUserFullName())
. $this->_tag('td',
$this->_getRecordLink($reservation->getTitre(), $reservation->getNoticeOPACId()))
. $this->_tag('td',
......@@ -80,7 +79,7 @@ class ZendAfi_View_Helper_Abonne_ReservationsTable extends ZendAfi_View_Helper_B
. $this->_tag('td',
$reservation->getRang())
. $this->_tag('td',
$this->_getCancelLink($reservation->getId())));
$this->_getCancelLink($reservation)));
}
......@@ -97,11 +96,14 @@ class ZendAfi_View_Helper_Abonne_ReservationsTable extends ZendAfi_View_Helper_B
}
protected function _getCancelLink($reservation_id) {
return $this->view->tagAnchor($this->view->url(['id_delete' => $reservation_id]),
protected function _getCancelLink($reservation) {
return $this->view->tagAnchor($this->view->url(['id_delete' => $reservation->getId()]),
$this->view->tagImg(URL_IMG . 'bouton/cancel.gif',
['onclick' => 'return confirm(\''. str_replace("'", "\\'", $this->_('Etes vous sûr de vouloir supprimer cette réservation ?')) . '\')',
'title' => $this->_('Supprimer cette réservation')]));
'title' => $this->_('Supprimer la réservation du document %s',
$reservation->getTitre())]),
['data-popup' => 'true',
'data-popup-refresh' => 'true']);
}
......
......@@ -393,8 +393,13 @@ class Scenario_AbonneMultiCardsImpossiblePostActionTest extends Scenario_AbonneM
abstract class Scenario_AbonneMultiCardsAccountOfEwokTestCase extends Scenario_AbonneMultiCardsTestCase {
protected $_comm;
public function setUp() {
parent::setUp();
Class_CommSigb::setInstance($this->_comm = $this->mock());
ZendAfi_Auth::getInstance()->logUser(Class_Users::find(666));
$potter = new Class_WebService_SIGB_Emprunt('12', new Class_WebService_SIGB_Exemplaire(123));
......@@ -407,13 +412,24 @@ abstract class Scenario_AbonneMultiCardsAccountOfEwokTestCase extends Scenario_A
->setDateRetour(date('d/m/Y', strtotime('tomorrow')))
->getExemplaire()->setTitre('Alice');
$emprunteur = new Class_WebService_SIGB_Emprunteur('2', 'luke');
$emprunteur->empruntsAddAll([$potter, $alice]);
$arcadia = (new Class_WebService_SIGB_Reservation('78',
(new Class_WebService_SIGB_Exemplaire(44))->setTitre('Arcadia')));
$emprunteur = (new Class_WebService_SIGB_Emprunteur('2', 'luke'))
->empruntsAddAll([$potter, $alice])
->reservationsAddAll([$arcadia]);
Class_Users::getIdentity()
->addChildCard(Class_Users::find(2)->setFicheSIGB(['fiche' => $emprunteur]))
->addChildCard(Class_Users::find(2)
->setFicheSIGB(['fiche' => $emprunteur]))
->save();
}
public function tearDown() {
Class_CommSigb::setInstance(null);
parent::tearDown();
}
}
......@@ -439,6 +455,19 @@ class Scenario_AbonneMultiCardsAccountOfEwokFicheActionTest
$this->assertXPathContentContains('//a', 'Vous avez 2 prêts en cours (1 en retard)',
$this->_response->getBody());
}
/** @test */
public function holdsLinkShouldBePresent() {
$this->assertXPath('//a[contains(@href, "/abonne/reservations")]');
}
/** @test */
public function holdsButtonShouldContainsYouHave1Hold() {
$this->assertXPathContentContains('//a', 'Vous avez 1 réservation',
$this->_response->getBody());
}
}
......@@ -477,25 +506,67 @@ class Scenario_AbonneMultiCardsAccountOfEwokPretsActionTest
class Scenario_AbonneMultiCardsAccountOfEwokProlongerPretActionTest
extends Scenario_AbonneMultiCardsAccountOfEwokTestCase {
protected $_comm;
public function setUp() {
parent::setUp();
Class_CommSigb::setInstance($this->_comm = $this->mock()->whenCalled('prolongerPret')->answers(['statut' => true]));
$this->_comm->whenCalled('prolongerPret')->answers(['statut' => true]);
$this->dispatch('/abonne/prolongerPret/id_pret/2_12', true);
}
public function tearDown() {
Class_CommSigb::setInstance(null);
parent::tearDown();
/** @test */
public function shouldCallRenewPotterLoanOfLuke() {
$this->assertTrue($this->_comm->methodHasBeenCalledWithParams('prolongerPret', [Class_Users::find(2), 12]));
}
}
class Scenario_AbonneMultiCardsAccountOfEwokReservationsActionTest
extends Scenario_AbonneMultiCardsAccountOfEwokTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/abonne/reservations', true);
}
/** @test */
public function shouldCallRenewPotterLoanOfLuke() {
$this->assertTrue($this->_comm->methodHasBeenCalledWithParams('prolongerPret', [Class_Users::find(2), 12]));
public function shouldNotContainsErrorMessage() {
$this->assertNotXPath('//p[@class="error"]');
}
/** @test */
public function shouldContainsLukeArcadiaHold() {
$this->assertXPathContentContains('//td', 'Arcadia');
$this->assertXPathContentContains('//td', 'Luke Skywalker');
}
/** @test */
public function cancelHoldLinkShouldContainsLinkedCardId() {
$this->assertXPath('//a[contains(@href, "/abonne/reservations/id_delete/2_78")]');
}
}
?>
\ No newline at end of file
class Scenario_AbonneMultiCardsAccountOfEwokCancelReservationsActionTest
extends Scenario_AbonneMultiCardsAccountOfEwokTestCase {
public function setUp() {
parent::setUp();
$this->_comm->whenCalled('supprimerReservation')->answers([]);
$this->dispatch('/abonne/reservations/id_delete/2_78', true);
}
/** @test */
public function shouldCallCancelArcadiaHoldOfLuke() {
$this->assertTrue($this->_comm->methodHasBeenCalledWithParams('supprimerReservation', [Class_Users::find(2), 78]));
}
}
\ No newline at end of file
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