Commit 71a1a083 authored by Zéfling's avatar Zéfling 🎨

Script de mise à jour de la base

Génère le code pour mettre à jour "isbn_map.php"
parent a66285a9
<?php
// chemin du ficher XML repris sur https://www.isbn-international.org/range_file_generation
$file = 'isbn13/RangeMessage.xml';
if (file_exists($file)) {
$xml = simplexml_load_file($file);
echo "<?php
/* ***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the \"License\"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an \"AS IS\" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is : EAN13.
The Initial Developer of the Original Code is Zéfling.
Portions created by the Initial Developer are Copyright (C) 2014
the Initial Developer. All Rights Reserved.
Contributor(s):
- Zéfling
***** END LICENSE BLOCK ***** */
/*
* Conversion PHP du tableau pour les tirets
*
* Source : <br>
* Generated from RangeMessage.xml with isbn13_xml2php.php <br>
* Available from https://www.isbn-international.org/range_file_generation <br>
* MessageDate => ${$xml['MessageDate']} <br>
* MessageSerialNumber=> ${$xml['MessageSerialNumber']}
*/
/**
* Liste des groupes ISBN
* @author Zéfling (2019 - http://ikilote.net/fr/Blog/Techno-magis.html)
* @version 2019-12-25
*/
final class ISBN_Map {
public static \$groups_length = [\n";
// UCC
if(isset($xml->{'EAN.UCCPrefixes'}->{'EAN.UCC'})) {
$ucc = $xml->{'EAN.UCCPrefixes'}->{'EAN.UCC'};
$ucc_count = count( $ucc );
$list = [];
for($i = 0; $i < $ucc_count; $i++) {
$groups = [];
$rules = $ucc[$i]->Rules->Rule;
$rules_count = count( $rules );
for($j = 0; $j < $rules_count; $j++) {
list($min_str, $max_str) = explode('-', $rules[$j]->Range);
$length = $rules[$j]->Length;
$groups[] = [
min => intval($min_str),
max => intval($max_str),
length => each($rules[$j]->Length)['value'],
];
}
usort($groups, function ($a, $b) {
return $a['max'] <=> $b['max'];
});
$list[each($ucc[$i]->Prefix)['value']] = $groups;
}
krsort($list);
$i = 0;
$i_count = count( $list );
foreach($list as $prefix => $groups) {
echo " {$prefix} => [\n";
$j = 0;
$j_count = count( $groups );
foreach($groups as $group) {
echo " [
'max' => ${group['max']},
'length' => ${group['length']},
'min' => ${group['min']}
]";
echo $j++ !== $j_count - 1 ? ",\n" : "\n";
}
echo $i++ !== $i_count - 1 ? " ],\n" : " ]\n";
}
}
// Registration Groups
echo " ];
public static \$publisher_length = [\n";
if(isset($xml->RegistrationGroups->Group)) {
$group = $xml->RegistrationGroups->Group;
$group_count = count( $group );
$list = [];
for($i = 0; $i < $group_count; $i++) {
$groups = [];
$rules = $group[$i]->Rules->Rule;
$rules_count = count( $rules );
for($j = 0; $j < $rules_count; $j++) {
list($min_str, $max_str) = explode('-', $rules[$j]->Range);
$length = $rules[$j]->Length;
$groups[] = [
min => intval($min_str),
max => intval($max_str),
length => each($rules[$j]->Length)['value'],
];
}
usort($groups, function ($a, $b) {
return $a['max'] <=> $b['max'];
});
$list[each($group[$i]->Prefix)['value']] = $groups;
}
krsort($list);
$i = 0;
$i_count = count( $list );
foreach($list as $prefix => $groups) {
echo " '{$prefix}' => [\n";
$j = 0;
$j_count = count( $groups );
foreach($groups as $group) {
echo " [
'max' => ${group['max']},
'length' => ${group['length']},
'min' => ${group['min']}
]";
echo $j !== $rules_count - 1 ? ",\n" : "\n";
}
echo $i !== $group_count - 1 ? " ],\n" : " ]\n";
}
}
}
echo ' ];
}';
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment