From a9fae928140aa6cb5d86a4bd7d2a44e5fef2a190 Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@afi-sa.fr> Date: Tue, 6 Oct 2015 12:36:32 +0200 Subject: [PATCH] Sandbox reviews: refacto, add simple pager and switch eye image for archive button --- .../admin/controllers/ModoController.php | 62 +++++++--------- .../admin/views/scripts/modo/avisnotice.phtml | 19 +++-- library/Class/AvisNotice.php | 74 +++++++++++++++++-- .../Cosmogramme/Integration/PhaseReviews.php | 1 - library/ZendAfi/View/Helper/AvisBloc.php | 10 ++- library/ZendAfi/View/Helper/BoutonIco.php | 4 +- .../admin/controllers/ModoControllerTest.php | 21 +++++- .../controllers/AbonneControllerAvisTest.php | 1 - 8 files changed, 135 insertions(+), 57 deletions(-) diff --git a/application/modules/admin/controllers/ModoController.php b/application/modules/admin/controllers/ModoController.php index d9c9314525c..e8b3c634584 100644 --- a/application/modules/admin/controllers/ModoController.php +++ b/application/modules/admin/controllers/ModoController.php @@ -27,23 +27,7 @@ class Admin_ModoController extends ZendAfi_Controller_Action { public function avisnoticeAction() { - - $all_avis = Class_AvisNotice::getLoader()->findAllBy(['statut' => 0,'limit'=>100]); - $all_avis = Class_AvisNotice::sortByDateAvisDesc($all_avis); - - $avis_bib = Class_AvisNotice::filterByBibliothecaire($all_avis); - $avis_abo = Class_AvisNotice::filterByAbonne($all_avis); - $orphans = Class_AvisNotice::filterByOrphan($all_avis); - $archived = Class_AvisNotice::filterByArchived($all_avis); - - $this->view->subview = $this->view->partial('modo/avisnotice.phtml', - ['list_avis_bibliothecaires' => $avis_bib, - 'list_avis_utilisateurs' => $avis_abo, - 'list_orphan_reviews' => $orphans, - 'list_archived_reviews' => $archived, - 'display_all' => true -]); - + $this->subviewForStatus(0); $this->_forward('index'); } @@ -54,7 +38,7 @@ class Admin_ModoController extends ZendAfi_Controller_Action { $review=Class_AvisNotice::find($review_id); $review->setFlags(Class_AvisNotice::ARCHIVED_FLAG)->save(); - $this->_forward('allreviews'); + $this->_forward('index'); } @@ -64,34 +48,42 @@ class Admin_ModoController extends ZendAfi_Controller_Action { $review=Class_AvisNotice::find($review_id); $review->setFlags(Class_AvisNotice::NO_FLAG)->save(); - $this->_forward('allreviews'); + $this->_forward('index'); } + protected function subviewForStatus($status) { - public function allreviewsAction() { + $page = $this->_getParam('page',1); + $nb_bib=Class_AvisNotice::countBiblioReviews($status); + $nb_abo=Class_AvisNotice::countAboReviews($status); + $display_per_page=$page*10; + $avis_bib = Class_AvisNotice::findBiblioReviews($status, + [($nb_bib<=$display_per_page)? 1: $page,10]); - $avis_bib = Class_AvisNotice::findAllBy(['abon_ou_bib' => Trait_Avis::$AVIS_BIBLIO, - 'flags' => 0, - 'order' => 'date_avis desc', - 'limitPage' => [1,20]]); - $avis_abo = Class_AvisNotice::findAllBy(['abon_ou_bib' => Trait_Avis::$AVIS_ABONNE, - 'flags' => 0, - 'order' => 'date_avis desc', - 'limitPage' => [1,20]]); - $orphans = Class_AvisNotice::findAllBy(['flags' => Class_AvisNotice::ORPHAN_FLAG, - 'order' => 'date_avis desc', - 'limitPage' => [1,20]]); - $archived = Class_AvisNotice::findAllBy(['flags' => Class_AvisNotice::ARCHIVED_FLAG, - 'order' => 'date_avis desc', - 'limitPage' => [1,20]]); + $avis_abo = Class_AvisNotice::findAboReviews($status, + [($nb_abo<=$display_per_page)? 1 : $page,10]); + $nb_orphans=Class_AvisNotice::countOrphanReviews($status); + $nb_archived=Class_AvisNotice::countArchivedReviews($status); + $orphans = Class_AvisNotice::findOrphanReviews($status,[($nb_orphans<=$display_per_page)? 1: $page,10]); + $archived = Class_AvisNotice::findArchivedReviews($status,[($nb_archived<=$display_per_page)? 1: $page,10]); $this->view->subview = $this->view->partial('modo/avisnotice.phtml', ['list_avis_bibliothecaires' => $avis_bib, 'list_avis_utilisateurs' => $avis_abo, 'list_orphan_reviews' => $orphans, 'list_archived_reviews' => $archived, - 'display_all' => false + 'display_all' => $status, + 'nb_bib' => $nb_bib, + 'nb_abo' => $nb_abo, + 'nb_orphans' => $nb_orphans, + 'nb_archived' => $nb_archived, + 'page' => $page ]); + +} + public function allreviewsAction() { + + $this->subviewForStatus(1); $this->_forward('index'); } diff --git a/application/modules/admin/views/scripts/modo/avisnotice.phtml b/application/modules/admin/views/scripts/modo/avisnotice.phtml index 8286f614fca..fe1fbf30e53 100644 --- a/application/modules/admin/views/scripts/modo/avisnotice.phtml +++ b/application/modules/admin/views/scripts/modo/avisnotice.phtml @@ -1,18 +1,23 @@ <?php -echo '<h1>'.$this->traduire('Modération des avis sur les notices').'</h1>'; + if ($this->display_all) + echo '<h1>'.$this->traduire('Tous les avis de notices').'</h1>'; +if (!$this->display_all) { + echo '<h1>'.$this->traduire('Modération des avis sur les notices').'</h1>'; echo $this->tagAnchor(['action' => 'allreviews'],"Afficher tous les avis"); +} echo '<div id="avis-notice-liste" >'; -echo $this->avisBloc('Bibliothécaires', $this->list_avis_bibliothecaires); +echo $this->avisBloc('Avis de bibliothécaires ('.$this->nb_bib.')', $this->list_avis_bibliothecaires,$this->page,$this->nb_bib); + -echo $this->avisBloc('Abonnés', $this->list_avis_utilisateurs); +echo $this->avisBloc('Avis d\'abonnés ('. $this->nb_abo.')', $this->list_avis_utilisateurs,$this->page,$this->nb_abo); -echo $this->avisBloc('Avis orphelins', $this->list_orphan_reviews); +echo $this->avisBloc('Avis orphelins ('.$this->nb_orphans.')', $this->list_orphan_reviews,$this->page,$this->nb_orphans); -echo $this->avisBloc('Avis archives', $this->list_archived_reviews); +echo $this->avisBloc('Avis archivés ('.$this->nb_archived.')', $this->list_archived_reviews,$this->page,$this->nb_archived); echo '</div>'; @@ -21,7 +26,7 @@ echo '</div>'; <script type='text/javascript'> $(document).ready(function() { $('.critique a:not(.actions a)').attr('target', '_blank'); - $('#avis-notice-liste').accordion({heightStyle:'content',collapsible:true,disabled:false, icons:null}); - $('#avis-notice-liste .ui-accordion-content').show(); + $('#avis-notice-liste').accordion({heightStyle:'content',collapsible:true,disabled:false}); +// $('#avis-notice-liste .ui-accordion-content').show(); }); </script> diff --git a/library/Class/AvisNotice.php b/library/Class/AvisNotice.php index 5cb7e9c781d..37744676f12 100644 --- a/library/Class/AvisNotice.php +++ b/library/Class/AvisNotice.php @@ -42,15 +42,75 @@ class AvisNoticeLoader extends Storm_Model_Loader { return $this; } - public function findOrphanReviews() { - return Class_AvisNotice::findAllBy(['flags' => Class_AvisNotice::ORPHAN_FLAG, - 'order' => 'date_avis']); + public function findOrphanReviews($status, $limitPage=null) { + $req = ['flags' => Class_AvisNotice::ORPHAN_FLAG, + 'order' => 'date_avis desc', + 'statut' => $status]; + if ($limitPage) + $req['limitPage'] = $limitPage; + return Class_AvisNotice::findAllBy($req); } + public function findBiblioReviews($status, $limitPage=null) { + $req = ['flags' => Class_AvisNotice::NO_FLAG, + 'abon_ou_bib' => Trait_Avis::$AVIS_BIBLIO, + 'order' => 'date_avis desc', + 'statut' => $status]; + if ($limitPage) + $req['limitPage'] = $limitPage; + return Class_AvisNotice::findAllBy($req); + } + + public function countBiblioReviews($status) { + $req = ['flags' => Class_AvisNotice::NO_FLAG, + 'abon_ou_bib' => Trait_Avis::$AVIS_BIBLIO, + 'statut' => $status]; + return Class_AvisNotice::countBy($req); + } - public function findArchivedReviews() { - return Class_AvisNotice::findAllBy(['flags' => Class_AvisNotice::ARCHIVED_FLAG, - 'order' => 'date_avis']); + public function countAboReviews($status) { + $req = ['flags' => Class_AvisNotice::NO_FLAG, + 'abon_ou_bib' => Trait_Avis::$AVIS_ABONNE, + 'statut' => $status]; + return Class_AvisNotice::countBy($req); + } + + + public function findAboReviews($status, $limitPage=null) { + $req = ['flags' => Class_AvisNotice::NO_FLAG, + 'abon_ou_bib' => Trait_Avis::$AVIS_ABONNE, + 'order' => 'date_avis desc', + 'statut' => $status]; + if ($limitPage) + $req['limitPage'] = $limitPage; + return Class_AvisNotice::findAllBy($req); + } + + + public function countOrphanReviews($status) { + $req = ['flags' => Class_AvisNotice::ORPHAN_FLAG, + 'order' => 'date_avis desc', + 'statut' => $status]; + + return Class_AvisNotice::countBy($req); + } + + public function countArchivedReviews($status) { + $req = ['flags' => Class_AvisNotice::ARCHIVED_FLAG, + 'order' => 'date_avis desc', + 'statut' => $status]; + + return Class_AvisNotice::countBy($req); + } + + public function findArchivedReviews($status,$limitPage=null) { + $req = ['flags' => Class_AvisNotice::ARCHIVED_FLAG, + 'order' => 'date_avis desc', + 'statut' => $status]; + if ($limitPage) + $req['limitPage'] = $limitPage; + + return Class_AvisNotice::findAllBy($req); } protected function _addStatutAbonBibWhereClause($abon_ou_bib, &$params) { @@ -86,7 +146,7 @@ class AvisNoticeLoader extends Storm_Model_Loader { */ public function getAvisFromPreferences($preferences, $limit_page=null, $include_orphan = false) { $params = ['order' => 'DATE_AVIS DESC']; - xdebug_break(); + if (!$include_orphan) $params['flags'] = Class_AvisNotice::NO_FLAG; $preferences = array_merge(['id_panier' => 0, diff --git a/library/Class/Cosmogramme/Integration/PhaseReviews.php b/library/Class/Cosmogramme/Integration/PhaseReviews.php index 7f2c917b534..40aa67d398d 100644 --- a/library/Class/Cosmogramme/Integration/PhaseReviews.php +++ b/library/Class/Cosmogramme/Integration/PhaseReviews.php @@ -48,7 +48,6 @@ class Class_Cosmogramme_Integration_PhaseReviews extends Class_Cosmogramme_Integ public function _execute() { - xdebug_break(); $this->_setData('pointeur_notice', 0); while ($records = Class_AvisNotice::findAllAfter($this->_getData('pointeur_notice'))) { diff --git a/library/ZendAfi/View/Helper/AvisBloc.php b/library/ZendAfi/View/Helper/AvisBloc.php index 05d4817d0de..db6fa4fb26e 100644 --- a/library/ZendAfi/View/Helper/AvisBloc.php +++ b/library/ZendAfi/View/Helper/AvisBloc.php @@ -21,13 +21,13 @@ class ZendAfi_View_Helper_AvisBloc extends Zend_View_Helper_HtmlElement { - public function avisBloc($libelle_bloc, $avis_list) { + public function avisBloc($libelle_bloc, $avis_list,$page=0,$nb_elements=0) { $libelle_bloc = $this->view->_($libelle_bloc); - return $this->renderHtmlAvisBloc($libelle_bloc, $avis_list); + return $this->renderHtmlAvisBloc($libelle_bloc, $avis_list,$page,$nb_elements); } - public function renderHtmlAvisBloc($libelle, $list) { + public function renderHtmlAvisBloc($libelle, $list,$page=0 ,$nb_elements=0) { $html = '<h2>'.$libelle.'</h2>'; $html.= '<div>'; @@ -41,7 +41,11 @@ class ZendAfi_View_Helper_AvisBloc extends Zend_View_Helper_HtmlElement { $list, ['first', 'second']); + if ($page>0) + $html.= $this->view->Pager($nb_elements,10,$page,$this->view->url(['page' => null],null,false)); } + + return $html.='</div>'; } diff --git a/library/ZendAfi/View/Helper/BoutonIco.php b/library/ZendAfi/View/Helper/BoutonIco.php index 2f3e8972fb0..6abedb0e2bb 100644 --- a/library/ZendAfi/View/Helper/BoutonIco.php +++ b/library/ZendAfi/View/Helper/BoutonIco.php @@ -72,8 +72,8 @@ class ZendAfi_View_Helper_BoutonIco extends ZendAfi_View_Helper_BaseHelper { 'TEST' => ['tester.gif', $this->traduire('Tester')], 'SHOW' => ['show.gif', $this->traduire('Visualiser')], 'MAIL' => ['mail.png', $this->traduire('Envoyer par mail')], - 'VISIBLE' => ['show.gif', $this->traduire('Rendre visible')], - 'INVISIBLE' => ['hide.gif', $this->traduire('Archiver')] + 'VISIBLE' => ['hide.gif', $this->traduire('Rendre visible')], + 'INVISIBLE' => ['show.gif', $this->traduire('Archiver')] ]; $type = strtoupper($type); diff --git a/tests/application/modules/admin/controllers/ModoControllerTest.php b/tests/application/modules/admin/controllers/ModoControllerTest.php index a4d7eaab000..e3c0d8dfa32 100644 --- a/tests/application/modules/admin/controllers/ModoControllerTest.php +++ b/tests/application/modules/admin/controllers/ModoControllerTest.php @@ -655,13 +655,32 @@ class ModoControllerAllReviewsActionTest extends ModoControllerIndexActionTest { } -class ModoControllerArchivedReviewsActionTest extends ModoControllerIndexActionTest { + + + +class ModoControllerAllReviewsPageActionTest extends ModoControllerIndexActionTest { public function setup() { parent::setup(); + $this->dispatch('admin/modo/allreviews/page/10', true); + } + + /** @test **/ + public function moderatedReviewsShouldBeDisplayedEvenIfPageIsOutOfBound() { + $this->assertXpathContentContains('//div//h2', 'B comme bière : la bière expliquée aux (grands) enfants', $this->_response->getBody()); } +} + + + +class ModoControllerArchivedReviewsActionTest extends ModoControllerIndexActionTest { + + public function setup() { + parent::setup(); + + } /** @test **/ public function moderatedReviewsShouldBeArchived() { diff --git a/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php b/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php index 9b161b7c342..f081f6303ee 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php @@ -826,7 +826,6 @@ class AbonneControllerEditAvisNoticeNotFoundActionTest extends AbstractControlle /** @test */ public function responseShouldReloadPage() { - xdebug_break(); $this->assertTrue(false !== strpos(json_decode($this->_response->getBody())->title, 'Sauvegarde en cours')); } } -- GitLab