diff --git a/application/modules/opac/controllers/NoticeajaxController.php b/application/modules/opac/controllers/NoticeajaxController.php index b87cf12a087ba8128e9beee8e9a7c81ad9e0511f..dc385b6b4d1112d5b1823c15eb4d199cb094ef41 100644 --- a/application/modules/opac/controllers/NoticeajaxController.php +++ b/application/modules/opac/controllers/NoticeajaxController.php @@ -297,11 +297,17 @@ class NoticeAjaxController extends Zend_Controller_Action { public function resnumeriquesAction() { - $html = sprintf('<p>%s</p>', $this->view->_('Aucune ressource correspondante')); - if (null !== $exemplaire = Class_Exemplaire::getLoader()->findFirstBy(array('id_notice' => $this->id_notice))) { - $html = $this->view->renderAlbum($exemplaire->getAlbum()); - } - $this->_sendResponse($html.Class_ScriptLoader::getInstance()->html()); + $html = ''; + if (null !== $exemplaire = Class_Exemplaire::findFirstBy(['id_notice' => $this->id_notice])) + $html .= $this->view->renderAlbum($exemplaire->getAlbum()); + + foreach(Class_FRBR_Link::findAllAlbumsFromNotice($this->notice) as $link) + $html .= $this->view->renderAlbum($link->getTargetEntity()); + + if ('' == $html) + $html = sprintf('<p>%s</p>', $this->view->_('Aucune ressource correspondante')); + + $this->_sendResponse($html . Class_ScriptLoader::getInstance()->html()); } diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php index 68e104fcfe3248f8f64fa3d462b18b02880b0ad0..1813afe6fe4b411c5f8ac2e9c11d4e014922b799 100644 --- a/cosmogramme/php/_init.php +++ b/cosmogramme/php/_init.php @@ -1,7 +1,7 @@ <?php // Constantes error_reporting(E_ERROR | E_PARSE); -define("PATCH_LEVEL","228"); +define("PATCH_LEVEL","229"); define("APPLI","cosmogramme"); define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs"); diff --git a/cosmogramme/sql/patch/patch_229.php b/cosmogramme/sql/patch/patch_229.php new file mode 100644 index 0000000000000000000000000000000000000000..3658a468f77bb8491cb159354bf4d2bdadb8c97d --- /dev/null +++ b/cosmogramme/sql/patch/patch_229.php @@ -0,0 +1,9 @@ +<?php + +$adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); +$adapter->query('ALTER TABLE frbr_link ADD source_key VARCHAR(255) null default null'); +$adapter->query('ALTER TABLE frbr_link ADD KEY source_key (source_key)'); +$adapter->query('ALTER TABLE frbr_link ADD target_key VARCHAR(255) null default null'); +$adapter->query('ALTER TABLE frbr_link ADD KEY target_key (target_key)'); +$adapter->query('ALTER TABLE frbr_link ADD KEY source_type (source_type)'); +$adapter->query('ALTER TABLE frbr_link ADD KEY target_type (target_type)'); \ No newline at end of file diff --git a/library/Class/FRBR/Link.php b/library/Class/FRBR/Link.php index 815068198d517c208d6af07c8bec6a868be2d8a8..871e50aa30d1cc4cb7f869ddc562f37cbb0e80e3 100644 --- a/library/Class/FRBR/Link.php +++ b/library/Class/FRBR/Link.php @@ -43,8 +43,15 @@ class FRBR_LinkLoader extends Storm_Model_Loader { * @param $value string */ public function getLinksFor($name, $value) { - return $this->findAllBy(['where' => $name . ' like \'%' . $value . '%\'', - 'order' => 'type_id']); + return Class_FRBR_Link::findAllBy([$name .'_key' => $value, + 'order' => 'type_id']); + } + + + public function findAllAlbumsFromNotice($notice) { + return Class_FRBR_Link::findAllBy(['source_type' => Class_FRBR_Link::TYPE_NOTICE, + 'target_type' => Class_FRBR_Link::TYPE_ALBUM, + 'source_key' => $notice->getClefAlpha()]); } @@ -55,7 +62,7 @@ class FRBR_LinkLoader extends Storm_Model_Loader { public function findFirstForAlbum($album) { return Class_FRBR_Link::findFirstBy(['source_type' => Class_FRBR_Link::TYPE_NOTICE, 'target_type' => Class_FRBR_Link::TYPE_ALBUM, - 'target' => Class_Url::absolute($album->getPermalink())]); + 'target_key' => $album->getId()]); } } @@ -117,44 +124,51 @@ class Class_FRBR_Link extends Storm_Model_Abstract { if ('opac' == $request->getModuleName() && 'recherche' == $request->getControllerName() && 'viewnotice' == $request->getActionName()) { - $callback(self::TYPE_NOTICE); + $callback(self::TYPE_NOTICE, $request->getParam('clef')); + ; return; } if ('opac' == $request->getModuleName() && 'bib-numerique' == $request->getControllerName() && 'notice' == $request->getActionName()) { - $callback(self::TYPE_ALBUM); + $callback(self::TYPE_ALBUM, $request->getParam('id')); return; } - $callback(self::TYPE_EXTERNAL); + $callback(self::TYPE_EXTERNAL, null); } protected function _detectSourceType() { $this->_detectEntityTypeFromUrl( - $this->getSource(), - function ($type) {$this->setSourceType($type);}); + $this->getSource(), + function ($type, $key) { + $this->setSourceType($type) + ->setSourceKey($key); + }); } protected function _detectTargetType() { $this->_detectEntityTypeFromUrl( - $this->getTarget(), - function ($type) {$this->setTargetType($type);}); + $this->getTarget(), + function ($type, $key) { + $this->setTargetType($type) + ->setTargetKey($key); + }); } - /** @return Class_Notice */ - public function getTargetNotice() { + /** @return Storm_Model_Abstract */ + public function getTargetEntity() { return $this->getEntityFor('target'); } - /** @return Class_Notice */ - public function getSourceNotice() { + /** @return Storm_Model_Abstract */ + public function getSourceEntity() { return $this->getEntityFor('source'); } @@ -164,15 +178,19 @@ class Class_FRBR_Link extends Storm_Model_Abstract { * @return Class_Notice */ public function getEntityFor($type) { - if (self::TYPE_EXTERNAL == $this->{'get'. ucfirst($type) . 'Type'}()) + $entity_type = $this->{'get'. ucfirst($type) . 'Type'}(); + if (self::TYPE_EXTERNAL == $entity_type) return; $attribute = '_' . $type .'_entity'; if ($this->$attribute) return $this->$attribute; - $this->$attribute = Class_Notice::findByUrl($this->{'get' . ucfirst($type)}()); - return $this->$attribute; + if (self::TYPE_NOTICE == $entity_type) + return $this->$attribute = Class_Notice::getNoticeByClefAlpha($this->{'get' . ucfirst($type) . 'Key'}()); + + if (self::TYPE_ALBUM == $entity_type) + return $this->$attribute = Class_Album::find($this->{'get' . ucfirst($type) . 'Key'}()); } diff --git a/library/Class/TypeDoc.php b/library/Class/TypeDoc.php index 416faddc9ce1f1bfdb9e0864a1568889e6103662..1554de7c5fe69ddc02459fcb16795e907350fed2 100644 --- a/library/Class/TypeDoc.php +++ b/library/Class/TypeDoc.php @@ -16,12 +16,12 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class TypeDocLoader extends Storm_Model_Loader { protected $_all_instances; - + public function __construct() { $this->findAll(); } @@ -37,7 +37,7 @@ class TypeDocLoader extends Storm_Model_Loader { if (!empty($attributes)) $instance->updateAttributes($attributes); - + return $instance; } @@ -72,14 +72,15 @@ class TypeDocLoader extends Storm_Model_Loader { public function findAll($select = NULL) { if (isset($this->_all_instances)) return $this->_all_instances; - - $types_docs = Class_CosmoVar::getLoader()->find('types_docs'); - $lines = explode("\r\n", $types_docs->getListe()); - $instances = array(); - - foreach ($lines as $line) { - $instance = $this->unserialize($line); - $instances [$instance->getId()]= $instance; + + if ($types_docs = Class_CosmoVar::find('types_docs')) { + $lines = explode("\r\n", $types_docs->getListe()); + $instances = array(); + + foreach ($lines as $line) { + $instance = $this->unserialize($line); + $instances [$instance->getId()]= $instance; + } } $default_types = Class_TypeDoc::getDefaultTypeDocs(); @@ -87,7 +88,7 @@ class TypeDocLoader extends Storm_Model_Loader { if (!isset($instances[$id])) $instances[$id] = Class_TypeDoc::newWithLabel($label)->setId($id); } - + return $this->_all_instances = $instances; } @@ -128,7 +129,7 @@ class TypeDocLoader extends Storm_Model_Loader { return $this->_saveSerialized($serialized); } - + public function delete($model) { $serialized = array(); @@ -176,7 +177,7 @@ class Class_TypeDoc extends Storm_Model_Abstract { const CODE_FACETTE = 'T'; protected $_loader_class = 'TypeDocLoader'; - protected $_belongs_to = ['codif_type_doc' => + protected $_belongs_to = ['codif_type_doc' => [ 'model' => 'Class_CodifTypeDoc', 'referenced_in' => 'id' ]]; const LIVRE = 1; @@ -200,7 +201,7 @@ class Class_TypeDoc extends Storm_Model_Abstract { const NUMERIQUEPREMIUM = 110; const CYBERLIBRIS = 111; - + public static function getDefaultTypeDocs() { return [self::LIVRE => 'Livres', self::PERIODIQUE => 'Périodiques', @@ -228,7 +229,7 @@ class Class_TypeDoc extends Storm_Model_Abstract { /** * @param String label * @return Class_Type_Doc - */ + */ public static function newWithLabel($label) { $instance = new self(); return $instance->setLabel($label); @@ -279,7 +280,7 @@ class Class_TypeDoc extends Storm_Model_Abstract { } public function isRessourceNumerique() { - return ($this->getId() >= Class_TypeDoc::LIVRE_NUM) + return ($this->getId() >= Class_TypeDoc::LIVRE_NUM) && (!in_array($this->getId(),[static::ARTICLE, static::RSS, static::SITE])); } @@ -295,7 +296,7 @@ class Class_TypeDoc extends Storm_Model_Abstract { return $codif; } - + public function getLibelleFamille() { return $this->getCodifTypeDoc()->getLibelle(); } diff --git a/library/ZendAfi/View/Helper/Frbr.php b/library/ZendAfi/View/Helper/Frbr.php index 1f9ea47ef5adaea1eccc45c04244e9c12c28d99e..716977d3b49722ff2ce60278770e8a28ad8b7610 100644 --- a/library/ZendAfi/View/Helper/Frbr.php +++ b/library/ZendAfi/View/Helper/Frbr.php @@ -11,133 +11,138 @@ * * BOKEH is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_View_Helper_Frbr extends Zend_View_Helper_HtmlElement{ - protected $linksRenderer; - const NO_RESULT_MESSAGE = 'Aucun lien n\'a été trouvé'; - /** - * Retourne les notices liées - * - * @param $model Class_Notice - * @return string - */ - public function frbr($model) { - $this->linksRenderer = $this->getLinksRenderer(); - $sourceLinks = $model->getLinksAsSource(); - $targetLinks = $model->getLinksAsTarget(); - - if (0 == count($sourceLinks) and 0 == count($targetLinks)){ - $noResultMessage = $this->linksRenderer->returnNoResultMessage(); - return $noresultmessage; - } - - - $html = ''; - foreach ($this->_getLinksBySourceTypes($sourceLinks) as $label => $links) - $html .= $this->_getTargetTypeLinks($label, $links); - - foreach ($this->_getLinksByTargetTypes($targetLinks) as $label => $links) - $html .= $this->_getSourceTypeLinks($label, $links); - - if ('' == $html){ - $noResultMessage = $this->linksRenderer->returnNoResultMessage(); - return $noResultMessage; - } - - return $html;} - - - - protected function _getLinksBySourceTypes($links) { - return $this->_getLinksByType($links, function ($link) { - return $link->getTypeLabelFromSource(); - }); - } - - - protected function _getLinksByTargetTypes($links) { - return $this->_getLinksByType($links, function ($link) { - return $link->getTypeLabelFromTarget(); - }); - } - - - protected function _getLinksByType($links, $callback) { - $byTypes = []; - foreach ($links as $link) { - $typeLabel = $callback($link); - if (!array_key_exists($typeLabel, $byTypes)) - $byTypes[$typeLabel] = []; - - $byTypes[$typeLabel][] = $link; - } - return $byTypes; - } - - - protected function _getTargetTypeLinks($label, $links) { - return $this->_getTypeLinks($label, $links, function($link) { - return $link->getTargetNotice(); - }); - } - - - protected function _getSourceTypeLinks($label, $links) { - return $this->_getTypeLinks($label, $links, function($link) { - return $link->getSourceNotice(); - }); - } - - - protected function _getTypeLinks($label, $links, $callback) { - $html = ''; - if (!$links) - return $html; - - $html .= $this->linksRenderer->renderType($label); - $notices = []; - foreach ($links as $link) { - if ($model = $callback($link)) - $notices[] = $model; - } - - if (empty($notices)) - return ''; - - $html .= $this->linksRenderer->render($notices, $this->view); - - return $html; - } - - - public function getLinksRenderer(){ - return new FrbrNoticesOpacRenderer(); - } + protected $linksRenderer; + const NO_RESULT_MESSAGE = 'Aucun lien n\'a été trouvé'; + /** + * Retourne les notices liées + * + * @param $model Class_Notice + * @return string + */ + public function frbr($model) { + $this->linksRenderer = $this->getLinksRenderer(); + $sourceLinks = $model->getLinksAsSource(); + $targetLinks = $model->getLinksAsTarget(); + + if (0 == count($sourceLinks) and 0 == count($targetLinks)){ + $noResultMessage = $this->linksRenderer->returnNoResultMessage(); + return $noresultmessage; + } + + + $html = ''; + foreach ($this->_getLinksBySourceTypes($sourceLinks) as $label => $links) + $html .= $this->_getTargetTypeLinks($label, $links); + + foreach ($this->_getLinksByTargetTypes($targetLinks) as $label => $links) + $html .= $this->_getSourceTypeLinks($label, $links); + + if ('' == $html){ + $noResultMessage = $this->linksRenderer->returnNoResultMessage(); + return $noResultMessage; + } + + return $html; + } + + + + protected function _getLinksBySourceTypes($links) { + return $this->_getLinksByType($links, function ($link) { + return $link->getTypeLabelFromSource(); + }); + } + + + protected function _getLinksByTargetTypes($links) { + return $this->_getLinksByType($links, function ($link) { + return $link->getTypeLabelFromTarget(); + }); + } + + + protected function _getLinksByType($links, $callback) { + $byTypes = []; + foreach ($links as $link) { + $typeLabel = $callback($link); + if (!array_key_exists($typeLabel, $byTypes)) + $byTypes[$typeLabel] = []; + + $byTypes[$typeLabel][] = $link; + } + return $byTypes; + } + + + protected function _getTargetTypeLinks($label, $links) { + return $this->_getTypeLinks( + $label, $links, + function($link) { + return $link->getTargetEntity(); + }); + } + + + protected function _getSourceTypeLinks($label, $links) { + return $this->_getTypeLinks( + $label, $links, + function($link) { + return $link->getSourceEntity(); + }); + } + + + protected function _getTypeLinks($label, $links, $callback) { + $html = ''; + if (!$links) + return $html; + + $html .= $this->linksRenderer->renderType($label); + $notices = []; + foreach ($links as $link) { + if ($model = $callback($link)) + $notices[] = $model; + } + + if (empty($notices)) + return ''; + + $html .= $this->linksRenderer->render($notices, $this->view); + + return $html; + } + + + public function getLinksRenderer(){ + return new FrbrNoticesOpacRenderer(); + } } class FrbrNoticesOpacRenderer { - public function render($notices, $view){ + public function render($notices, $view){ $noticeHtml = new Class_NoticeHtml(); return $noticeHtml->getListeNotices($notices, $view); - } + } + + public function renderType($type) { + return '<div class="notice_info_titre">' . $type . '</div>'; + } - public function renderType($type) { - return '<div class="notice_info_titre">' . $type . '</div>'; - } - - public function returnNoResultMessage() { - return 'Aucun lien n\'a été trouvé'; - } -} + public function returnNoResultMessage() { + return 'Aucun lien n\'a été trouvé'; + } +} ?> diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php index 18de3486c7a4cde599d619365436c8e9df43557a..d8202b717039a20b80e8c46eb0f4daf41fdfa2b6 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php @@ -261,7 +261,6 @@ class NoticeAjaxControllerNoticeSimilairesSouleymaneTest extends NoticeAjaxContr class NoticeAjaxControllerResNumeriquesTest extends AbstractControllerTestCase { - public function setup() { parent::setup(); $this->fixture('Class_Notice', ['id' => 123]); @@ -273,7 +272,6 @@ class NoticeAjaxControllerResNumeriquesTest extends AbstractControllerTestCase { /** @test */ function bookletShouldBeLoadedWithAlbumTypeLivreNumerique() { - $this->fixture('Class_Notice', ['id' => 123]); $album = $this->fixture('Class_Album', ['id' => 8, 'type_doc_id' => Class_TypeDoc::LIVRE_NUM]); @@ -307,6 +305,38 @@ class NoticeAjaxControllerResNumeriquesTest extends AbstractControllerTestCase { } + +class NoticeAjaxControllerResNumeriquesFromFrbrLinkTest extends AbstractControllerTestCase { + public function setup() { + parent::setup(); + $this->fixture('Class_Notice', ['id' => 123, 'clef_alpha' => 'ACESHIGH--IRONM---1984-1']); + $album = $this->fixture('Class_Album', + ['id' => 42, + 'titre' => 'Aces High', + 'type_doc_id' => Class_TypeDoc::AUDIO_RECORD]); + + $this->fixture('Class_FRBR_LinkType', + ['id' => 1, + 'libelle' => 'CD MP3', + 'from_source' => 'A pour pistes MP3', + 'from_target' => 'Pistes MP3 de']); + $this->fixture('Class_FRBR_Link', + ['id' => 1, + 'type_id' => 1, + 'source' => ROOT_URL . BASE_URL . '/recherche/viewnotice/clef/ACESHIGH--IRONM---1984-1', + 'target' => ROOT_URL . BASE_URL . '/bib-numerique/notice/id/42']); + + $this->dispatch('noticeajax/resnumeriques?id_notice=123', true); + } + + + /** @test */ + public function audioPlayerShouldBeLoaded() { + $this->assertXPathContentContains('//script', 'audiojs.createAll'); + } +} + + class NoticeAjaxControllerBandeAnnonceTest extends AbstractControllerTestCase { /** @test */ @@ -716,60 +746,59 @@ abstract class NoticeAjaxControllerFrbrWithLinksTestCase extends AbstractControl public function setUp() { parent::setUp(); + Storm_Model_Loader::defaultToVolatile(); $leCombat = 'LECOMBATDESJUGES--BILLYY--ZARAFAFILMSDISTRIB-2006-4'; $this->_lesGrandsTextes = 'LESGRANDSTEXTESDEDROITINTERNATIONALPUBLIC--DUPUYP--DALLOZ-2010-1'; $this->_moiCEstQuoi = 'MOICESTQUOI--BRENIFIERO--NATHANJEUNESSE-2004-1'; - $type = Class_FRBR_LinkType::newInstanceWithId(1) - ->setLibelle('Suite') - ->setFromSource('a pour suite') - ->setFromTarget('est une suite de'); - - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_FRBR_Link') - ->whenCalled('getLinksForSource') - ->with($leCombat) - ->answers([Class_FRBR_Link::newInstanceWithId(1) - ->setType($type) - ->setSource($this->_getUrlForKey($leCombat)) - ->setSourceType(Class_FRBR_Link::TYPE_NOTICE) - ->setTarget($this->_getUrlForKey($this->_lesGrandsTextes)) - ->setTargetType(Class_FRBR_Link::TYPE_NOTICE)]) - - ->whenCalled('getLinksForTarget') - ->with($leCombat) - ->answers([Class_FRBR_Link::newInstanceWithId(2) - ->setType($type) - ->setSource($this->_getUrlForKey($this->_moiCEstQuoi)) - ->setSourceType(Class_FRBR_Link::TYPE_NOTICE) - ->setTarget($this->_getUrlForKey($leCombat)) - ->setTargetType(Class_FRBR_Link::TYPE_NOTICE)]); + $type = $this->fixture('Class_FRBR_LinkType', + ['id' => 1, + 'libelle' => 'Suite', + 'from_source' => 'a pour suite', + 'from_target' => 'est une suite de']); - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') - ->whenCalled('getNoticeByClefAlpha') - ->with($this->_lesGrandsTextes) - ->answers(Class_Notice::newInstanceWithId(888) - ->setTitrePrincipal('Les grands textes de droit') - ->setClefAlpha($this->_lesGrandsTextes) - ->setUrlVignette('NO') - ->setUrlImage('NO') - ->setTypeDoc(2)) - - ->whenCalled('getNoticeByClefAlpha') - ->with($this->_moiCEstQuoi) - ->answers(Class_Notice::newInstanceWithId(999) - ->setTypeDoc(2) - ->setTitrePrincipal('Moi, c\'est quoi ?') - ->setClefAlpha($this->_moiCEstQuoi) - ->setUrlVignette('moi_c_est_quoi.jpg') - ->setUrlImage('moi_c_est_quoi.jpg')) + $this->fixture('Class_FRBR_Link', + ['id' => 1, + 'type' => $type, + 'source' => $this->_getUrlForKey($leCombat), + 'target' => $this->_getUrlForKey($this->_lesGrandsTextes)]); - ->whenCalled('find') - ->with(777) - ->answers(Class_Notice::newInstanceWithId(777, ['clef_alpha' => $leCombat, - 'url_vignette' => '', - 'url_image' => ''])); + $this->fixture('Class_FRBR_Link', + ['id' => 2, + 'type' => $type, + 'source' => $this->_getUrlForKey($this->_moiCEstQuoi), + 'target' => $this->_getUrlForKey($leCombat)]); + + $this->fixture('Class_Notice', + ['id' => 888, + 'titre_principal' => 'Les grands textes de droit', + 'clef_alpha' => $this->_lesGrandsTextes, + 'url_vignette' => 'NO', + 'url_image' => 'NO', + 'type_doc' => 2]); + + $this->fixture('Class_Notice', + ['id' => 999, + 'titre_principal' => 'Moi, c\'est quoi ?', + 'clef_alpha' => $this->_moiCEstQuoi, + 'url_vignette' => 'moi_c_est_quoi.jpg', + 'url_image' => 'moi_c_est_quoi.jpg', + 'type_doc' => 2]); + + $this->fixture('Class_Notice', + ['id' => 777, + 'clef_alpha' => $leCombat, + 'url_vignette' => '', + 'url_image' => '']); + + } + + + public function tearDown() { + Storm_Model_Loader::defaultToDb(); + parent::tearDown(); }