Commit 0129c7c2 authored by Patrick Barroca's avatar Patrick Barroca 😁
Browse files

Merge branch 'dev#65267_bonus_moderation_des_videos' into 'master'

Dev#65267 bonus moderation des videos

See merge request afi/opacce!2427
parents 1e065005 54f6b1b4
'65267' =>
['Label' => $this->_('Modération des vidéos'),
'Desc' => $this->_('Vous pouvez désormais proposer une url de bande-annonce pour une notice'),
'Image' => '',
'Video' => 'https://www.youtube.com/watch?v=PMHhBcoB68Y',
'Category' => $this->_('Administration'),
'Right' => function($feature_description, $user) {return true;},
'Wiki' => 'http://wiki.bokeh-library-portal.org/index.php?title=Modifier_une_bande_annonce',
'Test' => '',
'Date' => '2017-11-27'],
\ No newline at end of file
- ticket #65267 : Administration : Modération des vidéos de bande-annonces
\ No newline at end of file
......@@ -77,4 +77,23 @@ class Admin_RecordsController extends ZendAfi_Controller_Action {
$this->view->form = $form;
}
public function trailerAction() {
$this->view->titre = $this->_('Modifier la bande-annonce');
$form = new ZendAfi_Form_RecordTrailer(['action' => $this->view->url()]);
$this->view->form = $form;
if (!$this->_request->isPost() || !$form->isValid($this->_request->getPost()))
return $this;
if ($this->view->error = (new Class_WebService_AllServices())
->uploadTrailerForRecord($this->_getParam('url_trailer'),
$this->_getParam('id')))
return $this;
$this->_helper->notify($this->_('La bande-annonce a bien été mise à jour'));
$this->_redirectClose($this->_getReferer());
}
}
<?php
if ($this->error)
echo $this->tag('p', $this->error, ['class' => 'error']);
echo $this->renderForm($this->form);
......@@ -220,24 +220,9 @@ class NoticeAjaxController extends Zend_Controller_Action {
public function bandeannonceAction() {
session_write_close();
if ($this->service_afi > "") {
$width = $this->_getParam('width', 500);
$height = (int)($width * 4/5);
$args= ['titre' => $this->notice->getRecordTitle(),
'auteur' => $this->notice->getAuteurPrincipal(),
'width' => $width,
'height' => $height];
$data=Class_WebService_AllServices::runServiceAfi(6,$args);
$source=$data["source"];
$bo=$data["player"];
$html=$this->notice_html->getBandeAnnonce($source,$bo);
}
else
$html= $html=$this->notice_html->getNonTrouve($this->view->_("Service non disponible"),true);
$this->_sendResponseWithScripts($html);
$this->_sendResponseWithScripts(
$this->view->trailer($this->notice,
$this->_getParam('width', 500)));
}
......
......@@ -20,6 +20,8 @@
*/
class Class_WebService_AllServices {
use Trait_Translator;
const RETOUR_SERVICE_OK = 2;
const SVC_API = '2.0';
......@@ -97,6 +99,11 @@ class Class_WebService_AllServices {
}
public static function runServiceAfiUploadTrailer($args) {
return self::runServiceAfi(14, $args);
}
public static function runServiceGetUrlVignette($args) {
return self::runServiceAfi(10, $args);
}
......@@ -138,6 +145,24 @@ class Class_WebService_AllServices {
}
public function uploadTrailerForRecord($url, $id) {
if (!$notice = Class_Notice::find($id))
return $this->_('Notice non trouvée');
$result = static::runServiceAfiUploadTrailer(array_filter(['url_trailer' => $url,
'clef_oeuvre' => $notice->getClefOeuvre(),
'type_doc' => $notice->getFamilleId()]));
if (!isset($result['statut_recherche']))
return $this->_('Le service n\'a pas répondu');
if (self::RETOUR_SERVICE_OK != $result['statut_recherche'])
return $result['message'];
}
public static function httpGet($url, $args) {
if (!isset(self::$_http_client))
self::$_http_client = new Class_WebService_SimpleWebClient();
......
......@@ -16,23 +16,21 @@
*
* 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_Form_BiographieNotice extends ZendAfi_Form {
public function init() {
parent::init();
$this
->addElement('url',
'url_auteur',
->addElement('url',
'url_auteur',
['label' => $this->_('URL Wikipedia de l\'auteur'),
'size' => 80,
'required' => true,
'allowEmpty' => false,
'placeholder' => 'ex: http://fr.wikipedia.org/wiki/Henri_Laborit'])
->addElement('submit',
'envoyer',
['label' => 'Envoyer']);
->addToHeadGroup(['url_auteur'])
;
}
}
?>
\ No newline at end of file
}
\ No newline at end of file
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* 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).
*
* 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
* 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
*/
class ZendAfi_Form_RecordTrailer extends ZendAfi_Form {
public function init() {
parent::init();
$this
->addElement('url',
'url_trailer',
['label' => $this->_('URL de la bande-annonce'),
'size' => 80,
'required' => true,
'allowEmpty' => false,
'placeholder' => 'ex: https://youtu.be/AUI12X'])
->addToHeadGroup(['url_trailer'])
;
}
}
\ No newline at end of file
......@@ -47,8 +47,13 @@ class ZendAfi_View_Helper_Biographie extends ZendAfi_View_Helper_BaseHelper {
'action' => 'biography',
'id' => $notice->getId()]);
return $this->_tag('a', $this->_('Modifier la biographie'),
['href' => $url, 'data-popup' => 'true']);
return $this->view
->admin_Button((new Class_Entity())
->setText($this->_('Modifier la biographie'))
->setUrl($url)
->setAttribs(['data-popup' => 'true'])
->setImage(Class_Admin_Skin::current()
->renderButtonIconOn('configuration', $this->view)));
}
......
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* 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).
*
* 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
* 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
*/
class ZendAfi_View_Helper_Trailer extends ZendAfi_View_Helper_BaseHelper {
public function trailer($notice, $width) {
return trim(Class_CosmoVar::get('url_services'))
? $this->_renderTrailer($notice, $width)
: $this->_renderServiceUnavailable();
}
protected function _renderServiceUnavailable() {
return (new Class_NoticeHtml())
->getNonTrouve($this->view->_('Service non disponible'),
true);
}
protected function _renderTrailer($notice, $width) {
return
$this->_renderEditLink($notice)
.
$this->_renderPlayer($notice, $width);
}
protected function _renderPlayer($notice, $width) {
$height = (int)($width * 4/5);
$args= ['titre' => $notice->getRecordTitle(),
'auteur' => $notice->getAuteurPrincipal(),
'clef_oeuvre' => $notice->getClefOeuvre(),
'type_doc' => $notice->getFamilleId(),
'width' => $width,
'height' => $height];
$data = Class_WebService_AllServices::runServiceAfi(6, $args);
return (new Class_NoticeHtml())->getBandeAnnonce($data['source'],
$data['player']);
}
protected function _renderEditLink($notice) {
if (!Class_Users::isCurrentUserCanAccesBackend())
return '';
$url = $this->view->url(['module' => 'admin',
'controller' => 'records',
'action' => 'trailer',
'id' => $notice->getId()]);
return $this->view
->admin_Button((new Class_Entity())
->setText($this->_('Modifier la bande-annonce'))
->setUrl($url)
->setAttribs(['data-popup' => 'true'])
->setImage(Class_Admin_Skin::current()
->renderButtonIconOn('configuration', $this->view)));
}
}
......@@ -325,12 +325,6 @@ class RecordsControllerBiographyTest extends RecordsControllerTestCase {
public function formShouldHaveInputUrlAuteur() {
$this->assertXPath('//form//input[@type="url"][@name="url_auteur"][contains(@placeholder, "ex: http://fr.wikipedia.org/wiki/Henri_Laborit")]');
}
/** @test */
public function formShouldHaveSubmitButtonEnvoyer() {
$this->assertXPath('//form//input[@type="submit"][@value="Envoyer"]');
}
}
......@@ -383,4 +377,74 @@ class RecordsControllerBiographyPostServeurCacheErrorTest extends RecordsControl
public function pageShouldDisplayErrorMessageBiographieNonTrouvee() {
$this->assertXPathContentContains('//p[@class="error"]', 'Biographie non trouvée');
}
}
\ No newline at end of file
}
class RecordsControllerTrailerTest extends RecordsControllerTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/admin/records/trailer/id/12345', true);
}
/** @test */
public function formShouldHaveInputUrlTrailer() {
$this->assertXPath('//form//input[@type="url"][@name="url_trailer"][contains(@placeholder, "ex: https://youtu.be/AUI12X")]');
}
}
class RecordsControllerTrailerPostTest extends RecordsControllerTestCase {
/** @test */
public function withValidUrlPageShouldDisplayTrailerUpdated() {
$this->_http_client
->whenCalled('open_url')
->with('http://cache.org'
.'?url_trailer='.urlencode('https://youtu.be/BEPO2')
.'&clef_oeuvre=HARRY_POTTER'
.'&type_doc=1'
.'&src='.Class_WebService_AllServices::createSecurityKey()
.'&api=2.0'
.'&action=14')
->answers(json_encode(['url_trailer' => 'http://youtu.be/BEPO2',
'statut_recherche' => 2]))
->beStrict();
$this->postDispatch('/admin/records/trailer/id/12345',
['url_trailer' => 'https://youtu.be/BEPO2']);
$this->assertFlashMessengerContentContains('La bande-annonce a bien été mise à jour');
}
/** @test */
public function withInvalidUrlPageShouldDisplayError() {
$this->_http_client
->whenCalled('open_url')
->answers(json_encode(['message' => 'source inconnue',
'statut_recherche' => 0]));
$this->postDispatch('/admin/records/trailer/id/12345',
['url_trailer' => 'http://mavid.eo']);
$this->assertXPathContentContains('//p[@class="error"]', 'source inconnue');
}
/** @test */
public function withErrorFromCacheServerPageShouldDisplayError() {
$this->_http_client
->whenCalled('open_url')
->answers('');
$this->postDispatch('/admin/records/trailer/id/12345',
['url_trailer' => 'http://mavid.eo']);
$this->assertXPathContentContains('//p[@class="error"]',
'Le service n\'a pas répondu');
}
}
......@@ -461,14 +461,66 @@ class NoticeAjaxControllerResNumeriquesFromFrbrLinkNonAdminTest extends NoticeAj
class NoticeAjaxControllerBandeAnnonceTest extends AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
Class_CosmoVar::setValueOf('url_services', 'https://websvc.net/main.php');
Class_WebService_AllServices
::setHttpClient(
Storm_Test_ObjectWrapper::mock()
->whenCalled('open_url')
->answers(json_encode(['source' => 'Testing',
'player' => 'toto'])));
$this->fixture('Class_Notice',
['id' => 2,
'unimarc' => file_get_contents(ROOT_PATH . 'tests/fixtures/dvd_potter.uni'),
'clef_oeuvre' => 'POTTER',
'type_doc' => Class_TypeDoc::DVD]);
}
public function tearDown() {
Class_WebService_AllServices::setHttpClient(null);
parent::tearDown();
}
/** @test */
public function shouldContainsSourceTitle() {
Class_WebService_AllServices::setHttpClient(
Storm_Test_ObjectWrapper::mock()
->whenCalled('open_url')
->answers(json_encode(['source' => 'Testing', 'player' => 'toto'])));
$this->dispatch('noticeajax/bandeannonce', true);
$this->assertXPathContentContains('//h3', 'Source : Testing', $this->_response->getBody());
public function responseShouldContainsSourceTitle() {
$this->dispatch('noticeajax/bandeannonce/id/2', true);
$this->assertXPathContentContains('//h3',
'Source : Testing',
$this->_response->getBody());
}
/** @test */
public function asAPatronResponseShouldNotLinkToEditTrailer() {
Zend_Auth::getInstance()
->logUser($this->fixture('Class_Users',
['id' => 15,
'login'=>'someone',
'password' => 'is here',
'id_bib' => 3])->beAbonneSIGB());
$this->dispatch('noticeajax/bandeannonce/id/2', true);
$this->assertNotXPath('//button');
}
/** @test */
public function asAdminResponseShouldContainLinkToEditTrailer() {
Zend_Auth::getInstance()
->logUser($this->fixture('Class_Users',
['id' => 15,
'login'=>'someone',
'password' => 'is here',
'id_bib' => 3])->beModoBib());
$this->dispatch('noticeajax/bandeannonce/id/2', true);
$this->assertXPath('//button[@data-popup="true"][contains(@data-url, "records/trailer/id/2")]');
}
......@@ -479,14 +531,10 @@ class NoticeAjaxControllerBandeAnnonceTest extends AbstractControllerTestCase {
Class_WebService_AllServices::setHttpClient(
Storm_Test_ObjectWrapper::mock()
->whenCalled('open_url')
->with('https://websvc.afi-sa.net/afi_opac_services/main.php?titre=Harry+Potter+%C3%A0+l%27%C3%A9cole+des+sorciers&auteur=Chris+Columbus&width=500&height=400&src=' . $key . '&api=2.0&action=6')
->with('https://websvc.net/main.php?titre=Harry+Potter+%C3%A0+l%27%C3%A9cole+des+sorciers&auteur=Chris+Columbus&clef_oeuvre=POTTER&type_doc=4&width=500&height=400&src=' . $key . '&api=2.0&action=6')
->answers(json_encode(['source' => 'CommeAuCinema', 'player' => '<iframe></iframe>']))
->beStrict());
$this->fixture('Class_Notice',
['id' => 2,
'unimarc' => file_get_contents(ROOT_PATH . 'tests/fixtures/dvd_potter.uni'),
'type_doc' => Class_TypeDoc::DVD]);
$this->dispatch('noticeajax/bandeannonce/id/2', true);
$this->assertXPath('//iframe', $this->_response->getBody());
}
......@@ -1933,7 +1981,7 @@ class NoticeAjaxControllerBiographieTest extends NoticeAjaxControllerBiographieT
/** @test */
public function linkModifierLaBiographieShouldBeVisible() {
$this->assertXPathContentContains('//a', 'Modifier la biographie');
$this->assertXPathContentContains('//button', 'Modifier la biographie');
}
......@@ -1957,7 +2005,7 @@ class NoticeAjaxControllerBiographieTest extends NoticeAjaxControllerBiographieT
Zend_Auth::getInstance()->logUser($abon);
$this->dispatch('/opac/noticeajax/biographie/id_notice/23', true);
$this->assertNotXPathContentContains('//a', 'Modifier la biographie');
$this->assertNotXPathContentContains('//button', 'Modifier la biographie');
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment