Skip to content
Snippets Groups Projects

Dev#13230 Cvs Tracks

Merged Patrick Barroca requested to merge dev#13230-CVS-tracks into master
Compare and
+ 397
161
Preferences
Compare changes
Files
+ 233
0
<?php
/**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 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).
*
* AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_Notice_TracksReader {
const SOURCE = 'source';
const NB_RESULTATS = 'nb_resultats';
const NOMBRE_VOLUMES = 'nombre_volumes';
const MORCEAUX = 'morceaux';
const TITRE = 'titre';
const URL_ECOUTE = 'url_ecoute';
public static function getTracksOf($record) {
if (0 == count($record->get_subfield('464', '3'))) {
$clazz = null;
if ($record->isGam())
$clazz = 'Class_Notice_TracksReader_Gam';
if ($record->isCvs())
$clazz = 'Class_Notice_TracksReader_Cvs';
if ($clazz)
return (new $clazz($record))->getTracks();
}
return (new Class_Notice_TracksReader_Local($record))->getTracks();
}
public function __construct($record) {
$this->_record = $record;
}
public function getTracks() {
return [static::NB_RESULTATS => 0,
static::NOMBRE_VOLUMES => 0,
static::MORCEAUX => [],
static::SOURCE => $this->getSource()];
}
public function getSource() {
return 'Bibliothèque';
}
}
class Class_Notice_TracksReader_Local extends Class_Notice_TracksReader {
public function getMapping($datas) {
foreach($datas as $data)
if ($this->_record->decoupe_bloc_champ($data)[0]['code'] == 't')
return ['t' => 'titre',
'd' => 'duree',
'a' => 'auteur_nom',
'b' => 'auteur_prenom',
'v' => 'volume',
'3' => 'url_ecoute'];
return ['a' => 'titre',
'd' => 'duree',
'f' => 'auteur_nom',
'g' => 'auteur_prenom',
'v' => 'volume'];
}
public function getTracks() {
$ret = parent::getTracks();
// get zone 464
$datas = array_filter(
$this->_record->get_subfield('464'),
function($champ) {
return false !== $this->_record->decoupe_bloc_champ($champ)[0]['code'];
});
if(!count($datas))
return $ret;
$root_url_ecoute = Class_AdminVar::get('ROOT_URL_ECOUTE');
$mapping = $this->getMapping($datas);
$volume = $piste = 0;
foreach($datas as $champs) {
$champ = $this->_record->decoupe_bloc_champ($champs);
$titre = $auteur_nom = $auteur_prenom = $duree = $volume = $url_ecoute = '';
foreach($champ as $sous_champ)
if (array_key_exists($sous_champ['code'], $mapping))
${$mapping[$sous_champ['code']]} = $sous_champ['valeur'];
if (!$titre)
continue;
if ($auteur_prenom)
$auteur_nom = $auteur_prenom . ' ' . $auteur_nom;
if ($auteur_nom)
$titre .= ' / ' . $auteur_nom;
if ($duree)
$titre .= ' ' . $duree;
$piste++;
if (!$volume)
$volume = 1;
$ret['nb_resultats'] = $piste;
if ($volume > $ret['nombre_volumes'])
$ret['nombre_volumes'] = $volume;
$ret['morceaux'][$volume][$piste]['titre'] = $titre;
if ($url_ecoute)
$ret['morceaux'][$volume][$piste]['url_ecoute'] = $root_url_ecoute . $url_ecoute;
}
return $ret;
}
}
class Class_Notice_TracksReader_ThirdParty extends Class_Notice_TracksReader {
protected $_titles_sources, $_samples_sources = [];
public function getTitles() {
return $this->_getFirstFoundFieldIn($this->_titles_sources);
}
public function getSamples() {
$datas = $this->_getFirstFoundFieldIn($this->_samples_sources);
if (0 == count($datas))
return [];
$ret = [];
$indice = 0;
foreach ($datas as $bloc) {
$ret[$indice] = $this->_record->getValeursBloc($bloc);
$trav = explode('/', $ret[$indice][1]);
$ret[$indice][1] = trim($trav[0]);
$indice++;
}
return $ret;
}
protected function _getFirstFoundFieldIn($possibles) {
$datas = [];
foreach ($possibles as $possible) {
$datas = call_user_func_array([$this->_record, 'get_subfield'], $possible);
if (0 < count($datas))
return $datas;
}
return $datas;
}
public function getTracks() {
$ret = parent::getTracks();
$titles = $this->getTitles();
if(!count($titles))
return $ret;
$samples = $this->getSamples();
$volume = 1;
$piste = 0;
foreach($titles as $title) {
$piste++;
$ret[static::NB_RESULTATS] = $piste;
$ret[static::MORCEAUX][$volume][$piste][static::TITRE] = $title;
if (!$samples)
continue;
foreach($samples as $sample) {
if (trim($title) == trim($sample[1])) {
$ret[static::MORCEAUX][$volume][$piste][static::URL_ECOUTE] = $sample[0];
break;
}
}
}
return $ret;
}
}
class Class_Notice_TracksReader_Gam extends Class_Notice_TracksReader_ThirdParty {
protected $_titles_sources = [['464', 't'], ['464', 'a']];
protected $_samples_sources = [['958'], ['964'], ['985']];
public function getSource() {
return 'GAM Annecy';
}
}
class Class_Notice_TracksReader_Cvs extends Class_Notice_TracksReader_ThirdParty {
protected $_titles_sources = [['464', 't']];
protected $_samples_sources = [['856']];
public function getSource() {
return 'CVS';
}
}
?>
\ No newline at end of file