Commit 83d8622b authored by Patrick Barroca's avatar Patrick Barroca 🐧

Merge branch 'dev#106074_fiche_auteur_pas_de_biographie' into 'master'

dev #106074 add button to disable biography

See merge request !3415
parents a743134b f32ccc44
Pipeline #9565 passed with stage
in 43 minutes and 15 seconds
'106074' =>
['Label' => $this->_('Désactiver une biographie'),
'Desc' => $this->_('Bokeh permet de désactiver l\'affichage de la biographie d\'un homonyme'),
'Image' => '',
'Video' => '',
'Category' => $this->_('Administration'),
'Right' => function($feature_description, $user) {return true;},
'Wiki' => 'http://wiki.bokeh-library-portal.org/index.php?title=Modifier_la_biographie_issue_de_Wikip%C3%A9dia',
'Test' => '',
'Date' => '2020-02-20'],
\ No newline at end of file
- ticket #106074 : Vue notice : Bokeh permet de désactiver l'affichage de la biographie d'un homonyme
\ No newline at end of file
......@@ -104,6 +104,30 @@ class Admin_RecordsController extends ZendAfi_Controller_Action {
}
public function disableBiographyAction() {
$record = Class_Notice::find($this->_getParam('record_id'));
$author = Class_CodifAuteur::find($this->_getParam('author_id'));
$language = $this->_getParam('language');
(new Class_WebService_AllServices())->disableBiographyForRecord($author, $record, $language);
$this->_helper->notify($this->_('La biographie a été désactivée pour %s',
$author->getLibelle()));
$this->_redirectToReferer();
}
public function enableBiographyAction() {
$record = Class_Notice::find($this->_getParam('record_id'));
$author = Class_CodifAuteur::find($this->_getParam('author_id'));
$language = $this->_getParam('language');
(new Class_WebService_AllServices())->enableBiographyForRecord($author, $record, $language);
$this->_helper->notify($this->_('La biographie a été activée pour %s',
$author->getLibelle()));
$this->_redirectToReferer();
}
public function trailerAction() {
$this->view->titre = $this->_('Modifier la bande-annonce');
......
......@@ -36,6 +36,13 @@ class Class_CodifAuteur_Description {
}
public function restrictToRecord($record) {
$this->_all_records = [$record];
$this->_associated_authors = [];
return $this;
}
public function getAuthor() {
return $this->_author;
}
......@@ -102,12 +109,28 @@ class Class_CodifAuteur_Description {
}
public function hasBiography() {
return !empty($this->_fetchBiographyFromCacheServer()['wikidata_id']);
}
public function isBiographyDisabled() {
$biography = $this->_fetchBiographyFromCacheServer();
if (!isset($biography['biography_disabled']))
return false;
return 1 === (int)$biography['biography_disabled'];
}
public function renderBiographieOn($view) {
if (!count($this->getRecords()))
return '';
$data = $this->fetchBiography();
if ($this->isBiographyDisabled())
return $this->renderEditButtonOn($view);
$data = $this->fetchBiography();
if ($biography = $data->getbiographie()) {
$biography = $this->_enrichBiographyWithRecords($biography,
$this->getRecords(),
......@@ -126,14 +149,13 @@ class Class_CodifAuteur_Description {
'alt' => $this->getLabel() . '. ' . $this->_('Source: Wikipedia')]);
$update_button = $view->biographie_UpdateButton($this->getRecords()[0],
$this->getLabel());
$update_buttons = $this->renderEditButtonOn($view);
$licence = $view->biographie_Licence($this->getLabel(),
$data->getsource(),
$data->geturl_source());
$licence = $view->biography_Licence($this->getLabel(),
$data->getsource(),
$data->geturl_source());
return $update_button . $thumbnail . $biography . $licence;
return $update_buttons . $thumbnail . $biography . $licence;
}
......@@ -198,14 +220,14 @@ class Class_CodifAuteur_Description {
}
protected function _fetchBiography($author, $all_records, $associated_authors) {
protected function _fetchBiographyFromCacheServer() {
if ($this->_biography)
return $this->_biography;
if (!$all_records)
if (!$all_records = $this->getRecords())
return [];
$args = ['auteur' => $author->getLibelle(),
$args = ['auteur' => $this->_author->getLibelle(),
'clef_oeuvre' => $all_records[0]->getClefOeuvre(),
'language' => Class_Profil::getCurrentProfil()->getLocale()];
......@@ -214,9 +236,7 @@ class Class_CodifAuteur_Description {
public function fetchBiography() {
$bio = new Class_Entity($this->_fetchBiography($this->_author,
$this->getRecords(),
$this->getAssociatedAuthors()));
$bio = new Class_Entity($this->_fetchBiographyFromCacheServer());
$author_attribs = array_intersect_key($bio->toArray(),
['wikidata_id' => '',
......@@ -306,17 +326,15 @@ class Class_CodifAuteur_Description {
public function renderEditButtonOn($view) {
if (!$records = $this->getRecords())
return '';
return $view->biographie_UpdateButton($this->getRecords()[0],
$this->getLabel());
return $view->biography_UpdateButtons($this);
}
public function renderThumbnailOn($view) {
$this->fetchBiography();
if ($this->isBiographyDisabled())
return '';
$this->fetchBiography();
return $this->_author->getThumbnailUrl()
? $view->tag('img',
null,
......@@ -327,8 +345,10 @@ class Class_CodifAuteur_Description {
public function renderWikipediaOn($view) {
$data = $this->fetchBiography();
if ($this->isBiographyDisabled())
return '';
$data = $this->fetchBiography();
if (!$biography = $data->getbiographie())
return '';
......@@ -338,6 +358,9 @@ class Class_CodifAuteur_Description {
return $this->_enrichBiographyWithAuthorLinks($biography,
$this->getAssociatedAuthors(),
$view);
$view)
. $view->biography_Licence($this->getLabel(),
$data->getsource(),
$data->geturl_source());
}
}
\ No newline at end of file
......@@ -22,9 +22,18 @@
class Class_WebService_AllServices {
use Trait_Translator;
const RETOUR_SERVICE_OK = 2;
const SVC_API = '2.0';
const
RETOUR_SERVICE_OK = 2,
SVC_API = '2.0',
SVC_GET_BIOGRAPHY = 8,
SVC_GET_VIDEO = 9,
SVC_GET_INTERVIEW = 7,
SVC_UPLOAD_THUMBNAIL = 12,
SVC_SET_BIOGRAPHY = 13,
SVC_SET_TRAILER = 14,
SVC_GET_THUMBNAIL = 10,
BIO_ENABLED = 'enabled',
BIO_DISABLED = 'disabled';
private static $_http_client;
......@@ -75,37 +84,36 @@ class Class_WebService_AllServices {
public static function runServiceAfiBiographie($args) {
return self::runServiceAfi(8, $args);
return self::runServiceAfi(static::SVC_GET_BIOGRAPHY, $args);
}
public static function runServiceAfiVideo($args) {
return self::runServiceAfi(9, $args);
return self::runServiceAfi(static::SVC_GET_VIDEO, $args);
}
public static function runServiceAfiInterviews($args) {
return self::runServiceAfi(7, $args);
return self::runServiceAfi(static::SVC_GET_INTERVIEW, $args);
}
public static function runServiceAfiUploadVignette($args) {
return self::runServiceAfi(12, $args);
return self::runServiceAfi(static::SVC_UPLOAD_THUMBNAIL, $args);
}
public static function runServiceAfiUploadBiographie($args) {
return self::runServiceAfi(13, $args);
return self::runServiceAfi(static::SVC_SET_BIOGRAPHY, $args);
}
public static function runServiceAfiUploadTrailer($args) {
return self::runServiceAfi(14, $args);
return self::runServiceAfi(static::SVC_SET_TRAILER, $args);
}
public static function runServiceGetUrlVignette($args) {
return self::runServiceAfi(10, $args);
return self::runServiceAfi(static::SVC_GET_THUMBNAIL, $args);
}
......@@ -147,6 +155,27 @@ class Class_WebService_AllServices {
public function disableBiographyForRecord($author, $record, $lang) {
return $this->toggleBiographyForRecord($author, $record, $lang, static::BIO_DISABLED);
}
public function enableBiographyForRecord($author, $record, $lang) {
return $this->toggleBiographyForRecord($author, $record, $lang, static::BIO_ENABLED);
}
public function toggleBiographyForRecord($author, $record, $lang, $status) {
$result = static::runServiceAfiUploadBiographie(['auteur' => $author->getLibelle(),
'clef_oeuvre' => $record->getClefOeuvre(),
'language' => $lang,
'biography_disabled' => ($status == static::BIO_DISABLED) ? 1 : 0]);
if (self::RETOUR_SERVICE_OK != $result['statut_recherche'])
return $result['message'];
}
public function uploadTrailerForRecord($url, $id) {
if (!$notice = Class_Notice::find($id))
return $this->_('Notice non trouvée');
......
......@@ -29,43 +29,44 @@ class ZendAfi_View_Helper_Biographie extends ZendAfi_View_Helper_BaseHelper {
if (!Class_CosmoVar::get('url_services'))
return $notice_html->getNonTrouve($this->_('Service non disponible'));
$args = ['auteur' => $auteur,
'clef_oeuvre' => $notice->getClefOeuvre(),
'language' => Class_Profil::getCurrentProfil()->getLocale()];
if (!$codif_author = Class_CodifAuteur::findWithFullName($auteur))
return $notice_html->getNonTrouve($this->_('Auteur inconnu'));
$author_description = (new Class_CodifAuteur_Description($codif_author))
->restrictToRecord($notice);
$data = Class_WebService_AllServices::runServiceAfiBiographie($args);
return
$this->view->biographie_UpdateButton($notice, $auteur)
$this->view->biography_UpdateButtons($author_description)
.
$this->renderBiographie($data, $notice);
$this->_renderBiographie($author_description, $notice);
}
protected function _renderBiographie($description, $notice) {
$data = $description->fetchBiography();
if ($description->isBiographyDisabled())
$data->setbiographie('');
if (!$data->getbiographie())
$data->setsource($this->_("Aucune information n'a été trouvée"));
public function renderBiographie($data, $notice) {
if(!$data['biographie']) {
$data['source'] = $this->_("Aucune information n'a été trouvée");
$data['biographie'] = [];
}
$source = $this->view->tag('p', $this->view->_('Source'). ' : ' . $data['source']);
$source = $this->view->tag('p', $this->view->_('Source'). ' : ' . $data->getsource());
$auteur = $notice->getAuteurPrincipal();
$biographie = $data['biographie'];
$biographie = $data->getbiographie();
$source .= $this->view->biographie_Licence($auteur,$data['source'], $data['url_source']);
$source .= $this->view->biography_Licence($auteur,
$data->getsource(),
$data->geturl_source());
if(!is_array($biographie) && preg_match("/<[^<]+>/", $biographie) != 0)
return $biographie.$source;
$content = $this->_renderTitle($auteur, $source);
$suite = false;
foreach ($data['biographie'] as $ligne) {
foreach ((array)$biographie as $ligne) {
$content .= $this->_renderBio($ligne, $suite, $data, $auteur, $notice);
$suite = true;
}
......@@ -126,15 +127,15 @@ class ZendAfi_View_Helper_Biographie extends ZendAfi_View_Helper_BaseHelper {
protected function _renderVignette($bio, $data, $auteur, $notice) {
if (!$data['vignette'])
if (!$url_thumbnail = $data->getvignette())
return '';
$html = $this
->view->tagImg($data['vignette'],
->view->tagImg($url_thumbnail,
['style' => 'border:0;width:100px;float:left;margin-right:5px;cursor:pointer',
'alt' => $this->_('Vignette')]);
if (!$data['image'])
if (!$url_image = $data->getimage())
return $html;
$id = 'auteur_' . $notice->getId();
......@@ -143,7 +144,7 @@ class ZendAfi_View_Helper_Biographie extends ZendAfi_View_Helper_BaseHelper {
return $this->_tag('a', $html,
['id' => $id,
'href' => $data['image'],
'href' => $url_image,
'rel' => 'lightbox',
'title' => $auteur]);
}
......@@ -173,5 +174,3 @@ class ZendAfi_View_Helper_Biographie extends ZendAfi_View_Helper_BaseHelper {
return $html;
}
}
?>
......@@ -20,8 +20,8 @@
*/
class ZendAfi_View_Helper_Biographie_Licence extends ZendAfi_View_Helper_BaseHelper{
public function biographie_Licence($author, $source, $url) {
class ZendAfi_View_Helper_Biography_Licence extends ZendAfi_View_Helper_BaseHelper{
public function biography_Licence($author, $source, $url) {
if ($source != 'Wikipedia')
return '';
......@@ -32,53 +32,54 @@ class ZendAfi_View_Helper_Biographie_Licence extends ZendAfi_View_Helper_BaseHel
}
protected function _renderCreativeCommonsLink($url) {
$language = substr($url,8,2);
$cc_link_params = ['rel' => "license",
'href' => $this->_('http://creativecommons.org/licenses/by-sa/3.0/deed.%s', $language),
'title' => $this->_('Licence Creative Commons')];
protected function _renderCreativeCommonsLink($url) {
$parts = explode('.', parse_url($url, PHP_URL_HOST));
$language = (3 > count($parts)) ? 'en' : $parts[0];
return $this->_tag('p',
$this->_tag('a',
$this->_tag('img', null,
[
'alt' => $this->_('Licence Creative Commons'),
'style' => 'border-width:0',
'src' => $this->_('https://i.creativecommons.org/l/by-sa/3.0/%s/80x15.png',$language)
]),
$cc_link_params)
. ' ' . $this->_('Ce contenu est mis à disposition selon les termes de la')
. ' ' . $this->_tag('a',
$this->_('Licence Creative Commons Attribution - Partage dans les Mêmes Conditions 3.0'),
$cc_link_params));
}
$cc_link_params = ['rel' => 'license',
'href' => $this->_('http://creativecommons.org/licenses/by-sa/3.0/deed.%s', $language),
'title' => ''];
return $this
->_tag('p',
$this->_tag('a',
$this->_tag('img', null,
[
'alt' => '',
'style' => 'border-width:0',
'src' => $this->_('https://i.creativecommons.org/l/by-sa/3.0/%s/80x15.png', $language)
]),
$cc_link_params)
. ' '
. $this->_('Ce contenu est mis à disposition selon les termes de %s',
$this->_tag('a',
$this->_('Licence Creative Commons Attribution - Partage dans les Mêmes Conditions 3.0'),
$cc_link_params))
);
}
protected function _renderLinkToWikipediaPage($author, $url) {
$language = substr($url,8,2);
return $this->_tag('p',
'Source : Article '
. $this->_tag('a',$author ,
['href' => $url,
'title' => $this->_('Ouvrir la page wikipedia pour') . ' ' . $author])
.' '.
$this->_('de') . ' ' .
$this->_tag('a',
'Wikipédia',
['href' => $this->_('https://%s.wikipedia.org/', $language),
'title' => $this->_('Accéder à Wikipedia')]));
}
protected function _renderLinkToWikipediaPage($author, $url) {
return $this->_('Source : Article %s de %s',
$this->_tag('a', $author,
['href' => $url,
'title' => $this->_('Ouvrir la page wikipedia pour %s', $author)]),
$this->_tag('a',
$this->_('Wikipédia'),
['href' => 'https://www.wikipedia.org/',
'title' => $this->_('Accéder à Wikipedia')]));
}
protected function _renderLinkToContributors($author, $url) {
$contribs_url = $url . (strpos($url,'?') === false ? '?' : '&') . 'action=history';
protected function _renderLinkToContributors($author, $url) {
$url .= (strpos($url, '?') === false ? '?' : '&') . 'action=history';
return $this->_tag('p',
$this->_('Contributeurs'). ' : '.
$this->_tag('a',
$this->_('voir la liste'),
['href' => $contribs_url,
'title' => $this->_('Voir la liste des contributions de la page Wikipedia pour') . ' ' . $author]));
}
return $this
->_tag('p',
$this->_('Contributeurs : %s',
$this->_tag('a',
$this->_('voir la liste'),
['href' => $url,
'title' => $this->_('Voir la liste des contributions de la page Wikipedia pour %s', $author)])));
}
}
......@@ -19,17 +19,44 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_View_Helper_Biographie_UpdateButton extends ZendAfi_View_Helper_BaseHelper {
public function biographie_UpdateButton($record, $author_label) {
class ZendAfi_View_Helper_Biography_UpdateButtons extends ZendAfi_View_Helper_BaseHelper {
public function biography_UpdateButtons($author_description) {
if (!Class_Users::isCurrentUserCanAccesBackend())
return '';
$url = $this->view->url(['module' => 'admin',
'controller' => 'records',
'action' => 'biography',
'auteur' => $author_label,
'language' => Class_Profil::getCurrentProfil()->getLocale(),
'id' => $record->getId()], null, true);
if (!$records = $author_description->getRecords())
return '';
return
$this->_renderUpdateBiographyButton($author_description)
.
$this->_renderToggleBiographyButton($author_description);
}
protected function _biographyActionUrl($author_description, $action) {
return $this
->view
->url(['module' => 'admin',
'controller' => 'records',
'action' => $action,
'author_id' => $author_description->getId(),
'language' => Class_Profil::getCurrentProfil()->getLocale(),
'record_id' => $author_description->getRecords()[0]->getId()], null, true);
}
protected function _renderUpdateBiographyButton($author_description) {
$url = $this
->view
->url(['module' => 'admin',
'controller' => 'records',
'action' => 'biography',
'auteur' => $author_description->getLabel(),
'language' => Class_Profil::getCurrentProfil()->getLocale(),
'id' => $author_description->getRecords()[0]->getId()],
null,
true);
return $this->view
->Admin_Button((new Class_Entity())
......@@ -39,4 +66,44 @@ class ZendAfi_View_Helper_Biographie_UpdateButton extends ZendAfi_View_Helper_Ba
->setImage(Class_Admin_Skin::current()
->renderButtonIconOn('configuration', $this->view)));
}
protected function _renderToggleBiographyButton($author_description) {
if (!$author_description->hasBiography())
return '';
return $author_description->isBiographyDisabled()
? $this->_renderEnableBiographyButton($author_description)
: $this->_renderDisableBiographyButton($author_description);
}
protected function _renderDisableBiographyButton($author_description) {
$url = $this->_biographyActionUrl($author_description,
'disable-biography');
return $this->view
->Admin_Button((new Class_Entity())
->setText($this->_('Désactiver la biographie pour %s',
$author_description->getLabel()))
->setUrl($url)
->setImage(Class_Admin_Skin::current()
->renderButtonIconOn('remove', $this->view)));
}
protected function _renderEnableBiographyButton($author_description) {
$url = $this->_biographyActionUrl($author_description,
'enable-biography');
return $this->view
->Admin_Button((new Class_Entity())
->setText($this->_('Activer la biographie pour %s',
$author_description->getLabel()))
->setUrl($url)
->setImage(Class_Admin_Skin::current()
->renderButtonIconOn('validate', $this->view)));
}
}
\ No newline at end of file
......@@ -171,7 +171,9 @@ class ZendAfi_View_Helper_RenderAuthorDescription extends ZendAfi_View_Helper_Ba
protected function _renderRecord($author_description, $doc_type_id, $records) {
$type_doc = Class_TypeDoc::find($doc_type_id);
if (!$type_doc = Class_TypeDoc::find($doc_type_id))
return '';
$header = $this->_tag('h2', $this->view->tagAnchor(Class_Url::assemble(['controller' => 'recherche',
'action' => 'simple',
'code_rebond' => $author_description->getFacetCode(),
......
......@@ -41,7 +41,9 @@ class Intonation_Library_InaInterviews {
$data = Class_WebService_AllServices::runServiceAfiInterviews($args);
if (!$videos = $data["videos"])
if (!$data
|| !isset($data['videos'])
|| (!$videos = $data["videos"]))
return [];
$interviews = [];
......
......@@ -48,7 +48,10 @@ class Intonation_Library_View_Wrapper_Author extends Intonation_Library_View_Wra
public function getPicture() {
return $this->_model->getThumbnailUrl();
$description = new Class_CodifAuteur_Description($this->_model);
return $description->isBiographyDisabled()
? ''
: $this->_model->getThumbnailUrl();
}
......
......@@ -31,7 +31,9 @@ class Intonation_Library_View_Wrapper_Author_RichContent_Biography extends Inton
if ($this->_content)
return $this->_content;
return $this->_content = $this->_view->Author_RenderWikipedia(new Class_CodifAuteur_Description($this->_model));
$description = new Class_CodifAuteur_Description($this->_model);
return $this->_content = $this->_view->Author_RenderWikipedia($description)
. $this->_view->Author_EditBiographyUrl($description);
}
......
......@@ -22,10 +22,6 @@
class Intonation_View_Author_EditBiographyUrl extends ZendAfi_View_Helper_BaseHelper {
public function Author_EditBiographyUrl($author) {
if (!$records = $author->getRecords())
return '';
return $this->view->biographie_UpdateButton(array_shift($records),
$author->getLabel());
return $author->renderEditButtonOn($this->view);
}
}
......@@ -22,19 +22,25 @@
class Intonation_View_Author_RenderThumbnail extends ZendAfi_View_Helper_BaseHelper {
public function Author_RenderThumbnail($author) {
if ($author->isBiographyDisabled())
return $this->_defaultIco();
$bio = $author->fetchBiography();
return $bio->getvignette()
return ($url = $bio->getvignette())
? $this->_div(['onclick' => '$(this).toggleClass(\'modal_image\');'],
$this->view->tagImg($bio->getvignette(),
$this->view->tagImg($url,
['class' => 'img-thumbnail',
'title' => $this->_('Portrait de %s. Source: Wikipedia',
$author->getLabel()),
'alt' => $this->_('%s. Source: Wikipedia',
$author->getLabel())]))
: Class_Template::current()->getIco($this->view,
'author',
'library',
['class' => 'ico_xl m-0 text-center pt-5']);
: $this->_defaultIco();
}
protected function _defaultIco() {
return Class_Template::current()->getIco($this->view, 'author', 'library',
['class' => 'ico_xl m-0 text-center pt-5']);
}
}
......@@ -42,6 +42,10 @@ abstract class RecordsControllerTestCase extends Admin_AbstractControllerTestCas
'auteur_principal' => 'J.K.Rowling',
'clef_oeuvre' => 'HARRY_POTTER']);
$this->fixture('Class_CodifAuteur',
['id' => 345,
'libelle' => 'J.K.Rowling']);
Class_CosmoVar::newInstanceWithId('url_services')->setValeur('http://cache.org');
Class_WebService_AllServices::setHttpClient($this->_http_client = $this->mock());
......@@ -417,6 +421,86 @@ class RecordsControllerBiographyTest extends RecordsControllerTestCase {