From b346fef16e92208db0a58629289704196005de9c Mon Sep 17 00:00:00 2001 From: lbrun <leo@sandbox.pergame.net> Date: Fri, 26 Feb 2016 11:25:43 +0100 Subject: [PATCH] dev#37281 : fix rt --- .../admin/controllers/BibnumController.php | 19 ++++-------- library/Class/AlbumCategorie.php | 20 ++++++------ .../View/Helper/Accueil/BibNumerique.php | 11 ++----- .../controllers/BibnumControllerTest.php | 31 +++++++++++++++++-- 4 files changed, 46 insertions(+), 35 deletions(-) diff --git a/application/modules/admin/controllers/BibnumController.php b/application/modules/admin/controllers/BibnumController.php index 5f2f5363b29..90821b401bc 100644 --- a/application/modules/admin/controllers/BibnumController.php +++ b/application/modules/admin/controllers/BibnumController.php @@ -26,28 +26,21 @@ class Admin_BibnumController extends ZendAfi_Controller_Action { } public function collectionsAction() { - $this->_helper->viewRenderer->setNoRender(); - $categories = Class_AlbumCategorie::getCollections(); $categories[] = Class_AlbumCategorie::defaultCategory() ->setAlbums(Class_Album::findAllBy(['cat_id' => 0])); - $jsons = []; + $albums = []; foreach ($categories as $category) { - $jsons[] = $category->toJson(); + $albums[] = $category->toArray(); } $bib = Class_Bib::getPortail(); - $jsons = '{'. - '"id":'.$bib->getId().','. - '"label": "'.htmlspecialchars($bib->getLibelle()).'",'. - '"categories": ['.implode(",", $jsons).'],'. - '"items": []'. - '}'; - - $this->getResponse()->setHeader('Content-Type', 'application/json; charset=utf-8'); - $this->getResponse()->setBody('[' . $jsons .']'); + $this->_helper->json([['id' => $bib->getId(), + 'label' => htmlspecialchars($bib->getLibelle()), + 'categories' => $albums, + 'items' => []]]); } } \ No newline at end of file diff --git a/library/Class/AlbumCategorie.php b/library/Class/AlbumCategorie.php index 149abd0887a..ac9554c0c20 100644 --- a/library/Class/AlbumCategorie.php +++ b/library/Class/AlbumCategorie.php @@ -244,24 +244,22 @@ class Class_AlbumCategorie extends Storm_Model_Abstract { } - public function albumsToJSON($albums) { + public function albumsToArray($albums) { - $json_albums = []; + $albums_array = []; foreach ($albums as $album) { - $json_albums []= $album->toJSON(); + $albums_array []= $album->toArray(); } - return $json_albums; + return $albums_array; } - public function toJSON() { + public function toArray() { return - '{'. - '"id":'.$this->getId().','. - '"label": "'.htmlspecialchars($this->getLibelle()).'",'. - '"categories": ['.implode(",", $this->albumsToJSON($this->getSousCategories())).'],'. - '"items": []'. - '}'; + ['id' => $this->getId(), + 'label' => htmlspecialchars($this->getLibelle()), + 'categories' => $this->albumsToArray($this->getSousCategories()), + 'items' => []]; } } \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Accueil/BibNumerique.php b/library/ZendAfi/View/Helper/Accueil/BibNumerique.php index 8815a422e5f..7738897583c 100644 --- a/library/ZendAfi/View/Helper/Accueil/BibNumerique.php +++ b/library/ZendAfi/View/Helper/Accueil/BibNumerique.php @@ -172,17 +172,13 @@ class BibNumDisplayStrategy { class BibNumAlbumTeaserStrategy extends BibNumDisplayStrategy { public function getContent() { - $contenu = $this->displayNumericRessources(); - - if ($contenu) + if ($contenu = $this->displayNumericRessources()) return $contenu; if ($this->accueil_bibnum->isDisplayDiaporama() or $this->accueil_bibnum->isDisplayListe()) - $contenu .= $this->accueil_bibnum->getSlideshow()->renderAlbumMedias(); - else - $contenu .= sprintf('<div id="booklet_%d" class="bib-num-album"></div>', $this->id_module); + return $contenu . $this->accueil_bibnum->getSlideshow()->renderAlbumMedias(); - return $contenu; + return $contenu . sprintf('<div id="booklet_%d" class="bib-num-album"></div>', $this->id_module); } public function getTitle() { @@ -286,7 +282,6 @@ class BibNumPaginatedStrategy extends BibNumDisplayStrategy { 'id_module' => $this->id_module, 'id_division' => $this->division]; - xdebug_break(); if (Class_Systeme_ModulesAccueil_BibliothequeNumerique::ORDER_RANDOM == $this->preferences['display_order']) return $this->view->tagAnchor($reload_link, '', diff --git a/tests/application/modules/admin/controllers/BibnumControllerTest.php b/tests/application/modules/admin/controllers/BibnumControllerTest.php index 3580e83c780..143f7396044 100644 --- a/tests/application/modules/admin/controllers/BibnumControllerTest.php +++ b/tests/application/modules/admin/controllers/BibnumControllerTest.php @@ -88,9 +88,34 @@ class Admin_BibnumControllerTreeSelectTest extends Admin_AbstractControllerTestC /** @test */ public function jsonShouldContainsNatureAndFaune() { - $expected = '[{"id":0,"label": "Portail","categories": [{"id":6,"label": "arbre","categories": [],"items": []},{"id":2,"label": "nature","categories": [{"id":4,"label": "faune","categories": [{"id":6,"label": "arbre","categories": [],"items": []}],"items": []}],"items": []},{"id":0,"label": "Albums non classés","categories": [],"items": []}],"items": []}]'; - - $this->assertEquals($expected, $this->_response->getBody()); + $expected = [['id' => 0, + 'label' => 'Portail', + 'categories' => [ + ['id' => 6, + 'label' => 'arbre', + 'categories' => [], + 'items' => []], + + ['id' => 2, + 'label' => 'nature', + 'categories' => [ + ['id' => 4, + 'label' => 'faune', + 'categories' => [ + ['id' => 6, + 'label' => 'arbre', + 'categories' => [], + 'items' => []]], + 'items' => []]], + 'items' => []], + + ['id' => 0, + 'label' => 'Albums non classés', + 'categories' => [], + 'items' => []]], + 'items' => []]]; + + $this->assertEquals(json_encode($expected), $this->_response->getBody()); } } \ No newline at end of file -- GitLab