Skip to content
Snippets Groups Projects

Master

Merged Patrick Barroca requested to merge master into WIP
Compare and
+ 556
384
Preferences
Compare changes
Files
<?PHP
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
@@ -18,308 +18,279 @@
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
//////////////////////////////////////////////////////////////////////////////////////
// CLASSE NOTICE POUR LES ARCHIVES DE ST-CLAUDE HAUT JURA
//////////////////////////////////////////////////////////////////////////////////////
class notice_avenio
{
private $id_profil; // Id du profil de données pour le fichier chargé
private $id_bib; // id bib
private $profil; // Instance du profil pour optimiser
private $indexation; // Instance de la classe d'indexation
private $enreg; // Enreg notice brut
private $champs; // Champs de données découpés
private $warnings; // Erreurs non bloquantes
private $erreur; // Erreur bloquante
private $nb_champs; // nombre de champs attendus
// ----------------------------------------------------------------
// Constructeur
// ----------------------------------------------------------------
function __construct($id_bib)
{
require_once("classe_profil_donnees.php");
require_once("classe_indexation.php");
require_once("Class/Isbn.php");
require_once("classe_unimarc.php");
$this->id_bib=$id_bib;
$this->profil=new profil_donnees();
$this->indexation=new indexation();
}
// ----------------------------------------------------------------
// Initialisation nouvelle notice
// ----------------------------------------------------------------
public function ouvrirNotice($data,$id_profil)
{
// Découper les champs
unset($this->enreg);
if(!$data) return false;
$data=utf8_encode($data);
$this->champs=explode(chr(9),$data);
return true;
}
// ----------------------------------------------------------------
// Rend la structure complète pour l'integration
// ----------------------------------------------------------------
public function getNoticeIntegration()
{
$notice["warnings"]=array();
$notice["statut"] = 0;
$notice["id_origine"]=$this->getIdOrigine();
$notice["type_doc"] = 1;
// supprimer la ligne d'entete
if($notice["id_origine"]=='Num_Inventaire')
{
$this->nb_champs=count($this->champs);
$notice["statut"] = 1;
return $notice;
}
// Isbn /ean
$trav=$this->getIsbn();
if($trav["statut"] == 1) $warnings[]=array("isbn incorrect",$trav["code_brut"]);
else
{
$notice["isbn"] = $trav["isbn"];
$notice["isbn10"] = $trav["isbn10"];
$notice["isbn13"] = $trav["isbn13"];
$notice["ean"]=$trav["ean"];
}
// données principales
$notice["titres"]= $this->getTitres();
$notice["titre_princ"] =$notice["titres"][0];
$notice["auteurs"]=$this->getAuteurs();
$notice["auteurs_renvois"] = array();
$notice["editeur"]=$this->getEditeur();
$notice["lieu_edition"]=$this->getLieuEdition();
$notice["collection"]=$this->getCollection();
$notice["tome_alpha"] = $this->getTome();
$notice["annee"] = $this->getAnnee();
$notice["collation"] = $this->getCollation();
$notice["notes"] = $this->getNotes();
$notice["exportable"] = true;
// clefs d'index
$notice["alpha_titre"]=$this->indexation->codeAlphaTitre($notice["titre_princ"]." ".$notice["tome_alpha"]);
$notice["clef_alpha"]=$this->getClefAlpha($notice);
$notice["clef_oeuvre"]=$this->getClefAlpha($notice,true);
$notice["alpha_auteur"]=$this->indexation->alphaMaj($notice["auteurs"][0]);
// unimarc
$notice["unimarc"] = $this->getUnimarc($notice);
$ex=$this->getExemplaire();
$notice["statut_exemplaires"] = $ex["statut_exemplaires"];
$notice["exemplaires"][0] = $ex["exemplaire"];
return $notice;
}
// ----------------------------------------------------------------
// Exemplaire
// ----------------------------------------------------------------
public function getExemplaire()
{
$ex["code_barres"]=trim('am-'.$this->champs[22]);
$ex["cote"]=trim($this->champs[1]);
$ex["activite"]="à consulter sur place";
if($this->id_bib) $ex['annexe']=$this->id_bib;
$ex["id_origine"]=$this->getIdOrigine();
$ret["exemplaire"]=$ex;
$statut["nb_ex"]=1;
$statut["nb_ex_detruits"]=0;
if(!$ex["code_barres"]) $statut["codes_barres"]=0; else $statut["codes_barres"]=1;
if(!$ex["cote"]) $statut["cotes"]=0; else $statut["cotes"]=1;
$ret["statut_exemplaires"]=$statut;
return $ret;
}
// ----------------------------------------------------------------
// Id origine
// ----------------------------------------------------------------
public function getIdOrigine()
{
return trim($this->champs[22]);
}
// ----------------------------------------------------------------
// Titres
// ----------------------------------------------------------------
public function getTitres()
{
$titres[0]=trim($this->champs[5]);
return $titres;
}
// ----------------------------------------------------------------
// Tome
// ----------------------------------------------------------------
public function getTome()
{
return trim($this->champs[8]);
}
// ----------------------------------------------------------------
// Auteurs
// ----------------------------------------------------------------
public function getAuteurs()
{
$data=$this->champs[0];
if(!$data) return false;
$enregs=explode(" ; ",$data);
foreach($enregs as $enreg)
{
$elems=explode("(",$enreg);
$nom=$elems[0];
$prenom=substr(trim($elems[1],0,(strlen(trim($elems[1]))-1)));
$auteurs[]=$nom . "|" .$prenom;
}
return $auteurs;
}
// ----------------------------------------------------------------
// Editeur
// ----------------------------------------------------------------
public function getEditeur()
{
return trim($this->champs[6]);
}
// ----------------------------------------------------------------
// Lieu d'edition
// ----------------------------------------------------------------
public function getLieuEdition()
{
return trim($this->champs[7]);
}
// ----------------------------------------------------------------
// Collation
// ----------------------------------------------------------------
public function getCollation()
{
return trim($this->champs[4]);
}
// ----------------------------------------------------------------
// Année d'édition
// ----------------------------------------------------------------
public function getAnnee()
{
$data=$this->champs[2];
for($i=0; $i < strlen($data); $i++)
{
$car=substr($data,$i,1);
if($car >="0" And $car <= "9") $annee = $annee .$car;
if(strLen($annee) == 4 ) break;
}
if($annee < "1000" or $annee > "2020") $annee="";
return($annee);
}
// ----------------------------------------------------------------
// Collection
// ----------------------------------------------------------------
public function getCollection()
{
return trim($this->champs[10]);
}
// ----------------------------------------------------------------
// Notes
// ----------------------------------------------------------------
public function getNotes()
{
if(trim($this->champs[19])>'') $notes["300"]=trim($this->champs[19]);
if(trim($this->champs[17])>'') $notes["315"]=trim($this->champs[17]);
return $notes;
}
// ----------------------------------------------------------------
// Isbn
// ----------------------------------------------------------------
public function getIsbn()
{
// Recup du premier
$isbn=trim($this->champs[3]);
if($isbn)
{
$oIsbn=new class_isbn($isbn);
$isbn=$oIsbn->getAll();
}
return $isbn;
}
// ----------------------------------------------------------------
// Unimarc
// ----------------------------------------------------------------
public function getUnimarc($notice)
{
$notice_sgbd=new notice_unimarc();
$zone_100=rendDate($this->champs[26],4)."a|||||||||||y0frey0103####ba";
$notice_sgbd->setNotice("");
$notice_sgbd->set_dt("a");
$notice_sgbd->set_bl("m");
$notice_sgbd->add_field("001","","".$notice["id_origine"]);
if($notice["isbn"]) $notice_sgbd->add_field("010","","a".$notice["isbn"]);
$notice_sgbd->add_field("100"," ","a".$zone_100);
$notice_sgbd->add_field("200","1 ","a".$notice["titre_princ"]);
if($notice["lieu_edition"]) $notice_sgbd->add_field("210","1 ","a".$notice["lieu_edition"]);
if($notice["editeur"]) $notice_sgbd->add_field("210","1 ","c".$notice["editeur"]);
if($notice["annee"]) $notice_sgbd->add_field("210","1 ","d".$notice["annee"]);
if($notice["collation"]) $notice_sgbd->add_field("215"," ","a".$notice["collation"]);
if($notice["collection"]) $notice_sgbd->add_field("225"," ","a".$notice["collection"]);
if($notice["notes"])
{
foreach($notice["notes"] as $key=>$valeur)
{
$notice_sgbd->add_field($key,"1 ","a".$valeur);
}
}
if($notice["auteurs"])
{
foreach($notice["auteurs"] as $auteur)
{
if(!trim($auteur)) continue;
$elems=explode("|",$auteur);
$notice_sgbd->add_field("700","1 ","a".trim($elems[0]." ".trim($elems[1])));
}
}
$unimarc=$notice_sgbd->update();
return $unimarc;
}
// ----------------------------------------------------------------
// Rend la clef alpha
// ----------------------------------------------------------------
public function getClefAlpha($notice,$oeuvre=false)
{
$type_doc=$notice["type_doc"];
$titre=$notice["titre_princ"];
$complement_titre="";
$auteur=$notice["auteurs"][0];
$editeur=$notice["editeur"];
$annee=$notice["annee"];
$tome=$notice["tome_alpha"];
if($oeuvre==true) $clef_alpha=$this->indexation->getClefOeuvre($titre,$complement_titre,$auteur,$tome);
else $clef_alpha=$this->indexation->getClefAlpha($type_doc,$titre,$complement_titre,$auteur,$tome,$editeur,$annee);
return $clef_alpha;
}
// ----------------------------------------------------------------
// Rend la derniere erreur bloquante
// ----------------------------------------------------------------
public function getLastError()
{
return $this->erreur;
}
}
?>
\ No newline at end of file
require_once 'classe_indexation.php';
require_once 'Class/Isbn.php';
require_once 'classe_unimarc.php';
/**
* Format spécifique Archives de St-Claude Haut Jura
*/
class notice_avenio {
const CELLS_COUNT = 33;
private $id_bib; // id bib
private $indexation; // Instance de la classe d'indexation
private $enreg; // Enreg notice brut
private $champs; // Champs de données découpés
private $warnings; // Erreurs non bloquantes
private $erreur; // Erreur bloquante
public function __construct($id_bib) {
$this->id_bib = $id_bib;
$this->indexation = new indexation();
}
public function ouvrirNotice($data, $id_profil) {
unset($this->enreg);
if (!$data)
return false;
$this->champs = $data;
return true;
}
public function getNoticeIntegration() {
$notice['warnings']= [];
$notice['statut'] = 0;
$notice['id_origine'] = $this->getIdOrigine();
$notice['type_doc'] = 1;
// supprimer la ligne d'entete
if ($notice['id_origine'] == 'Num_Inventaire') {
$notice['statut'] = 1;
return $notice;
}
// si pas assez de colonnes
if (count($this->champs) != static::CELLS_COUNT) {
$notice['statut'] = 1;
return $notice;
}
// Isbn /ean
$trav = $this->getIsbn();
if ($trav['statut'] == 1)
$warnings[] = ['isbn incorrect', $trav['code_brut']];
else {
$notice['isbn'] = $trav['isbn'];
$notice['isbn10'] = $trav['isbn10'];
$notice['isbn13'] = $trav['isbn13'];
$notice['ean'] = $trav['ean'];
}
// données principales
$notice['titres'] = $this->getTitres();
$notice['titre_princ'] = $notice['titres'][0];
$notice['auteurs'] = $this->getAuteurs();
$notice['auteurs_renvois'] = [];
$notice['editeur'] = $this->getEditeur();
$notice['lieu_edition'] = $this->getLieuEdition();
$notice['collection'] = $this->getCollection();
$notice['tome_alpha'] = $this->getTome();
$notice['annee'] = $this->getAnnee();
$notice['collation'] = $this->getCollation();
$notice['notes'] = $this->getNotes();
$notice['exportable'] = true;
// clefs d'index
$notice['alpha_titre'] = $this->indexation->codeAlphaTitre($notice['titre_princ'].' '.$notice['tome_alpha']);
$notice['clef_alpha'] = $this->getClefAlpha($notice);
$notice['clef_oeuvre'] = $this->getClefAlpha($notice,true);
$notice['alpha_auteur'] = $this->indexation->alphaMaj($notice['auteurs'][0]);
// unimarc
$notice['unimarc'] = $this->getUnimarc($notice);
$ex = $this->getExemplaire();
$notice['statut_exemplaires'] = $ex['statut_exemplaires'];
$notice['exemplaires'][0] = $ex['exemplaire'];
$notice['clef_chapeau'] = '';
$notice['id_commerciale'] = '';
$notice['cote'] = '';
return $notice;
}
public function getExemplaire() {
$ex['code_barres'] = trim('am-' . $this->champs[22]);
$ex['cote'] = trim($this->champs[1]);
$ex['activite'] = 'à consulter sur place';
if ($this->id_bib)
$ex['annexe'] = $this->id_bib;
$ex['id_origine'] = $this->getIdOrigine();
$ret['exemplaire'] = $ex;
$statut['nb_ex'] = 1;
$statut['nb_ex_detruits'] = 0;
$statut['codes_barres'] = (!$ex['code_barres']) ? 0 : 1;
$statut['cotes'] = (!$ex['cote']) ? 0 : 1;
$ret['statut_exemplaires'] = $statut;
return $ret;
}
public function getIdOrigine() {
return trim($this->champs[22]);
}
public function getTitres() {
$titres[0] = trim($this->champs[5]);
return $titres;
}
public function getTome() {
return trim($this->champs[8]);
}
public function getAuteurs() {
$data = $this->champs[0];
if (!$data)
return false;
$enregs = explode(' ; ', $data);
foreach($enregs as $enreg) {
$elems = explode('(', $enreg);
array_walk($elems,
function(&$value) { $value = trim($value); });
$nom = $elems[0];
$prenom = trim(substr($elems[1], 0, strlen($elems[1]) - 1));
$auteurs[] = $nom . '|' . $prenom;
}
return $auteurs;
}
public function getEditeur() {
return trim($this->champs[6]);
}
public function getLieuEdition() {
return trim($this->champs[7]);
}
public function getCollation() {
return trim($this->champs[4]);
}
public function getAnnee() {
$data = $this->champs[2];
for ($i=0; $i < strlen($data); $i++) {
$car = substr($data,$i,1);
if ($car >= '0' and $car <= '9')
$annee = $annee . $car;
if (strLen($annee) == 4)
break;
}
if ($annee < '1000' or $annee > '2020')
$annee = '';
return($annee);
}
public function getCollection(){
return trim($this->champs[10]);
}
public function getNotes() {
if (trim($this->champs[19]) > '')
$notes['300'] = trim($this->champs[19]);
if (trim($this->champs[17]) > '')
$notes['315'] = trim($this->champs[17]);
return $notes;
}
public function getIsbn() {
// Recup du premier
$isbn = trim($this->champs[3]);
if ($isbn) {
$oIsbn = new class_isbn($isbn);
$isbn = $oIsbn->getAll();
}
return $isbn;
}
public function getUnimarc($notice) {
$notice_sgbd = new notice_unimarc();
$zone_100 = rendDate($this->champs[26],4).'a|||||||||||y0frey0103####ba';
$notice_sgbd->setNotice('');
$notice_sgbd->set_dt('a');
$notice_sgbd->set_bl('m');
$notice_sgbd->add_field('001','',''.$notice['id_origine']);
if ($notice['isbn'])
$notice_sgbd->add_field('010','','a'.$notice['isbn']);
$notice_sgbd->add_field('100',' ','a'.$zone_100);
$notice_sgbd->add_field('200','1 ','a'.$notice['titre_princ']);
if ($notice['lieu_edition'])
$notice_sgbd->add_field('210','1 ','a'.$notice['lieu_edition']);
if ($notice['editeur'])
$notice_sgbd->add_field('210','1 ','c'.$notice['editeur']);
if ($notice['annee'])
$notice_sgbd->add_field('210','1 ','d'.$notice['annee']);
if ($notice['collation'])
$notice_sgbd->add_field('215',' ','a'.$notice['collation']);
if ($notice['collection'])
$notice_sgbd->add_field('225',' ','a'.$notice['collection']);
if ($notice['notes']) {
foreach($notice['notes'] as $key=>$valeur) {
$notice_sgbd->add_field($key,'1 ','a'.$valeur);
}
}
if($notice['auteurs']) {
foreach($notice['auteurs'] as $auteur) {
if(!trim($auteur))
continue;
$elems=explode('|',$auteur);
$notice_sgbd->add_field('700','1 ','a'.trim($elems[0].' '.trim($elems[1])));
}
}
$unimarc = $notice_sgbd->update();
return $unimarc;
}
public function getClefAlpha($notice, $oeuvre=false) {
$type_doc = $notice['type_doc'];
$titre = $notice['titre_princ'];
$complement_titre = '';
$auteur = $notice['auteurs'][0];
$editeur = $notice['editeur'];
$annee = $notice['annee'];
$tome = $notice['tome_alpha'];
return $oeuvre
? $this->indexation->getClefOeuvre($titre, $complement_titre, $auteur, $tome)
: $this->indexation->getClefAlpha($type_doc, $titre, $complement_titre, $auteur, $tome, $editeur, $annee);
}
public function getLastError() {
return $this->erreur;
}
}
\ No newline at end of file