diff --git a/application/modules/telephone/controllers/RechercheController.php b/application/modules/telephone/controllers/RechercheController.php index 2e704adb9a84ac4e370209af09a9eaa5dd1e3e25..8936faeb5a04dee47220ebe43a9ea67793f53119 100644 --- a/application/modules/telephone/controllers/RechercheController.php +++ b/application/modules/telephone/controllers/RechercheController.php @@ -40,13 +40,15 @@ class Telephone_RechercheController extends RechercheController { $this->_('Notices liées') => ['action' => 'frbr'] ]; - if ($notice->isLivreNumerique()) + if ($notice->isLivreNumerique()) { $actions[$this->_('Feuilleter le livre')] = ['action' => 'ressourcesnumeriques', - 'attribs' => ['data-ajax' => 'false']]; + 'attribs' => ['data-ajax' => 'false']]; + } - if ($notice->isArteVOD()) + if ($notice->isArteVOD()) { $actions[$this->_('Bande-annonce')] = ['action' => 'ressourcesnumeriques', - 'attribs' => ['data-ajax' => 'false']]; + 'attribs' => ['data-ajax' => 'false']]; + } $this->view->notice = $notice; $this->view->actions = $actions; diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index 11547d797fca27e79e7d8cf6b062afc44a5335a1..9a38336dc38e8cfc4d6375dfabc057953f3e652d 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -187,6 +187,7 @@ class CatalogueLoader extends Storm_Model_Loader { return implode(' and ', $clauses); } + public function allByIdLabel() { $catalogues = Class_Catalogue::findAllBy(['order' => 'libelle']); $allids=[]; @@ -196,15 +197,26 @@ class CatalogueLoader extends Storm_Model_Loader { return $allids; } + public function findTopCatalogues() { return Class_Catalogue::findAllBy(['where' => 'parent_id is null', 'order' => 'libelle']); } + + public function findByPath($path) { + $parts = array_filter(explode(Class_Catalogue::PATH_SEPARATOR, $path)); + if (!$root = Class_Catalogue::findFirstBy(['parent_id' => null, + 'libelle' => array_shift($parts)])) + return null; + return $root->sousDomaineByPath(implode(Class_Catalogue::PATH_SEPARATOR, $parts)); + } } class Class_Catalogue extends Storm_Model_Abstract { + const PATH_SEPARATOR = '/'; + protected $_table_name = 'catalogue', $_table_primary = 'ID_CATALOGUE', @@ -249,15 +261,30 @@ class Class_Catalogue extends Storm_Model_Abstract { $_until; - public static function getLoader() { - return self::getLoaderFor(__CLASS__); - } - public static function newCatalogueForAll() { return new AllNoticesCatalogue(); } + public function sousDomaineByPath($path) { + if (!$parts = array_filter(explode(static::PATH_SEPARATOR, $path))) + return $this; + + if ($child = static::getLoader()->findFirstBy(['parent_id' => $this->getId(), + 'libelle' => array_shift($parts)])) + return $child->sousDomaineByPath(implode(static::PATH_SEPARATOR, $parts)); + + return null; + } + + + public function getPath() { + return (($parent = $this->getDomaineParent()) + ? $parent->getPath() + : '').static::PATH_SEPARATOR.$this->getLibelle(); + } + + public function acceptVisitor($visitor) { $visitor->visitOaiSpec($this->getOaiSpec()); $visitor->visitLibelle($this->getLibelle()); diff --git a/tests/application/modules/admin/controllers/SitothequeControllerTest.php b/tests/application/modules/admin/controllers/SitothequeControllerTest.php index d3d5efa663bde9bb8fe0188fc66e53ac87153680..2c34665b6963dbccc0814d6ca7e27b47af2d2fad 100644 --- a/tests/application/modules/admin/controllers/SitothequeControllerTest.php +++ b/tests/application/modules/admin/controllers/SitothequeControllerTest.php @@ -204,7 +204,6 @@ class SitothequeControllerAddActionTest extends SitothequeControllerTestCase { public function titreShouldBeAjouterUnSite() { $this->assertXPathContentContains('//h1', 'Ajouter un site'); } - } @@ -218,7 +217,7 @@ class SitothequeControllerPostAddActionTest extends SitothequeControllerTestCase $this->postDispatch('/admin/sito/sitoadd/id_cat/2', ['titre' => 'google', 'url' => 'http://www.google.fr', - 'id_items' => '23-23'], + 'id_items' => '23-23'], true); } diff --git a/tests/library/Class/CatalogueTest.php b/tests/library/Class/CatalogueTest.php index 760d09a75670d6fe788a13e8f67f1fc0ea93070b..a9878429663a3fcdb6865e729b18fb0a20a1eddc 100644 --- a/tests/library/Class/CatalogueTest.php +++ b/tests/library/Class/CatalogueTest.php @@ -132,6 +132,8 @@ class CatalogueTestGetSelectionFacette extends ModelTestCase { } + + class CatalogueTestGetPagedNotices extends ModelTestCase { protected $_catalogue; protected $_noticeWrapper; @@ -515,20 +517,32 @@ class CatalogueTestGetNoticesByPreferences extends ModelTestCase { class CatalogueParentTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); - $this->_histoire = Class_Catalogue::newInstanceWithId(100, [ 'libelle' => 'Histoire']); + $this->_histoire = Class_Catalogue::newInstanceWithId(100, [ 'libelle' => 'Histoire', + 'parent_id' => 0]); $this->_politique = Class_Catalogue::newInstanceWithId(200, [ 'libelle' => 'Politique', 'parent_id' => 100]); $this->_moyenage = Class_Catalogue::newInstanceWithId(300, [ 'libelle'=>'Moyen-age', 'parent_id' => 100]); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') - ->whenCalled('findAllBy') - ->with(['role' => 'domaine_parent', - 'model' => $this->_histoire, - 'order' => 'libelle' - ]) - ->answers([ $this->_politique, $this->_moyenage]); + ->whenCalled('findAllBy') + ->with(['role' => 'domaine_parent', + 'model' => $this->_histoire, + 'order' => 'libelle' + ]) + ->answers([ $this->_politique, $this->_moyenage]) - + ->whenCalled('findFirstBy') + ->answers(null) + + ->whenCalled('findFirstBy') + ->with(['parent_id' => null, + 'libelle' => 'Histoire']) + ->answers($this->_histoire) + + ->whenCalled('findFirstBy') + ->with(['parent_id' => 100, + 'libelle' => 'Politique']) + ->answers($this->_politique); } @@ -549,6 +563,38 @@ class CatalogueParentTest extends Storm_Test_ModelTestCase { $this->_politique->setParentId($this->_politique->getId()); $this->assertNull($this->_politique->getParentId()); } + + + /** @test */ + public function findByPathHistoireShouldAnswerCatalogueHistoire() { + $this->assertEquals($this->_histoire, + Class_Catalogue::findByPath('/Histoire')); + } + + + /** @test */ + public function findByPathHistoireSlashPolitiqueShouldAnswerCataloguePolitique() { + $this->assertEquals($this->_politique, + Class_Catalogue::findByPath('/Histoire/Politique')); + } + + + /** @test */ + public function findByPathHistoireSlashZorkShouldAnswerNull() { + $this->assertNull(Class_Catalogue::findByPath('/Histoire/Zork')); + } + + + /** @test */ + public function findByPathZorkShouldAnswerNull() { + $this->assertNull(Class_Catalogue::findByPath('/Zork')); + } + + + /** @test */ + public function cataloguePolitiquePathShouldBeSlashHistoireSlashPolitique() { + $this->assertEquals('/Histoire/Politique', $this->_politique->getPath()); + } } diff --git a/tests/library/Class/SitothequeTest.php b/tests/library/Class/SitothequeTest.php index ac2626c341f4d9aff040323e8ea65c3c970cb268..c43d276502ec8de511b581488d581090c8d44674 100644 --- a/tests/library/Class/SitothequeTest.php +++ b/tests/library/Class/SitothequeTest.php @@ -18,7 +18,7 @@ * along with AFI-OPAC 2.0; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class SitothequeTest extends Storm_Test_ModelTestCase { +class SitothequeSitesFromIdsAndCategoriesTest extends Storm_Test_ModelTestCase { /** @test */ function getSitesFromIdAndCategoriesShouldReturnFeeds() { $site_premiere = Class_Sitotheque::getLoader()->newInstanceWithId(26); @@ -35,6 +35,7 @@ class SitothequeTest extends Storm_Test_ModelTestCase { $this->assertEquals(array($site_premiere, $site_allocine, $site_telerama), $sites); } - } + + ?> \ No newline at end of file