function extractISBNNumber( $isbnNr = false, &$error ) { $ini = eZINI::instance( 'content.ini' ); $ean = preg_replace( "/[\s|\-]+/", "", $isbnNr ); if ( is_numeric( $ean ) and strlen( $ean ) == self::LENGTH ) { $prefix = substr( $ean, 0, self::PREFIX_LENGTH ); $this->Prefix = $prefix; $checkDigit = substr( $ean, 12, self::CHECK_LENGTH ); $this->CheckDigit = $checkDigit; if ( $prefix == self::PREFIX_978 ) { $registrantValue = false; $groupValue = false; $publicationValue = false; $checkDigit = false; $groupRange = eZISBNGroupRange::extractGroup( $ean ); $groupLength = false; if ( $groupRange ) { $groupLength = $groupRange->attribute( 'group_length' ); } if ( $groupLength ) { $groupValue = substr( $ean, self::PREFIX_LENGTH, $groupLength ); $this->RegistrationGroup = $groupValue; $group = eZISBNGroup::fetchByGroup( $groupValue ); if ( $group instanceof eZISBNGroup ) { $registrant = eZISBNRegistrantRange::extractRegistrant( $ean, $group, $groupRange, $registrantLength ); if ( $registrant instanceof eZISBNRegistrantRange and $registrantLength > 0 ) { $registrantOffset = self::PREFIX_LENGTH + $groupLength; $registrantValue = substr( $ean, $registrantOffset, $registrantLength ); $this->RegistrantElement = $registrantValue; $publicationOffset = $registrantOffset + $registrantLength; $publicationLength = 12 - $publicationOffset; $publicationValue = substr( $ean, $publicationOffset, $publicationLength ); $this->PublicationElement = $publicationValue; } else { $strictValidation = $ini->variable( 'ISBNSettings', 'StrictValidation' ); if ( $strictValidation == 'true' ) { $error = ezpI18n::tr( 'kernel/classes/datatypes', 'The registrant element of the ISBN number does not exist.' ); return false; } } } else { $strictValidation = $ini->variable( 'ISBNSettings', 'StrictValidation' ); if ( $strictValidation == 'true' ) { $error = ezpI18n::tr( 'kernel/classes/datatypes', 'The ISBN number has a incorrect registration group number.' ); return false; } } } else { $strictValidation = $ini->variable( 'ISBNSettings', 'StrictValidation' ); if ( $strictValidation == 'true' ) { $error = ezpI18n::tr( 'kernel/classes/datatypes', 'The group element of the ISBN number does not exist.' ); return false; } } } else { $strictValidation = $ini->variable( 'ISBNSettings', 'StrictValidation' ); if ( $strictValidation == 'true' ) { $error = ezpI18n::tr( 'kernel/classes/datatypes', '%1 is not a valid prefix of the ISBN number.', null, array( $prefix ) ); return false; } } } else { $error = ezpI18n::tr( 'kernel/classes/datatypes', 'All ISBN 13 characters need to be numeric' ); return false; } return true; }
static function cleanAll() { $db = eZDB::instance(); $definition = eZISBNGroupRange::definition(); $table = $definition['name']; $sql = "TRUNCATE TABLE " . $table; $db->query($sql); }
foreach ($rules as $rule) { $length = (int) $rule->Length; // if length is 0 there is no need to add to the database if ($length > 0) { $rangeArray = explode('-', $rule->Range); $fromValue = substr($rangeArray[0], 0, 5); $toValue = substr($rangeArray[1], 0, 5); $registrantFrom = substr($rangeArray[0], 0, $length); $registrantTo = substr($rangeArray[1], 0, $length); $registrationGroup = eZISBNRegistrantRange::create($isbnGroupID, $fromValue, $toValue, $registrantFrom, $registrantTo, $length); $registrationGroup->store(); } } } // get group ranges $groupRanges = $xml->xpath('///EAN.UCC/Rules/Rule'); foreach ($groupRanges as $groupRange) { $registrationGroupItemLength = (int) $groupRange->Length; // if length is 0 there is no need to add to the database if ($registrationGroupItemLength > 0) { $rangeArray = explode('-', $groupRange->Range); $fromValue = substr($rangeArray[0], 0, 5); $toValue = substr($rangeArray[1], 0, 5); $groupFrom = substr($rangeArray[0], 0, $registrationGroupItemLength); $groupTo = substr($rangeArray[1], 0, $registrationGroupItemLength); $registrationGroupRange = eZISBNGroupRange::create($fromValue, $toValue, $groupFrom, $groupTo, $registrationGroupItemLength); $registrationGroupRange->store(); } } $cli->output('Complete'); $script->shutdown();
function cleanDBDataBeforeImport() { eZISBNGroup::cleanAll(); eZISBNGroupRange::cleanAll(); eZISBNRegistrantRange::cleanAll(); return true; }