Commit d4fcf5a5 authored by Sebastien ANDRE's avatar Sebastien ANDRE
Browse files

Merge branch...

Merge branch 'hotline#118591_soucis_avec_l_affichage_des_auteurs_principaux_entete_bokeh' into 'master'

hotline#118591 : extract load all authors from Notice

See merge request afi/opacce!4134
parents 451c59a3 cfddb493
- ticket #118591 : Vue Notice : Les liens de rebond, pour certains auteurs principaux avec un deuxième prénom constitué d'une seule lettre, ne fonctionnait pas
\ No newline at end of file
......@@ -176,11 +176,11 @@ class Class_Album extends Storm_Model_Abstract {
/** @var Class_Upload */
protected $_uploadHandler = [];
protected $_marc;
protected $path_flash;
protected $_date_maj_enabled = true;
protected
$_marc,
$path_flash,
$_date_maj_enabled = true,
$_authors;
public function __construct() {
......@@ -1571,43 +1571,20 @@ class Class_Album extends Storm_Model_Abstract {
}
/**
* Main author
* @return string
*/
public function getMainAuthorName() {
if (!$authors = $this->getAuthors())
return '';
return array_shift($authors)->getName();
return ($main_author = $this->_initAuthors()->getAuthorPrincipal())
? $main_author
: '';
}
/**
* Author names from unimarc container
* @return array
*/
public function getAuthorsNames() {
$names = [];
foreach($this->getAuthors() as $author)
$names []= $author->getName();
return $names;
return $this->_initAuthors()->getAllAuthors();
}
/**
* Author from unimarc container
* @return array
*/
public function getAuthors() {
$authors = [];
foreach ($this->getMarc()->getDatasOfField(self::AUTHOR_FIELD) as $item) {
if (!isset($item['a']))
continue;
$authors []= new Class_Notice_Author($item['a'],
isset($item['4']) ? $item['4'] : '');
}
return $authors;
return $this->_initAuthors()->getArrayAuthors();
}
......@@ -1617,35 +1594,10 @@ class Class_Album extends Storm_Model_Abstract {
* @param function string
*/
public function addAuthor($author, $responsibility = '') {
if (!$author)
return $this;
if (is_string($author))
$author = new Class_Notice_Author($author, $responsibility);
$datas = ['a' => $author->getName()];
if ($author->getResponsibility())
$datas['4'] = $author->getResponsibility();
if (!in_array($author->getName(), $this->getAuthorsNames())) {
$this->getMarc()->addZone(self::AUTHOR_FIELD, $datas);
return $this;
}
if (!$author->getResponsibility())
return $this;
$found = false;
foreach($this->getAuthors() as $other) {
if ($author->getName() == $other->getName() && $author->getResponsibility() == $other->getResponsibility()) {
$found = true;
break;
}
}
if (!$found)
$this->getMarc()->addZone(self::AUTHOR_FIELD, $datas);
if ($author = $this->_initAuthors()
->addAuthorOrLabel($author, $responsibility))
$this->getMarc()
->addZone(static::AUTHOR_FIELD, $this->_getDatasFromAuthor($author));
return $this;
}
......@@ -1747,4 +1699,20 @@ class Class_Album extends Storm_Model_Abstract {
public function getRootCategoryId() {
return $this->getRootCategory()->getId();
}
protected function _initAuthors() {
return $this->_authors
? $this->_authors
: ($this->_authors = new Class_Album_Authors($this));
}
protected function _getDatasFromAuthor($author) {
$datas = ['a' => $author->getName()];
if ($author->getResponsibility())
$datas['4'] = $author->getResponsibility();
return $datas;
}
}
<?php
/**
* Copyright (c) 2012-2021, 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 Class_Album_Authors extends Class_Authors {
protected $_zones = '701';
public function addAuthorOrLabel($author, $responsibility = '') {
if (!$author)
return null;
if (is_string($author))
$author = new Class_Notice_Author($author, $responsibility);
return $this->addAuthor($author);
}
public function getAllAuthors() {
if ($this->_authors->isEmpty())
return [];
return $this->_authors
->collect(function ($author)
{
return $author->getLabelForAlbum();
})
->reject(function ($label)
{
return !$label;
})
->getArrayCopy();
}
protected function _init($album) {
foreach ($album->getMarc()->getDatasOfField($this->_zones) as $item)
$this->_initAuthor($item);
return $this;
}
protected function _initAuthor($item) {
if (!isset($item['a']))
return $this;
$author = new Class_Notice_Author('');
$author->setZone('701');
$author->visitAuthor('a', $item['a']);
if (isset($item['4']))
$author->visitAuthor('4', $item['4']);
$this->_authors->add($author);
return $this;
}
}
......@@ -286,14 +286,9 @@ class Class_AlbumCategorie_EadGallicaVisitor_AlbumWrapper {
protected function _initAuthors() {
if (!$authors = $this->_record->getAuteursUnimarc(false, true))
return $this->_album->getAuthors();
return array_map(function($author)
{
return new Class_Notice_Author($author->getAuthorName(), $author->getFonction());
},
$authors);
return ($authors = $this->_record->getArrayAuthors())
? $authors
: $this->_album->getAuthors();
}
......@@ -405,4 +400,4 @@ class Class_AlbumCategorie_EadGallicaVisitor_AlbumWrapper {
public function acceptEadVisitor($visitor) {
return $this->_album->acceptEadVisitor($visitor);
}
}
\ No newline at end of file
}
<?php
/**
* Copyright (c) 2012-2021, 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
*/
abstract class Class_Authors {
protected $_authors;
public function __construct($record) {
$this->_authors = new Storm_Collection();
$this->_init($record);
}
public function getAuthorPrincipal() {
return $this->_getPrincipalWith(function ($author)
{
return $author->getName();
});
}
public function getCodifAuthorPrincipal() {
return $this->_getPrincipalWith(function ($author)
{
return $author->getCodifAuthor();
});
}
public function getArrayAuthors() {
if ($this->_authors->isEmpty())
return [];
return $this->_authors->getArrayCopy();
}
public function getAllAuthorsFromZones($zones) {
if ($this->_authors->isEmpty())
return [];
return $this->_authors
->select(function ($author) use ($zones)
{
return in_array($author->getZone(), $zones);
})
->collect(function ($author)
{
return $author->getLabel();
})
->reject(function ($label)
{
return !$label;
})
->getArrayCopy();
}
public function addAuthor($author) {
$existing = $this->_authors
->detect(function ($current) use ($author)
{
if ($author->getName() !== $current->getName())
return false;
if (!$author->getResponsibility())
return true;
return $author->getResponsibility() === $current->getResponsibility();
});
if (!$existing) {
$this->_authors->add($author);
return $author;
}
return null;
}
protected function _getPrincipalWith($callback) {
return ($author = $this->_authors->first())
? $callback($author)
: null;
}
abstract protected function _init($record);
}
......@@ -16,21 +16,20 @@
*
* 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 Class_Autocomplete_IndexTitle extends Class_Autocomplete_Index {
use Trait_Translator;
protected $file_name = 'titles';
protected $model_name='Class_Notice';
protected $file_name = 'titles';
protected $model_name = 'Class_Notice';
protected function getRecordData($record) {
$author = $record->getFirstAuthor() ;
if ($author)
$author = $this->_(' de ') .$author;
if ($author = $record->getFirstAuthor())
$author = $this->_(' de ') . $author;
return str_replace('<br />', ': ', $record->getTitrePrincipal() . $author);
}
}
?>
\ No newline at end of file
......@@ -227,7 +227,7 @@ class CodifAuteurLoader extends Storm_Model_Loader {
public function findAllIdsByResponsibilitiesLabelsFromRecord($record, $responsibilities_labels) {
$authors = array_filter($record->getAuteursUnimarc(false, true),
$authors = array_filter($record->getAllAuthorsWithResponsibility(),
function($author) use ($responsibilities_labels)
{
......@@ -305,4 +305,4 @@ class Class_CodifAuteur extends Storm_Model_Abstract {
&&
(false == strpos($this->getThumbnailUrl(), 'Defaut.svg'));
}
}
\ No newline at end of file
}
......@@ -136,7 +136,7 @@ class Class_Cosmogramme_Integration_PhaseSerialArticlesIndex
protected function _handleAuthors($record, $issue, $facets) {
$authors = $record->getAuteursUnimarc();
$authors = $record->getAllAuthors();
foreach($authors as $author)
$this->_injectCodifFacetIn($author, '_getCodifAuthorFor', $facets);
......
......@@ -24,50 +24,6 @@ class Class_Migration_ArteVODAuthorsOrder {
use Trait_MemoryCleaner;
public function updateAuthorsForAllAlbums($closure=null) {
try {
$page = 0;
while($albums = Class_Album::findAllBy(['type_doc_id' => Class_TypeDoc::ARTEVOD,
'order' => 'id',
'limitPage' => [$page, 500]])) {
$this->_runPage($albums, $closure);
$this->_cleanMemory();
$page++;
}
} catch(Exception $e) {
return;
}
}
protected function _runPage($albums, $closure) {
foreach($albums as $album) {
$this->updateAuthors($album);
if ($closure)
$closure($album);
}
}
public function updateAuthors($album) {
$old_authors = new Storm_Collection($album->getAuthors());
$album->getMarc()->clearZone('701');
$this->addAuthorsTo($old_authors, function($author)
{
return $author->getResponsibility()=='300';
}, $album);
$this->addAuthorsTo($old_authors, function($author)
{
return $author->getResponsibility()!='300';
}, $album);
$album->index();
}
protected function addAuthorsTo($authors, $closure, $album) {
$authors->select($closure)
->eachDo(function ($author) use ($album)
{
$album->addAuthor($author);
}) ;
// Obsolète
}
}
......@@ -230,7 +230,8 @@ class Class_Notice extends Storm_Model_Abstract {
$_data_map,
$_collation,
$_main_author_cache,
$_same_serie_records;
$_same_serie_records,
$_authors;
protected $_default_attribute_values = ['type_doc' => 0,
'annee' => null,
......@@ -740,8 +741,8 @@ class Class_Notice extends Storm_Model_Abstract {
if ($complement = $serial_article->getComplementTitre())
$article["titre"] .= " : " . $complement;
$auteurs = $serial_article->getAuteursUnimarc(true);
$article["auteur"] = isset($auteurs[0]) ? $auteurs[0] : '';
$auteur = $serial_article->getFirstAuthor();
$article["auteur"] = $auteur;
$article["pagination"] = $serial_article->getCollation();
$note = $data = $serial_article->get_subfield("300", "a");
$article["note"] = isset($note[0]) ? trim($note[0]) : '';
......@@ -1136,219 +1137,72 @@ class Class_Notice extends Storm_Model_Abstract {
public function getAuteurPrincipal() {
if (!isset($this->_auteur_principal)) {
$this->_auteur_principal = '';
if (!$this->_auteur_principal=$this->getFirstAuthor()){
if ($data = $this->get_subfield("200", "f"))
$this->_auteur_principal = $data[0];
}
}
if (isset($this->_auteur_principal))
return $this->_auteur_principal;
return $this->_auteur_principal;
}
$this->_auteur_principal = $this->getFirstAuthor();
if (!$this->_auteur_principal
&& $data = $this->get_subfield('200', 'f'))
$this->_auteur_principal = $data[0];
if (!$this->_auteur_principal)
$this->_auteur_principal = '';
public function getFirstAuthor() {
if (!$auteurs = $this->getAuteursUnimarc(true))
return '';
return $auteurs[0];
return $this->_auteur_principal;
}
public function setAuteurPrincipal($auteur) {
$this->_auteur_principal = $auteur;
return $this;
public function getCodifAuthorPrincipal() {
return $this->_initAuthors()->getCodifAuthorPrincipal();
}
public function getUnimarcZone($zone) {
return $this->get_subfield($zone);
public function getFirstAuthor() {
return $this->_initAuthors()->getAuthorPrincipal();
}
public function getAuteursUnimarc($auteurPrincipal = false, $getFonction = false) {
$indexation = Class_Indexation::getInstance();
$auteurs = [];
$zones = ['700', '710', '720', '730', '701', '702', '711', '712', '721', '722'];
foreach ($zones as $zone) {
if ($auteurPrincipal
&& $auteur = $this->_getPremierAuteurDansZone($zone, $indexation))
return [$auteur];
$auteurs = array_merge($auteurs, $this->_getAuteursDansZone($zone, $indexation, $getFonction));
}
// Si fonctions on constitue une nouvelle matrice détaillée
if ($getFonction and 0 < count($auteurs))
return $this->_getAuteursAvecFonctions($auteurs);
return $auteurs;
public function getAllAuthors() {
return $this->_initAuthors()->getAllAuthors(false);
}
/**
* @param $zone string
* @param $indexation Class_Indexation
* @return string
*/
protected function _getPremierAuteurDansZone($zone, $indexation) {
$data = $this->get_subfield($zone);
foreach ($data as $items) {
$auteur = $this->_getAuteurDansSousChamps($this->decoupe_bloc_champ($items));
$libelle = $auteur->nom . '|' . $auteur->prenom;
if ($this->_isAuteurDansZoneValide($libelle, $indexation)) {
return trim($auteur->prenom . ' ' . $auteur->nom);
}
}
return '';
public function getAllAuthorsWithResponsibility() {
return $this->_initAuthors()->getAllAuthors(true);
}
/**
* @param $zone string
* @param $indexation Class_Indexation
* @param $avec_fonction boolean
* @return array
*/
protected function _getAuteursDansZone($zone, $indexation, $avec_fonction = false) {
$auteurs = [];
$data = $this->get_subfield($zone);
foreach ($data as $items) {
$libelle = $this->_getAuteurDansZone($items, $avec_fonction);
if ($this->_isAuteurDansZoneValide($libelle, $indexation)) {
$auteurs[] = $libelle;
}
}
return $auteurs;
public function getAllAuthorsFromZones($zones) {
return $this->_initAuthors()->getAllAuthorsFromZones($zones);
}
protected function getNatureDocs() {
return $this->get_subfield('200','b');
public function getArrayAuthors() {
return $this->_initAuthors()->getArrayAuthors();
}
/**
* @param $data array
* @param $indexation Class_Indexation
* @param $avec_fonction boolean
* @return string
*/
protected function _getAuteurDansZone($data, $avec_fonction = false) {
$auteur = $this->_getAuteurDansSousChamps($this->decoupe_bloc_champ($data), $avec_fonction);
$libelle = $auteur->nom . '|' . $auteur->prenom;
if ($avec_fonction)
$libelle .= '|' . $auteur->fonction . '|' . $auteur->fonction_pergame;
return $libelle;
}
/**
* @param $auteur string