static function cleanAll()
 {
     $db = eZDB::instance();
     $definition = eZISBNGroup::definition();
     $table = $definition['name'];
     $sql = "TRUNCATE TABLE " . $table;
     $db->query($sql);
 }
예제 #2
0
    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;
    }
    $script->shutdown(1);
}
// Clean up all tables to add everything from the start.
eZISBNGroup::cleanAll();
eZISBNGroupRange::cleanAll();
eZISBNRegistrantRange::cleanAll();
// Get registration groups.
$registrationGroups = $xml->xpath('RegistrationGroups/Group');
foreach ($registrationGroups as $group) {
    // Prefix is always 978 or 979 followed by an hyphen (-) and up to 5 digits
    // Explode it in order to get the group number
    $prefixArray = explode('-', $group->Prefix);
    $groupNumber = $prefixArray[1];
    $description = $group->Agency;
    // name
    $isbnGroup = eZISBNGroup::create($groupNumber, $description);
    $isbnGroup->store();
    $isbnGroupID = $isbnGroup->attribute('id');
    // look for the rules
    $rules = $group->Rules[0]->Rule;
    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();
예제 #4
0
 function cleanDBDataBeforeImport()
 {
     eZISBNGroup::cleanAll();
     eZISBNGroupRange::cleanAll();
     eZISBNRegistrantRange::cleanAll();
     return true;
 }
예제 #5
0
                $added = true;
            }
            if ($isbnRegGroupElementTo + 1 == $fromTestValue) {
                $registrationGroupArray[$length][$i]['from'] = $isbnRegGroupElementFrom;
                $added = true;
            }
        }
        // Since the range is not found as a continued range from the other ranges, so
        // create a new one.
        if ($added == false) {
            $registrationGroupArray[$length][] = array('from' => $isbnRegGroupElementFrom, 'to' => $isbnRegGroupElementTo);
        }
    } else {
        $registrationGroupArray[$length][] = array('from' => $isbnRegGroupElementFrom, 'to' => $isbnRegGroupElementTo);
    }
    $isbnGroup = eZISBNGroup::create($isbnRegGroupElement, $isbnItem['text']);
    $isbnGroup->store();
    $isbnGroupID = $isbnGroup->attribute('id');
    $pubRangeArray = $isbnItem['pubrange'];
    if (is_array($pubRangeArray)) {
        foreach ($pubRangeArray as $isbnRegistrantRange) {
            // The test number should have a base with 5 digits where from should be padded with 0 and
            // to should be padded with 9.
            $fromValue = (int) substr(str_pad($isbnRegistrantRange['from'], 5, 0, STR_PAD_RIGHT), 0, 5);
            $toValue = (int) substr(str_pad($isbnRegistrantRange['to'], 5, 9, STR_PAD_RIGHT), 0, 5);
            $length = $isbnRegistrantRange['length'];
            $registrationGroup = eZISBNRegistrantRange::create($isbnGroupID, $fromValue, $toValue, $isbnRegistrantRange['from'], $isbnRegistrantRange['to'], $length);
            $registrationGroup->store();
        }
    }
}