diff --git a/application/modules/admin/controllers/BibnumController.php b/application/modules/admin/controllers/BibnumController.php index 5f2f5363b29ae2af72ba7aff6c5e4662ff107ba3..90821b401bc64c8f3d808660df34babadb4d05cb 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 149abd0887a772c12830e36ee08c064d70e61533..ac9554c0c208e21b77bfac15dda31fca8120ace4 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 8815a422e5f59b3bbeb08ae4f8b0298eeb6faf8c..7738897583cf5fdb3607875c799de4fda209b7d9 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 3580e83c780a147d3c578394bbeaeb96fe908da2..143f7396044804a111545b99518b1fe599b8d538 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