From 39a64bc711048bc8b0463df8ed19eec9434cd471 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Tue, 17 Jan 2017 16:05:29 +0100 Subject: [PATCH] hotline #50082 plug holds and loans renderers to new record fetching method --- .../opac/controllers/AbonneController.php | 2 +- .../views/scripts/abonne/loans-history.phtml | 2 +- .../opac/views/scripts/abonne/prets.phtml | 4 +- .../views/scripts/abonne/reservations.phtml | 5 ++- .../views/scripts/abonne/fiche.phtml | 4 +- library/Class/Exemplaire.php | 4 +- library/ZendAfi/View/Helper/Abonne/Loans.php | 40 +++++++++++------- .../ZendAfi/View/Helper/Abonne/LoansPNB.php | 6 +-- .../View/Helper/Abonne/ReservationsTable.php | 42 +++++++++++++------ .../View/Helper/Accueil/Reservations.php | 10 +++-- .../Helper/Abonne/ReservationsTableTest.php | 2 +- 11 files changed, 77 insertions(+), 44 deletions(-) diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 9fed5713880..cddc9f53fef 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -27,7 +27,7 @@ class AbonneController extends ZendAfi_Controller_Action { if ('authenticate' == $this->getRequest()->getActionName()) return; - $this->_user = Class_Users::getIdentity(); + $this->_user = $this->view->user = Class_Users::getIdentity(); $this->clearEmprunteurCache(); diff --git a/application/modules/opac/views/scripts/abonne/loans-history.phtml b/application/modules/opac/views/scripts/abonne/loans-history.phtml index 3518eba9770..73191414a57 100644 --- a/application/modules/opac/views/scripts/abonne/loans-history.phtml +++ b/application/modules/opac/views/scripts/abonne/loans-history.phtml @@ -6,7 +6,7 @@ if ($this->error) $this->error, ['class' => 'error']); -echo $this->abonne_Loans(($this->loans ? $this->loans : []), false); +echo $this->abonne_Loans($this->user, ($this->loans ? $this->loans : []), false); $this->closeBoite(); echo $this->abonne_RetourFiche(); diff --git a/application/modules/opac/views/scripts/abonne/prets.phtml b/application/modules/opac/views/scripts/abonne/prets.phtml index 32340c23b3c..5f3c029e817 100644 --- a/application/modules/opac/views/scripts/abonne/prets.phtml +++ b/application/modules/opac/views/scripts/abonne/prets.phtml @@ -29,13 +29,13 @@ if ($emprunts = $this->user->getEmprunts()) { echo $this->abonne_LoanExport(); } -echo $this->abonne_Loans($loans); +echo $this->abonne_Loans($this->user, $loans); echo $extend_all; if($this->user->hasPNB()) { echo $this->tag('h2', $this->_('Prêts numériques en cours')); - echo $this->abonne_LoansPNB($this->user->getPNBLoans()); + echo $this->abonne_LoansPNB($this->user, $this->user->getPNBLoans()); } $this->closeBoite(); diff --git a/application/modules/opac/views/scripts/abonne/reservations.phtml b/application/modules/opac/views/scripts/abonne/reservations.phtml index faf3b29d52d..30cae0b908b 100644 --- a/application/modules/opac/views/scripts/abonne/reservations.phtml +++ b/application/modules/opac/views/scripts/abonne/reservations.phtml @@ -6,14 +6,15 @@ $this->openBoite($this->_('Réservations en cours')); echo $this->tag('div', $this->user->getNomAff(), ['class' => 'abonneTitre']); $cards = new Class_User_Cards($this->user); -echo $this->abonne_ReservationsTable($cards->getHolds(), $this->fiche); +echo $this->abonne_ReservationsTable($this->user, $cards->getHolds(), $this->fiche); $this->closeBoite(); if (!empty($this->consultations_reservations)) { $this->openBoite($this->_('Réservations pour la consultation sur place')); - echo $this->abonne_OnPlaceConsultationReservationsTable($this->consultations_reservations, + echo $this->abonne_OnPlaceConsultationReservationsTable($this->user, + $this->consultations_reservations, $this->fiche); $this->closeBoite(); } diff --git a/application/modules/telephone/views/scripts/abonne/fiche.phtml b/application/modules/telephone/views/scripts/abonne/fiche.phtml index aeead44b419..59134f5a161 100644 --- a/application/modules/telephone/views/scripts/abonne/fiche.phtml +++ b/application/modules/telephone/views/scripts/abonne/fiche.phtml @@ -38,10 +38,10 @@ $nb_resas = $this->user->getNbReservations(); ?> <?php -echo $this->abonne_Loans($cards->getLoansWithOutPNB(), $this->_('Mes prêts')); +echo $this->abonne_Loans($this->user, $cards->getLoansWithOutPNB(), $this->_('Mes prêts')); if ($this->user->hasPNB()) - echo $this->abonne_Loans($this->user->getPNBLoans(), $this->_('Mes prêts numériques')); + echo $this->abonne_Loans($this->user, $this->user->getPNBLoans(), $this->_('Mes prêts numériques')); echo $this->abonne_Holds($cards->getHolds()); ?> diff --git a/library/Class/Exemplaire.php b/library/Class/Exemplaire.php index f9294d5f70b..0d8939c1607 100644 --- a/library/Class/Exemplaire.php +++ b/library/Class/Exemplaire.php @@ -31,8 +31,8 @@ class Class_ExemplaireLoader extends Storm_Model_Loader { if (!array_filter($params)) return null; - $int_bibs = Class_IntBib::findAllAvailableForUser($user); - if($int_bibs->isEmpty()) + + if(!($int_bibs = Class_IntBib::findAllAvailableForUser($user)) || $int_bibs->isEmpty()) return null; $params['id_int_bib'] = $int_bibs->collect('id')->getArrayCopy(); diff --git a/library/ZendAfi/View/Helper/Abonne/Loans.php b/library/ZendAfi/View/Helper/Abonne/Loans.php index ed8c27771ec..f10a2164b1a 100644 --- a/library/ZendAfi/View/Helper/Abonne/Loans.php +++ b/library/ZendAfi/View/Helper/Abonne/Loans.php @@ -25,13 +25,13 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_BaseHelper { $_line_no, $_in_progress; - public function abonne_Loans($loans, $in_progress = true) { + public function abonne_Loans($user, $loans, $in_progress = true) { $this->_in_progress = $in_progress; Class_ScriptLoader::getInstance()->loadTableSorter(); return $this->_tag('table', $this->renderHeader() - . $this->renderLoans($loans), + . $this->renderLoans($user, $loans), ['class' => $this->_in_progress ? 'tablesorter loans' : 'tablesorter loans-history']); } @@ -42,12 +42,7 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_BaseHelper { function($title) { return $this->_tag('th', $title); }, - [$this->_('Emprunté par'), - $this->_('Titre'), - $this->_('Auteur'), - $this->_in_progress ? $this->_('Bibliothèque') : $this->_('Date d\'emprunt'), - $this->_in_progress ? $this->_('Retour prévu') : $this->_('Date de retour'), - $this->_('Informations')]); + $this->_tableColumns()); return $this->_tag('thead', $this->_tag('tr', @@ -66,7 +61,7 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_BaseHelper { } - protected function renderLoans($loans) { + protected function renderLoans($user, $loans) { $this->_line_no = 1; $html = ''; @@ -74,16 +69,19 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_BaseHelper { $loans = array_reverse($loans->getArrayCopy()); foreach($loans as $loan) - $html .= $this->renderLoan($loan); + $html .= $this->renderLoan($user, $loan); return $this->_tag('tbody', $html); } - protected function renderLoan($loan) { + protected function renderLoan($user, $loan) { $record_title = $loan->getTitre(); + $record = new Class_Entity(); + if($item = Class_Exemplaire::findFirstBySIGBOperation($user,$loan)) + $record = $item->getNotice(); - if ($record = $loan->getNoticeOPAC()) + if ($record) $record_title = $this->view->tagAnchor($this->view->url( ['controller' => 'recherche', 'action' => 'viewnotice', @@ -96,11 +94,11 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_BaseHelper { $this->_tag('td', $loan->getUserFullName()) . $this->_tag('td', - $record ? $record->getTypeDocLabel() : '') + $record->getTypeDocLabel()) . $this->_tag('td', $record_title) . $this->_tag('td', - $loan->getAuteur()) + $this->_getAuthorLink($record->getAuteurPrincipal())) . $this->_tag('td', $this->_in_progress ? $loan->getBibliotheque() : $loan->getIssueDate()) . $this->_tag('td', @@ -109,4 +107,18 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_BaseHelper { $loan->getType()), ($loan->isLate() && $this->_in_progress) ? ['class' => 'pret_en_retard'] : []); } + + + protected function _getAuthorLink($author) { + if(!$facet = Class_CodifAuteur::findFirstBy(['libelle' => $author])) + return $author; + + return $this->view->tagAnchor($this->view->url(['controller' => 'recherche', + 'action' => 'simple', + 'facette' => Class_CodifAuteur::CODE_FACETTE . $facet->getId(), + 'retour_abonne' => 'prets'], + null, true), + $author); + } + } \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Abonne/LoansPNB.php b/library/ZendAfi/View/Helper/Abonne/LoansPNB.php index bc5c9c0d35b..6621427ac1b 100644 --- a/library/ZendAfi/View/Helper/Abonne/LoansPNB.php +++ b/library/ZendAfi/View/Helper/Abonne/LoansPNB.php @@ -21,8 +21,8 @@ class ZendAfi_View_Helper_Abonne_LoansPNB extends ZendAfi_View_Helper_Abonne_Loans { - public function abonne_LoansPNB($loans, $in_progress = true) { - return parent::abonne_Loans($loans, $in_progress); + public function abonne_LoansPNB($user, $loans, $in_progress = true) { + return parent::abonne_Loans($user, $loans, $in_progress); } @@ -35,7 +35,7 @@ class ZendAfi_View_Helper_Abonne_LoansPNB extends ZendAfi_View_Helper_Abonne_Loa } - protected function renderLoan($loan) { + protected function renderLoan($user, $loan) { $record_title = $loan->getTitre(); if ($record_id = $loan->getNoticeOPACId()) diff --git a/library/ZendAfi/View/Helper/Abonne/ReservationsTable.php b/library/ZendAfi/View/Helper/Abonne/ReservationsTable.php index f8508ffb66a..f3932de4576 100644 --- a/library/ZendAfi/View/Helper/Abonne/ReservationsTable.php +++ b/library/ZendAfi/View/Helper/Abonne/ReservationsTable.php @@ -23,10 +23,11 @@ class ZendAfi_View_Helper_Abonne_ReservationsTable extends ZendAfi_View_Helper_BaseHelper { protected $_line_no; - public function abonne_ReservationsTable($reservations, $fiche) { + public function abonne_ReservationsTable($user, $reservations, $fiche) { Class_ScriptLoader::getInstance()->loadTableSorter(); return $this->_tag('table', - $this->_renderHeader() . $this->_renderReservations($reservations, $fiche), + $this->_renderHeader() + . $this->_renderReservations($user, $reservations, $fiche), ['class' => 'tablesorter reservations']); } @@ -53,29 +54,31 @@ class ZendAfi_View_Helper_Abonne_ReservationsTable extends ZendAfi_View_Helper_B } - protected function _renderReservations($reservations, $fiche) { + protected function _renderReservations($user, $reservations, $fiche) { $html = ''; $html .= (isset($fiche['message']) && $fiche['message'] ? $this->_renderError($fiche['message']) : ''); $html .= (isset($fiche['erreur']) && $fiche['erreur'] ? $this->_renderError($fiche['erreur']) : ''); $this->_line_no = 1; foreach($reservations as $reservation) - $html .= $this->_renderReservation($reservation); + $html .= $this->_renderReservation($user, $reservation); return $this->_tag('tbody', $html); } - protected function _renderReservation($reservation) { - $record = $reservation->getNoticeOPAC(); + protected function _renderReservation($user, $reservation) { + $record = new Class_Entity(); + if($item = Class_Exemplaire::findFirstBySIGBOperation($user, $reservation)) + $record = $item->getNotice(); return $this->_tag('tr', $this->_tag('td', $reservation->getUserFullName()) - . $this->_tag('td', $record ? $record->getTypeDocLabel() : '') + . $this->_tag('td', $record->getTypeDocLabel()) . $this->_tag('td', - $this->_getRecordLink($reservation->getTitre(), $reservation->getNoticeOPACId())) + $this->_getRecordLink($reservation->getTitre(), $record->getId())) . $this->_tag('td', - strip_tags($reservation->getAuteur())) + strip_tags($record->getAuteurPrincipal())) . $this->_tag('td', $reservation->getBibliotheque()) . $this->_tag('td', @@ -100,6 +103,19 @@ class ZendAfi_View_Helper_Abonne_ReservationsTable extends ZendAfi_View_Helper_B } + protected function _getAuthorLink($author) { + if(!$facet = Class_CodifAuteur::findByLastNameFirstName($author, $author)) + return $author; + + return $this->view->tagAnchor($this->view->url(['controller' => 'recherche', + 'action' => 'simple', + 'facette' => $facet, + 'retour_abonne' => 'reservations'], + null, true), + $author); + } + + protected function _getCancelLink($reservation) { return $this->view->tagAnchor($this->view->url(['id_delete' => $reservation->getId()]), $this->view->tagImg(URL_IMG . 'bouton/cancel.gif', @@ -124,13 +140,13 @@ class ZendAfi_View_Helper_Abonne_ReservationsTable extends ZendAfi_View_Helper_B class ZendAfi_View_Helper_Abonne_OnPlaceConsultationReservationsTable extends ZendAfi_View_Helper_Abonne_ReservationsTable { - public function abonne_OnPlaceConsultationReservationsTable($reservations, $fiche) { + public function abonne_OnPlaceConsultationReservationsTable($user, $reservations, $fiche) { if (isset($reservations['erreur'])) return ''; Class_ScriptLoader::getInstance()->loadTableSorter(); return $this->_tag('table', - $this->_renderHeader() . $this->_renderReservations($reservations, $fiche), + $this->_renderHeader() . $this->_renderReservations($user, $reservations, $fiche), ['class' => 'tablesorter reservations']); } @@ -155,7 +171,7 @@ class ZendAfi_View_Helper_Abonne_OnPlaceConsultationReservationsTable extends Ze } - protected function _renderReservation($reservation) { + protected function _renderReservation($user, $reservation) { $record = $reservation->getRecord(); return $this->_tag('tr', @@ -165,7 +181,7 @@ class ZendAfi_View_Helper_Abonne_OnPlaceConsultationReservationsTable extends Ze $this->_getRecordLink($reservation->getTitle(), $reservation->getRecordId())) . $this->_tag('td', - strip_tags($record ? $record->getAuteurPrincipal() : '')) + $this->_getAuthorLink($record->getAuteurPrincipal())) . $this->_tag('td', $reservation->getLocationLabel()) . $this->_tag('td', diff --git a/library/ZendAfi/View/Helper/Accueil/Reservations.php b/library/ZendAfi/View/Helper/Accueil/Reservations.php index d305a0dec48..dd9a235361a 100644 --- a/library/ZendAfi/View/Helper/Accueil/Reservations.php +++ b/library/ZendAfi/View/Helper/Accueil/Reservations.php @@ -28,12 +28,16 @@ class ZendAfi_View_Helper_Accueil_Reservations extends ZendAfi_View_Helper_Accue } - public function renderModelReservations($reservations) { + public function renderModelReservations($user, $reservations) { $html = ''; foreach ($reservations as $reservation) { + $record = null; + if($item = Class_Exemplaire::findFirstBySIGBOperation($user, $reservation)) + $record = $item->getNotice(); + $html .= $this->renderElement($reservation->getTitre(), $reservation->getEtat(), - $reservation->getNoticeOPAC()); + $record); } return $html; } @@ -55,7 +59,7 @@ class ZendAfi_View_Helper_Accueil_Reservations extends ZendAfi_View_Helper_Accue public function getContenu() { return - $this->renderModelReservations((new Class_User_Cards($this->_abonne))->getHolds()) . + $this->renderModelReservations($this->_abonne, (new Class_User_Cards($this->_abonne))->getHolds()) . $this->renderModelConsultations($this->_abonne->getConsultations()); } } diff --git a/tests/library/ZendAfi/View/Helper/Abonne/ReservationsTableTest.php b/tests/library/ZendAfi/View/Helper/Abonne/ReservationsTableTest.php index 048cf366837..02f0fc74d79 100644 --- a/tests/library/ZendAfi/View/Helper/Abonne/ReservationsTableTest.php +++ b/tests/library/ZendAfi/View/Helper/Abonne/ReservationsTableTest.php @@ -52,7 +52,7 @@ class ReservationsTableTest extends ViewHelperTestCase { $helper->setView(new ZendAfi_Controller_Action_Helper_View()); $cards = new Class_User_Cards($user); - $this->_html = $helper->abonne_ReservationsTable($cards->getHolds(), $user->getFicheSigb()); + $this->_html = $helper->abonne_ReservationsTable($user, $cards->getHolds(), $user->getFicheSigb()); } -- GitLab