diff --git a/VERSIONS_HOTLINE/115415 b/VERSIONS_HOTLINE/115415 new file mode 100644 index 0000000000000000000000000000000000000000..1d339bcace5a34dd4db6b1c5653b785c398f99e9 --- /dev/null +++ b/VERSIONS_HOTLINE/115415 @@ -0,0 +1 @@ + - ticket #115415 : Magasin de thèmes : Correction du nom de l'auteur dans les documents. Le nom de l'auteur utilisé est celui indexé par Bokeh et non le nom présent dans l'unimarc. Ajout de la modération des bandes annonces dans l'onglet média des documents grâce au bouton activer ou désactiver la bande annonce. \ No newline at end of file diff --git a/application/modules/admin/controllers/RecordsController.php b/application/modules/admin/controllers/RecordsController.php index ef9c8b7096470a58a255e2aadcaac5cd20937ecf..c15d7ff8fa7d501987b0a7c2a646f9f89a12bc09 100644 --- a/application/modules/admin/controllers/RecordsController.php +++ b/application/modules/admin/controllers/RecordsController.php @@ -158,4 +158,20 @@ class Admin_RecordsController extends ZendAfi_Controller_Action { $this->_redirectToReferer(); } + + + public function disableTrailerAction() { + $this->_helper->notify((new Class_WebService_AllServices()) + ->disableTrailerForRecord($this->_getParam('id'))); + + $this->_redirectToReferer(); + } + + + public function enableTrailerAction() { + $this->_helper->notify((new Class_WebService_AllServices()) + ->enableTrailerForRecord($this->_getParam('id'))); + + $this->_redirectToReferer(); + } } diff --git a/library/Class/Notice.php b/library/Class/Notice.php index ce8ed1dcddedb31ff9a5acdf83f978e922e267fc..0aba5991233abb258d31aa3d19099cf73ec2449d 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -215,7 +215,8 @@ class Class_Notice extends Storm_Model_Abstract { $_langueCodes, $_first_exemplaire, $_data_map, - $_collation; + $_collation, + $_main_author_cache; protected $_default_attribute_values = ['type_doc' => 0, 'annee' => null, @@ -1989,4 +1990,20 @@ class Class_Notice extends Storm_Model_Abstract { public function getClefAlpha() { return $this->_get('clef_alpha'); } + + + public function getMainAuthorFromCodif() { + if ($this->_main_author_cache) + return $this->_main_author_cache; + + if ( ! $main_author = $this->getAuteurPrincipal()) + return ''; + + if ( ! $codif = Class_CodifAuteur::findWithFullName($main_author)) + return $main_author; + + $author_field = new Class_Notice_FieldAuthor($codif); + + return $this->_main_author_cache = $author_field->getLabel(); + } } diff --git a/library/Class/WebService/AllServices.php b/library/Class/WebService/AllServices.php index 5337721effa14d07e5973a0b1feef09c2dd0d587..dfacdf30677ffeeed1440653631e5f657b4ee6e3 100644 --- a/library/Class/WebService/AllServices.php +++ b/library/Class/WebService/AllServices.php @@ -34,7 +34,11 @@ class Class_WebService_AllServices { SVC_SET_TRAILER = 14, SVC_GET_THUMBNAIL = 10, BIO_ENABLED = 'enabled', - BIO_DISABLED = 'disabled'; + BIO_DISABLED = 'disabled', + + DISABLE_TRAILER = 'disable_trailer', + TRAILER_ENABLED = 0, + TRAILER_DISABLED = 1; private static $_http_client; @@ -201,7 +205,6 @@ class Class_WebService_AllServices { } - public function uploadTrailerForRecord($url, $id) { if (!$notice = Class_Notice::find($id)) return $this->_('Notice non trouvée'); @@ -218,7 +221,6 @@ class Class_WebService_AllServices { } - public static function httpGet($url, $args) { if (!isset(static::$_http_client)) static::$_http_client = new Class_WebService_SimpleWebClient(); @@ -306,4 +308,34 @@ class Class_WebService_AllServices { public function getServices() { return $this->services; } + + + public function disableTrailerForRecord($id) { + return $this->_toggelTrailerForRecord($id, $this->_('La bande-annonce a bien été désactivée.'), static::TRAILER_DISABLED); + } + + + public function enableTrailerForRecord($id) { + return $this->_toggelTrailerForRecord($id, $this->_('La bande-annonce a bien été activée.'), static::TRAILER_ENABLED); + } + + + protected function _toggelTrailerForRecord($id, $message, $flag) { + if ( ! $record = Class_Notice::find($id)) + return $this->_('Notice non trouvée'); + + $args = array_filter(['clef_oeuvre' => Class_Notice_WorkKey::legacy()->keyString($record), + 'type_doc' => $record->getFamilleId()]); + + $args [static::DISABLE_TRAILER] = $flag; + + $result = static::runServiceAfi(static::SVC_SET_TRAILER, $args); + + if (!isset($result['statut_recherche'])) + return $this->_('Le service n\'a pas répondu'); + + return static::RETOUR_SERVICE_OK == $result['statut_recherche'] + ? $message + : $result['message']; + } } \ No newline at end of file diff --git a/library/templates/Intonation/Library/LastFm.php b/library/templates/Intonation/Library/LastFm.php index a1b01683fa5793b8c2c3117f59ab730c8e580c3f..5a4abf1d8ced69668513f7c9e37942a58bc7d0a6 100644 --- a/library/templates/Intonation/Library/LastFm.php +++ b/library/templates/Intonation/Library/LastFm.php @@ -39,12 +39,12 @@ class Intonation_Library_LastFm extends Class_Entity { public function getAlbumPictures() { - return $this->_getPictures($this->getModel()->getAuteurPrincipal()); + return $this->_getPictures($this->getModel()->getMainAuthorFromCodif()); } public function getAlbumTracks() { - return $this->_getTracks($this->getModel()->getAuteurPrincipal(), $this->getModel()->getTitrePrincipal()); + return $this->_getTracks($this->getModel()->getMainAuthorFromCodif(), $this->getModel()->getTitrePrincipal(' ')); } @@ -101,8 +101,8 @@ class Intonation_Library_LastFm extends Class_Entity { return $elements; $title = $this->_('Illustration du document %s de %s', - $this->getModel()->getTitrePrincipal(), - $this->getModel()->getAuteurPrincipal(' ')); + $this->getModel()->getTitrePrincipal(' '), + $this->getModel()->getMainAuthorFromCodif()); $elements [] = new Intonation_Library_Picture(['Src' => $url, diff --git a/library/templates/Intonation/Library/Trailer.php b/library/templates/Intonation/Library/Trailer.php index a9ab5190ffbe4e58ca070eb225ff02c889ddc126..cc5695dc397203640649bcbb703caac9f8344058 100644 --- a/library/templates/Intonation/Library/Trailer.php +++ b/library/templates/Intonation/Library/Trailer.php @@ -20,4 +20,9 @@ */ -class Intonation_Library_Trailer extends Class_Entity {} +class Intonation_Library_Trailer extends Class_Entity { + + public function isDisabled() { + return (bool) $this->get('Disabled'); + } +} diff --git a/library/templates/Intonation/Library/Trailers.php b/library/templates/Intonation/Library/Trailers.php index 884b2d56d1aa1c14b81bdcfb8f0e1f3edb4c133d..740b2b5831385fa64e70204f3ec120f705db3364 100644 --- a/library/templates/Intonation/Library/Trailers.php +++ b/library/templates/Intonation/Library/Trailers.php @@ -40,12 +40,13 @@ class Intonation_Library_Trailers { public function trailers() { $args = ['titre' => $this->_model->getRecordTitle(), - 'auteur' => $this->_model->getAuteurPrincipal(), + 'auteur' => $this->_model->getMainAuthorFromCodif(), 'clef_oeuvre' => $this->_model->getClefOeuvre(), 'type_doc' => $this->_model->getFamilleId()]; $trailer_service = (new Class_WebService_AllServices); $data = $trailer_service->runServiceAfi($trailer_service::SVC_GET_TRAILER, $args); + if ( empty($data) ) return []; @@ -59,8 +60,12 @@ class Intonation_Library_Trailers { if ( !$url = $match[1]) return []; + $disabled = isset($data[Class_WebService_AllServices::DISABLE_TRAILER]) + && ($data[Class_WebService_AllServices::DISABLE_TRAILER] == Class_WebService_AllServices::TRAILER_DISABLED); + return [(new Intonation_Library_Trailer(['Source' => $data['source'], 'Model' => $this->_model, - 'Url' => $url]))]; + 'Url' => $url, + 'Disabled' => $disabled]))]; } } diff --git a/library/templates/Intonation/Library/View/Wrapper/Record.php b/library/templates/Intonation/Library/View/Wrapper/Record.php index 4b7f437edd8317acb0b08019bff4834bc684e0f5..79fd42d18a82ed138827c45f86a77096083f95d6 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Record.php +++ b/library/templates/Intonation/Library/View/Wrapper/Record.php @@ -38,7 +38,7 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra public function getSecondaryTitle() { - return $this->_model->getAuteurPrincipal(); + return $this->_model->getMainAuthorFromCodif(); } @@ -137,7 +137,7 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wra return new Intonation_Library_Link(['Url' => $author_field->getUrlForLink(), 'Image' => $this->getSecondaryIco(), - 'Text' => $author, + 'Text' => $author_field->getLabel(), 'Title' => $author_field->getTitle()]); } diff --git a/library/templates/Intonation/Library/View/Wrapper/Record/RichContent/Author.php b/library/templates/Intonation/Library/View/Wrapper/Record/RichContent/Author.php index a817e2af266c0aa109355d285e095c9da645dfca..e18013dab1517a983af817fa941eb2f1bb1bcf0f 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Record/RichContent/Author.php +++ b/library/templates/Intonation/Library/View/Wrapper/Record/RichContent/Author.php @@ -27,7 +27,7 @@ class Intonation_Library_View_Wrapper_Record_RichContent_Author extends Intonati public function getTitle() { return $this->_('Auteur principal : %s', - $this->_model->getAuteurPrincipal()); + $this->_model->getMainAuthorFromCodif()); } diff --git a/library/templates/Intonation/Library/View/Wrapper/Work/RichContent/Author.php b/library/templates/Intonation/Library/View/Wrapper/Work/RichContent/Author.php index 908822ac76d4c3d85ccdadfb36eb52a42d967a56..3a0bd2d3f7ca45734cdaaeeebee206b9d8373829 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Work/RichContent/Author.php +++ b/library/templates/Intonation/Library/View/Wrapper/Work/RichContent/Author.php @@ -28,7 +28,7 @@ class Intonation_Library_View_Wrapper_Work_RichContent_Author public function getTitle() { return $this->_('Auteur principal : %s', - $this->_model->getAuteurPrincipal()); + $this->_model->getMainAuthorFromCodif()); } diff --git a/library/templates/Intonation/View/RenderTrailers.php b/library/templates/Intonation/View/RenderTrailers.php index 8cec4ad5d9671b96283d265878f2bd3696443ed3..1f33cd63052edf4812c83c60f0a55c526300e503 100644 --- a/library/templates/Intonation/View/RenderTrailers.php +++ b/library/templates/Intonation/View/RenderTrailers.php @@ -29,14 +29,22 @@ class Intonation_View_RenderTrailers extends ZendAfi_View_Helper_BaseHelper { foreach ($trailers as $trailer) { $html [] = $this->_renderEdit($trailer) - . $this->view->renderEmbed($trailer->getSource(), - $trailer->getUrl()); + . $this->_toggleTrailer($trailer) + . $this->_renderTrailer($trailer); } return $this->_renderTrailers($html); } + protected function _renderTrailer($trailer) { + return $trailer->isDisabled() + ? '' + : $this->view->renderEmbed($trailer->getSource(), + $trailer->getUrl()); + } + + protected function _renderTrailers($html) { return implode($html); } @@ -46,6 +54,9 @@ class Intonation_View_RenderTrailers extends ZendAfi_View_Helper_BaseHelper { if (!Class_Users::isCurrentUserCanAccesBackend()) return ''; + if ($trailer->isDisabled()) + return ''; + $url = $this->view->url(['module' => 'admin', 'controller' => 'records', 'action' => 'trailer', @@ -59,4 +70,46 @@ class Intonation_View_RenderTrailers extends ZendAfi_View_Helper_BaseHelper { ->setImage(Class_Admin_Skin::current() ->renderButtonIconOn('configuration', $this->view))); } + + + protected function _toggleTrailer($trailer) { + if (!Class_Users::isCurrentUserCanAccesBackend()) + return ''; + + return $trailer->isDisabled() + ? $this->_renderEnableTrailer($trailer) + : $this->_renderDisableTrailer($trailer); + } + + + protected function _renderDisableTrailer($trailer) { + $url = $this->view->url(['module' => 'admin', + 'controller' => 'records', + 'action' => 'disable-trailer', + 'id' => $trailer->getModel()->getId()]); + + return $this->view + ->Admin_Button((new Class_Entity()) + ->setText($this->_('Désactiver la bande-annonce')) + ->setUrl($url) + ->setAttribs(['data-popup' => 'true']) + ->setImage(Class_Admin_Skin::current() + ->renderButtonIconOn('inactive', $this->view))); + } + + + protected function _renderEnableTrailer($trailer) { + $url = $this->view->url(['module' => 'admin', + 'controller' => 'records', + 'action' => 'enable-trailer', + 'id' => $trailer->getModel()->getId()]); + + return $this->view + ->Admin_Button((new Class_Entity()) + ->setText($this->_('Activer la bande-annonce')) + ->setUrl($url) + ->setAttribs(['data-popup' => 'true']) + ->setImage(Class_Admin_Skin::current() + ->renderButtonIconOn('active', $this->view))); + } } diff --git a/library/templates/Intonation/View/RenderTruncateList.php b/library/templates/Intonation/View/RenderTruncateList.php index a0a3c4ceae9b4d0101a19bad2739e777f14304ea..bda4d5e242f1a86450e5afd2efbf017b73fcb694 100644 --- a/library/templates/Intonation/View/RenderTruncateList.php +++ b/library/templates/Intonation/View/RenderTruncateList.php @@ -32,7 +32,6 @@ class Intonation_View_RenderTruncateList extends ZendAfi_View_Helper_BaseHelper public function renderTruncateList($collection, $callback, $page_size = 3) { - xdebug_break(); $this->_container_id = $id = uniqid(); $this->_input_id = 'input_' . $this->_container_id; diff --git a/tests/application/modules/admin/controllers/RecordsControllerTest.php b/tests/application/modules/admin/controllers/RecordsControllerTest.php index bf80c951a2d6ebbeb172e7d95d8cb6b3ab4eae7d..fe075f21ffc1d39e53f42ea8650a66ef669aa489 100644 --- a/tests/application/modules/admin/controllers/RecordsControllerTest.php +++ b/tests/application/modules/admin/controllers/RecordsControllerTest.php @@ -683,4 +683,52 @@ class RecordsControllerDeleteInexistingItemTest extends RecordsControllerTestCas public function responseShouldNotifyDeletion() { $this->assertFlashMessengerContentContains('Exemplaire non trouvé'); } +} + + + + +class RecordsControllerTrailerAdministrationTest extends RecordsControllerTestCase { + + /** @test */ + public function disableAcionshouldRedirectWithTrailerDisabledNotification() { + $this->_http_client + ->whenCalled('open_url') + ->with('http://cache.org' + .'?clef_oeuvre=HARRYPOTTER--ROWLINGJ-' + .'&type_doc=1' + .'&disable_trailer=1' + .'&src='.Class_WebService_AllServices::createSecurityKey() + .'&api=2.0' + .'&action=14') + ->answers(json_encode(['url_trailer' => 'https://youtu.be/BEPO2', + 'trailer_disabled' => 1, + 'statut_recherche' => 2])) + ->beStrict(); + + $this->dispatch('/admin/records/disable-trailer/id/12345'); + $this->assertFlashMessengerContentContains('La bande-annonce a bien été désactivée.'); + } + + + /** @test */ + public function enableAcionshouldRedirectWithTrailerEnabledNotification() { + $this->_http_client + + ->whenCalled('open_url') + ->with('http://cache.org' + .'?clef_oeuvre=HARRYPOTTER--ROWLINGJ-' + .'&type_doc=1' + .'&disable_trailer=0' + .'&src='.Class_WebService_AllServices::createSecurityKey() + .'&api=2.0' + .'&action=14') + ->answers(json_encode(['url_trailer' => 'https://youtu.be/BEPO2', + 'trailer_disabled' => 0, + 'statut_recherche' => 2])) + ->beStrict(); + + $this->dispatch('/admin/records/enable-trailer/id/12345'); + $this->assertFlashMessengerContentContains('La bande-annonce a bien été activée.'); + } } \ No newline at end of file diff --git a/tests/scenarios/SearchByWork/SearchResultByWorkTest.php b/tests/scenarios/SearchByWork/SearchResultByWorkTest.php index 3ba7a912b400d2f59d1fe95cc428c918c7974085..cbecd7ab9204f4c07ef861d11fbece169700207d 100644 --- a/tests/scenarios/SearchByWork/SearchResultByWorkTest.php +++ b/tests/scenarios/SearchByWork/SearchResultByWorkTest.php @@ -32,6 +32,7 @@ abstract class SearchResultByWorkTestCase extends AbstractControllerTestCase { Class_Profil::setCurrentProfil($profil); Class_CodifAuteur::newInstance(['id' => '2897', + 'libelle' => 'Terry Pratchett', 'code_alpha' => 'PRATCHETTxTERRY', 'youtube_channel_id' => '80937UINT']) ->assertSave(); diff --git a/tests/scenarios/Templates/TemplateDigitalResourcesTest.php b/tests/scenarios/Templates/TemplateDigitalResourcesTest.php index ae31c828753fbdc278c7c2f850016af65271dcf5..47c6fd05e1226e063ac25a18ac705f0877203fe8 100644 --- a/tests/scenarios/Templates/TemplateDigitalResourcesTest.php +++ b/tests/scenarios/Templates/TemplateDigitalResourcesTest.php @@ -236,4 +236,157 @@ class TemplateDigitalResourcesDilicomItemTest extends TemplateDigitalResourcesDi public function consultLinkShouldBeDisabled() { $this->assertXPathContentContains('//a[@data-disabled]', 'Consulter le livre en ligne'); } +} + + + +/** @see http://forge.afi-sa.fr/issues/115415 */ +class TemplateDigitalResourcesWrongIndexationTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + + $this->_buildTemplateProfil(['id' => 5, + 'template' => 'CHILI']); + + $this->fixture('Class_Notice', + ['id' => 34, + 'titre_principal' => 'Psycho', + 'type_doc' => Class_TypeDoc::DISQUE, + ]) + ->setAuteurPrincipal('M.'); + + $this->fixture('Class_CodifAuteur', + ['id' => 324, + 'libelle' => 'M']); + + $mock = $this->mock() + + ->whenCalled('getResponse') + ->with('https://www.last.fm/music/M/Psycho') + ->answers((new Class_Testing_HttpResponse) + ->setBody(file_get_contents(ROOT_PATH . 'tests/fixtures/lastfm_bashung_albums.html'))) + + ->whenCalled('getResponse') + ->with('https://www.last.fm/music/M/+images/') + ->answers((new Class_Testing_HttpResponse)->setBody(' +<html lang="fr"> + <head></head> + <body> + <ul class="image-list"> + <li class="image-list-item"> + <a href="/music/Sh%C5%8D+Aimoto/+images/" class="image-list-link"> + <img class="image-list-image" + src="https://lastfm-img2.akamaized.net/i/u/avatar170s/big_picture_300x300.jpg" + alt="None"> + </a> + </li> + </ul> + </body> +</html>')) + + ->beStrict(); + + Class_WebService_SimpleWebClient::setInstance($mock); + + $this->dispatch('/noticeajax/media/id/34'); + } + + + /** @test */ + public function authorNameShouldBeMWithoutEndingDot() { + $this->assertXPath('//img[@title = "Illustration du document Psycho de M"]'); + } +} + + + +abstract class TemplateDigitalResourcesTrailerAdministrationTestCase extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + + $this->_buildTemplateProfil(['id' => 5, + 'template' => 'CHILI']); + + $this->fixture('Class_Notice', + ['id' => 34, + 'titre_principal' => 'Psycho', + 'type_doc' => Class_TypeDoc::DISQUE, + ]) + ->setAuteurPrincipal('M.'); + + $this->fixture('Class_CodifAuteur', + ['id' => 324, + 'libelle' => 'M']); + + Class_CosmoVar::set('url_services', 'https://cache-server.org'); + + $mock_web = $this->mock() + + ->whenCalled('open_url') + ->answers(json_encode(['source' => 'test_bokeh', + 'disable_trailer' => $this->_is_trailer_disabled, + 'player' => '<iframe src="https://www.super-trailers.org/?media=18397590" style="width:500px; height:400px" frameborder="0"></iframe>'])); + + Class_WebService_AllServices::setHttpClient($mock_web); + + $this->dispatch('/noticeajax/media/id/34'); + } +} + + + + +class TemplateDigitalResourcesTrailerEnabledAdministrationTest extends TemplateDigitalResourcesTrailerAdministrationTestCase { + + protected $_is_trailer_disabled = 0; + + + /** @test */ + public function linkToEditTrailerShouldBePresent() { + $this->assertXPath('//button[@data-url = "/admin/records/trailer/id/34"]'); + } + + + /** @test */ + public function linkToDisableTrailerShouldBePresent() { + $this->assertXPath('//button[@data-url = "/admin/records/disable-trailer/id/34"]'); + } + + + /** @test */ + public function trailerShouldBeRender() { + $this->assertXPath('//iframe[@src="https://www.super-trailers.org/?media=18397590"]'); + } +} + + + + +class TemplateDigitalResourcesTrailerDisabledAdministrationTest extends TemplateDigitalResourcesTrailerAdministrationTestCase { + + protected $_is_trailer_disabled = 1; + + + /** @test */ + public function linkToEditTrailerShouldNotBePresent() { + $this->assertNotXPath('//button[@data-url = "/admin/records/trailer/id/34"]'); + } + + + /** @test */ + public function linkToEnableTrailerShouldBePresent() { + $this->assertXPath('//button[@data-url = "/admin/records/enable-trailer/id/34"]'); + } + + + /** @test */ + public function trailerShouldNotBeRender() { + $this->assertNotXPath('//iframe[@src="https://www.super-trailers.org/?media=18397590"]'); + } } \ No newline at end of file