From 381ac59b1fc7c5dc17f7af97c6e64074e952c3a3 Mon Sep 17 00:00:00 2001
From: lbrun <leo@sandbox.pergame.net>
Date: Thu, 11 Feb 2016 11:22:12 +0100
Subject: [PATCH] 
 hotline#33533_avis_disfonctionnement_affichage_des_boites_accordeon_sur_validation
 :

keep params in differents actions
---
 VERSIONS_HOTLINE/33533                        |  1 +
 .../admin/controllers/ModoController.php      | 17 ++++++-----
 .../views/scripts/modo/_avis_partial.phtml    |  9 ------
 .../admin/views/scripts/modo/avisnotice.phtml | 12 ++++++--
 .../admin/views/scripts/modo/index.phtml      | 13 ++++----
 library/ZendAfi/Form/Admin/EditAvis.php       |  3 +-
 library/ZendAfi/View/Helper/Avis.php          | 22 ++++++++++++--
 library/ZendAfi/View/Helper/AvisBloc.php      | 30 +++++++++++++++----
 .../admin/controllers/ModoControllerTest.php  |  8 ++---
 9 files changed, 78 insertions(+), 37 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/33533
 delete mode 100644 application/modules/admin/views/scripts/modo/_avis_partial.phtml

diff --git a/VERSIONS_HOTLINE/33533 b/VERSIONS_HOTLINE/33533
new file mode 100644
index 00000000000..a225c46858a
--- /dev/null
+++ b/VERSIONS_HOTLINE/33533
@@ -0,0 +1 @@
+ - ticket #33533 : Administration : Moderation d'avis : Disfonctionnement affichage des boites accordeon sur validation
\ No newline at end of file
diff --git a/application/modules/admin/controllers/ModoController.php b/application/modules/admin/controllers/ModoController.php
index 889ec5bd327..20259be9af0 100644
--- a/application/modules/admin/controllers/ModoController.php
+++ b/application/modules/admin/controllers/ModoController.php
@@ -27,7 +27,9 @@ class Admin_ModoController extends ZendAfi_Controller_Action {
 
 
   public function avisnoticeAction() {
-    $this->subviewForStatus(0);
+    $status = $this->_getParam('status', 0);
+    $this->subviewForStatus($status);
+
     $this->_request->setParam('back', 'avisnotice');
     $this->_forward('index');
   }
@@ -103,14 +105,8 @@ class Admin_ModoController extends ZendAfi_Controller_Action {
 
                                                  'active_tab' => $active_tab]);
 
-}
-  public function allreviewsAction() {
-    $this->_request->setParam('back', 'avisnotice');
-    $this->subviewForStatus(1);
-    $this->_forward('index');
   }
 
-
   public function delavisnoticeAction() {
     $id = $this->_request->getParam('id');
     Class_AvisNotice::find($id)->delete();
@@ -158,10 +154,15 @@ class Admin_ModoController extends ZendAfi_Controller_Action {
 
   public function validateavisnoticeAction() {
     $id = $this->_request->getParam('id');
+    $page = $this->_request->getParam('page');
+    $active_tab = $this->_request->getParam('active_tab');
+    $status = $this->_request->getParam('status');
+
     Class_AvisNotice::find($id)
       ->setModerationOK()
       ->save();
-    $this->_redirect('admin/modo/avisnotice');
+
+    $this->_redirect('/admin/modo/avisnotice/status/' . $status . '/active_tab/' . $active_tab . '/page/' . $page);
   }
 
 
diff --git a/application/modules/admin/views/scripts/modo/_avis_partial.phtml b/application/modules/admin/views/scripts/modo/_avis_partial.phtml
deleted file mode 100644
index d62871b971c..00000000000
--- a/application/modules/admin/views/scripts/modo/_avis_partial.phtml
+++ /dev/null
@@ -1,9 +0,0 @@
-<div class="<?php echo $this->item_class ?>">
-  <?php
-  $actions = ['validate', 'edit', 'del'];
-  if ($this->avis->getFlags()>=0)
-    $actions[] = ($this->avis->getFlags()==0) ? 'invisible' :'visible';
-  $this->getHelper('avis')->setActions($actions); ?>
-   <?php echo $this->avis($this->avis) ?>
-   <div class='clear'></div>
-</div>
diff --git a/application/modules/admin/views/scripts/modo/avisnotice.phtml b/application/modules/admin/views/scripts/modo/avisnotice.phtml
index 5443bf7c18c..2723490bbf9 100644
--- a/application/modules/admin/views/scripts/modo/avisnotice.phtml
+++ b/application/modules/admin/views/scripts/modo/avisnotice.phtml
@@ -1,11 +1,19 @@
 <?php
 if ($this->display_all)
   echo $this->tag('h1', $this->_('Tous les avis de notices modérés')) .
-       $this->tagAnchor(['action' => 'avisnotice'], $this->_('Afficher les avis non modérés'));
+       $this->tagAnchor(['action' => 'avisnotice',
+                         'status' => '0',
+                         'active_tab' => null,
+                         'page' => null],
+                        $this->_('Afficher les avis non modérés'));
 
 if (!$this->display_all)
   echo $this->tag('h1', $this->_('Modération des avis sur les notices')) .
-       $this->tagAnchor(['action' => 'allreviews'], $this->_('Afficher tous les avis modérés'));
+       $this->tagAnchor(['action' => 'avisnotice',
+                         'status' => '1',
+                         'active_tab' => null,
+                         'page' => null],
+                        $this->_('Afficher tous les avis modérés'));
 
 echo $this->tag('div',
 
diff --git a/application/modules/admin/views/scripts/modo/index.phtml b/application/modules/admin/views/scripts/modo/index.phtml
index b60b9b001c5..c849f31edae 100644
--- a/application/modules/admin/views/scripts/modo/index.phtml
+++ b/application/modules/admin/views/scripts/modo/index.phtml
@@ -4,19 +4,22 @@ $modstats = $moderer->getModerationStats();
 
 $menus = [["icon" => "article.png",
            "label" => "Articles",
-           "url" => $this->url(['action' => 'aviscms']),
+           "url" => $this->url(['module' => 'admin', 'controller' => 'modo', 'action' => 'aviscms'], null, true),
            "count" => $modstats['avis_articles']['count']],
+
           ["icon" => "books.png",
            "label" => "Notices",
-           "url" =>$this->url(['action' => 'avisnotice']),
+           "url" =>$this->url(['module' => 'admin', 'controller' => 'modo', 'action' => 'avisnotice'], null, true),
            "count" => $modstats['avis_notices']['count']],
+
           ["icon" => "tag_blue.png",
            "label" => "Tags notices",
-           "url" => $this->url(['action' => 'tagnotice']),
+           "url" => $this->url(['module' => 'admin', 'controller' => 'modo', 'action' => 'tagnotice'], null, true),
            "count" => $modstats['tags_notices']['count']],
+
           ["icon" => "traductions_16.png",
            "label" => "Suggestions d'achat",
-           "url" => $this->url(['action' => 'suggestion-achat']),
+           "url" => $this->url(['module' => 'admin', 'controller' => 'modo', 'action' => 'suggestion-achat'], null, true),
            "count" => $modstats['suggestions_achat']['count']]
 
 ];
@@ -25,7 +28,7 @@ if (isset($modstats['formulaires'])) {
   $menus[] =
   ["icon" => "formulaires_16.png",
    "label" => "Formulaires",
-   "url" => $this->url(['action' => 'formulaires', 'id_article' => null]),
+   "url" => $this->url(['action' => 'formulaires', 'id_article' => null, 'status' => null, 'active_tab' => null, 'page' => null]),
    "count" => $modstats['formulaires']['count']]
   ;}
 ?>
diff --git a/library/ZendAfi/Form/Admin/EditAvis.php b/library/ZendAfi/Form/Admin/EditAvis.php
index c11db2b589e..c7556b835ac 100644
--- a/library/ZendAfi/Form/Admin/EditAvis.php
+++ b/library/ZendAfi/Form/Admin/EditAvis.php
@@ -41,7 +41,8 @@ class ZendAfi_Form_Admin_EditAvis extends ZendAfi_Form {
     $this->setAttrib('data-backurl',
                      $this->getView()->url(['module' => 'admin',
                                             'controller' => 'modo',
-                                            'action' => $action], null, true));
+                                            'action' => $action,
+                                            'id' => null]));
     return $this;
   }
 
diff --git a/library/ZendAfi/View/Helper/Avis.php b/library/ZendAfi/View/Helper/Avis.php
index e13c8854fdf..048fcb0a6b0 100644
--- a/library/ZendAfi/View/Helper/Avis.php
+++ b/library/ZendAfi/View/Helper/Avis.php
@@ -25,6 +25,8 @@ class ZendAfi_View_Helper_Avis extends ZendAfi_View_Helper_BaseHelper {
   protected $_actions = [];
   protected $_admin_actions = [];
   protected $_url_context = [];
+  protected $_active_tab = 0;
+  protected $_page = 0;
 
   public function setVignetteLinkToAvis() {
     $this->_vignette_link_to_avis = true;
@@ -43,6 +45,16 @@ class ZendAfi_View_Helper_Avis extends ZendAfi_View_Helper_BaseHelper {
   }
 
 
+  public function setActiveTab($active_tab) {
+    $this->_active_tab = $active_tab;
+  }
+
+
+  public function setPage($page) {
+    $this->_page = $page;
+  }
+
+
   public function setAdminActions($actions) {
     $this->_admin_actions = $actions;
     return $this;
@@ -220,8 +232,11 @@ class ZendAfi_View_Helper_Avis extends ZendAfi_View_Helper_BaseHelper {
     $suffix = ($avis->isAvisNotice()) ? 'avisnotice' : '-aviscms';
     foreach($this->_actions as $action) {
       $link = $this->view->tagAnchor($this->_url(['action' => $action . $suffix,
-                                                  'id' => $avis->getId()]),
+                                                  'id' => $avis->getId(),
+                                                  'active_tab' => $this->_active_tab,
+                                                  'page' => $this->_page]),
                                      $this->view->boutonIco('type=' . $action));
+
       $html_actions .= $this->_tag('span', $link, ['rel' => $action]);
     }
 
@@ -237,11 +252,12 @@ class ZendAfi_View_Helper_Avis extends ZendAfi_View_Helper_BaseHelper {
 
   protected function _getAdminActionsTag($avis) {
     $html_actions = '';
-
     foreach($this->_admin_actions as $action) {
       $link = $this->view->tagAnchor($this->_url(['controller' => 'abonne',
                                                   'action' => $action . 'avisnotice',
-                                                  'id' => $avis->getId()]),
+                                                  'id' => $avis->getId(),
+                                                  'active_tab' => $this->_active_tab,
+                                                  'page' => $this->_page]),
                                      $this->view->boutonIco('type=' .$action),
                                      ['data-popup' => 'true']);
       $html_actions .= $this->_tag('span', $link, ['rel' => $action]);
diff --git a/library/ZendAfi/View/Helper/AvisBloc.php b/library/ZendAfi/View/Helper/AvisBloc.php
index 22ee7bf9ff4..19361663327 100644
--- a/library/ZendAfi/View/Helper/AvisBloc.php
+++ b/library/ZendAfi/View/Helper/AvisBloc.php
@@ -43,13 +43,33 @@ class ZendAfi_View_Helper_AvisBloc extends Zend_View_Helper_HtmlElement {
   protected function renderBlock() {
     if(!count($this->_list))
       return $this->view->tag('p',
-                              $this->view->_('Aucun avis %s à modérer.', ($this->_label ? $this->_label : '')),
+                              $this->view->_('Aucun avis %s à modérer.',
+                                             ($this->_label ? $this->_label : '')),
                               ['class' => 'error']);
 
-    return $this->injectPager($this->view->partialCycle('modo/_avis_partial.phtml',
-                                                              'avis',
-                                                              $this->_list,
-                                                              ['first', 'second']));
+    $html = '';
+    foreach ($this->_list as $avis)
+      $html .= $this->_renderAvis($avis);
+
+    return $this->injectPager($html);
+  }
+
+
+  protected function _renderAvis($avis) {
+    $actions = ['validate', 'edit', 'del'];
+    if ($avis->getFlags() >= 0)
+      $actions[] = ($avis->getFlags() == 0) ? 'invisible' : 'visible';
+
+    $helper = $this->view->getHelper('avis');
+
+    $helper->setActions($actions);
+    $helper->setActiveTab($this->_index);
+    $helper->setPage($this->_page);
+
+    $html = $this->view->avis($avis) .
+      $this->view->tag('div', '', ['class' => 'clear']);
+
+    return $this->view->tag('div', $html);
   }
 
 
diff --git a/tests/application/modules/admin/controllers/ModoControllerTest.php b/tests/application/modules/admin/controllers/ModoControllerTest.php
index 1ca2ae894bb..2f46be2ff81 100644
--- a/tests/application/modules/admin/controllers/ModoControllerTest.php
+++ b/tests/application/modules/admin/controllers/ModoControllerTest.php
@@ -691,7 +691,7 @@ class ModoControllerAllReviewsActionTest extends ModoControllerIndexActionTestCa
 
   public function setup() {
     parent::setup();
-    $this->dispatch('admin/modo/allreviews', true);
+    $this->dispatch('admin/modo/avisnotice/status/1', true);
   }
 
 
@@ -736,21 +736,21 @@ class ModoControllerAllReviewsPageActionTest extends ModoControllerIndexActionTe
 
   /** @test **/
   public function moderatedReviewsShouldBeDisplayedEvenIfPageIsOutOfBound() {
-    $this->dispatch('admin/modo/allreviews/page/10', true);
+    $this->dispatch('admin/modo/avisnotice/status/1/page/10', true);
     $this->assertXpathContentContains('//div//h2', 'B comme bière : la bière expliquée aux (grands) enfants');
   }
 
 
   /** @test **/
   public function page3ShouldNotConstainsTheLastReviewSaved139() {
-    $this->dispatch('admin/modo/allreviews/page/3/active_tab/1', true);
+$this->dispatch('admin/modo/avisnotice/status/1/page/3/active_tab/1', true);
     $this->assertNotXpathContentContains('//div[@class="critique"]//div[@class="contenu_critique"]//a[contains(@href, "blog/viewavis")]', '139');
   }
 
 
   /** @test */
   public function page1ShouldContains10Reviews() {
-    $this->dispatch('admin/modo/allreviews/page/1/active_tab/1', true);
+    $this->dispatch('admin/modo/avisnotice/status/1/page/1/active_tab/1', true);
     $this->assertXPathContentContains('//div[2]/span', 'résultats sur cette page.', $this->_response->getBody());
   }
 }
-- 
GitLab