diff --git a/application/modules/admin/views/scripts/frbr-link/index.phtml b/application/modules/admin/views/scripts/frbr-link/index.phtml index 599f031070ffbb767e30cf8a3ac84b116cb7b988..18710e3a146d3671640f396fa9324cda63eba918 100644 --- a/application/modules/admin/views/scripts/frbr-link/index.phtml +++ b/application/modules/admin/views/scripts/frbr-link/index.phtml @@ -13,10 +13,16 @@ echo $this->bouton('id=add_link', 'largeur=250px;' ); -$truncate = function ($value) { - if (40 < mb_strlen($value)) - $value = mb_substr($value, 0, 40) . '...'; - return $value; +$label = function ($model, $attrib) { + if ($notice = $model->{'get'. ucfirst($attrib) . 'Notice'}()) { + return '<a href="' . $model->{'get' . ucfirst($attrib)}() . '" onclick="window.open(this.href);return false;">' . $notice->getTitrePrincipal() . '</a>' + . '<br>' . $notice->getAuteurPrincipal(); + } + + $value = $model->callGetterByAttributeName($attrib); + if (40 < mb_strlen($value)) + $value = mb_substr($value, 0, 40) . '...'; + return $value; }; echo $this->tagModelTable($this->relations, @@ -32,9 +38,9 @@ echo $this->tagModelTable($this->relations, null, - ['source' => $truncate, - 'target' => $truncate, - 'link_complete_label' => function($value) { - return '<pre>' . $value . '</pre>'; + ['source' => $label, + 'target' => $label, + 'link_complete_label' => function($model, $attrib) { + return '<pre>' . $model->callGetterByAttributeName($attrib) . '</pre>'; },]); ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/TagModelTable.php b/library/ZendAfi/View/Helper/TagModelTable.php index b843b22ed1802b3a395c3605e1c216c094dcda35..8c5ec767e0254fbbed133d16111a615afcd7d557 100644 --- a/library/ZendAfi/View/Helper/TagModelTable.php +++ b/library/ZendAfi/View/Helper/TagModelTable.php @@ -94,11 +94,13 @@ class ZendAfi_View_Helper_TagModelTable extends Zend_View_Helper_HtmlElement { public function renderModelAsTableRow($model, $attribs, $actions, $callbacks) { $cols = ''; - $default_callback = function ($value) {return $this->view->escape($value);}; + $default_callback = function ($model, $attrib) { + return $this->view->escape($model->callGetterByAttributeName($attrib)); + }; foreach ($attribs as $attrib) { $callback = (array_key_exists($attrib, $callbacks)) ? $callbacks[$attrib] : $default_callback; - $cols .= '<td>' . $callback($model->callGetterByAttributeName($attrib)) . '</td>'; + $cols .= '<td>' . $callback($model, $attrib) . '</td>'; } $row = '<tr>'.$cols.'<td>'; diff --git a/tests/application/modules/admin/controllers/FrbrLinkControllerTest.php b/tests/application/modules/admin/controllers/FrbrLinkControllerTest.php index 01f7f6f3b0d9629883c66c56b2a5f664691d37eb..db05b1cf7192038b177325744c6b3a1b416f4885 100644 --- a/tests/application/modules/admin/controllers/FrbrLinkControllerTest.php +++ b/tests/application/modules/admin/controllers/FrbrLinkControllerTest.php @@ -7,7 +7,7 @@ * the Free Software Foundation. * * There are special exceptions to the terms and conditions of the AGPL as it - * is applied to this software (see README file). + * is applied to this software (see README f ile). * * AFI-OPAC 2.0 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -34,14 +34,31 @@ abstract class Admin_FrbrLinkControllerTestCase extends Admin_AbstractController ->answers([ Class_FRBR_Link::newInstanceWithId(2) ->setType($type) - ->setSource('LESGRANDSTEXTESDEDROITINTERNATIONALPUBLIC--DUPUYP--DALLOZ-2010-1') - ->setTarget('LESGRANDSTEXTESDEDROITINTERNATIONALPUBLIC--DUPUYP--DALLOZ-2010-2'), + ->setSource('http://localhost/afi-opac3-ce/recherche/viewnotice/clef/LESGRANDSTEXTESDEDROITINTERNATIONALPUBLIC--DUPUYP--DALLOZ-2010-1?id_profil=1&type_doc=4') + ->setSourceType(Class_FRBR_Link::TYPE_NOTICE) + ->setTarget('http://localhost/afi-opac3-ce/recherche/viewnotice/clef/LESGRANDSTEXTESDEDROITINTERNATIONALPUBLIC--DUPUYP--DALLOZ-2010-2?id_profil=1&type_doc=4') + ->setTargetType(Class_FRBR_Link::TYPE_NOTICE), Class_FRBR_Link::newInstanceWithId(3) ->setType($type) - ->setSource('AMNESTYINTERNATIONAL--GRANTR--GAMMA-2002-1') - ->setTarget('AMNESTYINTERNATIONAL--GRANTR--GAMMA-2002-2') + ->setSource('http://localhost/afi-opac3-ce/recherche/viewnotice/clef/AMNESTYINTERNATIONAL--GRANTR--GAMMA-2002-1?id_profil=1&type_doc=4') + ->setSourceType(Class_FRBR_Link::TYPE_NOTICE) + ->setTarget('http://localhost/afi-opac3-ce/recherche/viewnotice/clef/AMNESTYINTERNATIONAL--GRANTR--GAMMA-2002-2?id_profil=1&type_doc=4') + ->setTargetType(Class_FRBR_Link::TYPE_NOTICE) ]); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') + ->whenCalled('getNoticeByClefAlpha') + ->with('LESGRANDSTEXTESDEDROITINTERNATIONALPUBLIC--DUPUYP--DALLOZ-2010-1') + ->answers(Class_Notice::newInstanceWithId(33) + ->setTitrePrincipal('Les grands textes tome 1') + ->setAuteurPrincipal('Vidalio Nesti')) + + ->whenCalled('getNoticeByClefAlpha') + ->with('LESGRANDSTEXTESDEDROITINTERNATIONALPUBLIC--DUPUYP--DALLOZ-2010-2') + ->answers(Class_Notice::newInstanceWithId(33) + ->setTitrePrincipal('Les grands textes tome 2') + ->setAuteurPrincipal('Vidalio Nesto')); } } @@ -62,16 +79,32 @@ class Admin_FrbrLinkControllerIndexTest extends Admin_FrbrLinkControllerTestCase /** @test */ - public function firstRowTDShouldContainsSourceKey() { - $this->assertXPathContentContains('//tr[1]//td', - 'LESGRANDSTEXTESDEDROITINTERNATIONALPUBLI...'); + public function firstRowTDShouldContainsSourceTitle() { + $this->assertXPathContentContains('//tr[1]//td', 'Les grands textes tome 1'); + } + + + /** @test */ + public function firstRowTDShouldContainsSourceAuthor() { + $this->assertXPathContentContains('//tr[1]//td', 'Vidalio Nesti'); + } + + + /** @test */ + public function firstRowTDShouldContainsSourceLink() { + $this->assertXPath('//tr[1]//td//a[contains(@href, "LESGRANDSTEXTESDEDROITINTERNATIONALPUBLIC--DUPUYP--DALLOZ-2010-1")]'); + } + + + /** @test */ + public function firstRowTDShouldContainsTargetTitle() { + $this->assertXPathContentContains('//tr[1]//td', 'Les grands textes tome 2'); } /** @test */ - public function firstRowTDShouldContainsTargetKey() { - $this->assertXPathContentContains('//tr[1]//td', - 'LESGRANDSTEXTESDEDROITINTERNATIONALPUBLI...'); + public function firstRowTDShouldContainsTargetAuthor() { + $this->assertXPathContentContains('//tr[1]//td', 'Vidalio Nesto'); }