-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.MarcTemplate.php
85 lines (75 loc) · 2.07 KB
/
class.MarcTemplate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
require_once 'File/MARC.php';
require_once 'File/MARC/Record.php';
require_once 'File/MARC/Data_Field.php';
require_once 'File/MARC/Control_Field.php';
require_once 'File/MARC/Subfield.php';
class MarcTemplate {
private $template;
/*
* Constructeur
*
* @param array template of datas
*/
public function __construct( $template ){
$this->template = $template;
}
/**
* Traitement des données
*
* @param string $datas les données suivant le template
* @return array of File_MARC_Record
*/
public function spell( $datas ){
$records = array();
foreach($datas as $data){
$record = new File_MARC_Record();
foreach($this->template as $fieldname => $fieldinfos){
if(isset($data[$fieldname])){
$record->appendField( $this->_field( $fieldinfos, $data[$fieldname] ) );
}
}
$records[] = $record;
}
return $records;
}
/**
* Construction d'un champ
*
* @param array les informations d'un champ provenant du templates
* @param array les données correspondant au champ
* @return File_MARC_Data_Field Contenant les données du champ
*/
private function _field( $fieldinfos, $data ){
if(is_array($fieldinfos)){
foreach( $fieldinfos as $fieldnumber => $subfieldsinfos ){
$subfields = array();
foreach($subfieldsinfos as $subfield => $subfieldname){
if(isset($data[$subfieldname])){
if(is_array($data[$subfieldname])){
foreach($data[$subfieldname] as $subfielddata){
$subfields[] = $this->_subfield( $subfield, $subfielddata );
}
}else{
$subfields[] = $this->_subfield( $subfield, $data[$subfieldname] );
}
}
}
return new File_MARC_Data_Field( $fieldnumber, $subfields );
}
}else{
return new File_MARC_Control_Field($fieldinfos, $data);
}
}
/**
* Construction d'un sous-champ
*
* @param string tag du sous-champ
* @param string les données à intégrer au sous-champ
* @return File_MARC_Subfield
*/
private function _subfield( $subfield, $data ){
return new File_MARC_Subfield($subfield, trim(html_entity_decode($data)));
}
}
?>