|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Created on: <17-Apr-2007 11:08:55 bjorn> 00004 // 00005 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00006 // SOFTWARE NAME: eZ Publish 00007 // SOFTWARE RELEASE: 4.0.x 00008 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00009 // SOFTWARE LICENSE: GNU General Public License v2.0 00010 // NOTICE: > 00011 // This program is free software; you can redistribute it and/or 00012 // modify it under the terms of version 2.0 of the GNU General 00013 // Public License as published by the Free Software Foundation. 00014 // 00015 // This program is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU General Public License for more details. 00019 // 00020 // You should have received a copy of version 2.0 of the GNU General 00021 // Public License along with this program; if not, write to the Free 00022 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00023 // MA 02110-1301, USA. 00024 // 00025 // 00026 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00027 // 00028 00029 /*! \file ezisbngrouprange.php 00030 */ 00031 00032 /*! 00033 \class eZISBNGroupRange ezisbngrouprange.php 00034 \brief The class eZISBNGroupRange handle registration group ranges. 00035 00036 Has information about how the different ranges the registration group 00037 element could be in. Example: From 0 to 5 and continues from 600-602. 00038 This means that the length of the registration group can differ from 00039 range to range. 00040 00041 The different Registration group ranges are described in more detail at 00042 http://www.isbn-international.org 00043 00044 */ 00045 00046 //include_once( 'kernel/classes/ezpersistentobject.php' ); 00047 00048 class eZISBNGroupRange extends eZPersistentObject 00049 { 00050 /*! 00051 Constructor 00052 */ 00053 function eZISBNGroupRange( $row ) 00054 { 00055 $this->eZPersistentObject( $row ); 00056 } 00057 00058 00059 /*! 00060 Definition of the ranges for ISBN groups. 00061 */ 00062 static function definition() 00063 { 00064 return array( 'fields' => array( 'id' => array( 'name' => 'ID', 00065 'datatype' => 'integer', 00066 'default' => 0, 00067 'required' => true ), 00068 'from_number' => array( 'name' => 'FromNumber', 00069 'datatype' => 'integer', 00070 'default' => 0, 00071 'required' => true ), 00072 'to_number' => array( 'name' => 'ToNumber', 00073 'datatype' => 'integer', 00074 'default' => 0, 00075 'required' => true ), 00076 'group_from' => array( 'name' => 'GroupFrom', 00077 'datatype' => 'string', 00078 'default' => '', 00079 'required' => true ), 00080 'group_to' => array( 'name' => 'GroupTo', 00081 'datatype' => 'string', 00082 'default' => '', 00083 'required' => true ), 00084 'group_length' => array( 'name' => 'GroupLength', 00085 'datatype' => 'integer', 00086 'default' => 0, 00087 'required' => true ), 00088 ), 00089 'keys' => array( 'id' ), 00090 'increment_key' => 'id', 00091 'class_name' => 'eZISBNGroupRange', 00092 'name' => 'ezisbn_group_range' ); 00093 } 00094 00095 /*! 00096 \static 00097 Create a new group range for an ISBN number. 00098 \param $fromNumber Group is starting from test number, which is based on 00099 the 5 numbers after the Prefix number. 00100 \param $toNumber Group is ending on the To test number, which is based on 00101 the 5 numbers after the Prefix number. 00102 \param $groupFrom Group number is starting on, based on the length set 00103 in the Group. 00104 \param $groupTo Group number is ending on, based on the length set 00105 in the group. 00106 \param $length How many characters $groupFrom and $groupTo should have. 00107 \return a new eZISBNGroupRange object. 00108 */ 00109 static function create( $fromNumber, $toNumber, $groupFrom, $groupTo, $length ) 00110 { 00111 $row = array( 00112 'id' => null, 00113 'from_number' => $fromNumber, 00114 'to_number' => $toNumber, 00115 'group_from' => $groupFrom, 00116 'group_to' => $groupTo, 00117 'group_length' => $length ); 00118 return new eZISBNGroupRange( $row ); 00119 } 00120 00121 00122 /*! 00123 \static 00124 Removes the ISBN group based on ID \a $id. 00125 */ 00126 static function removeByID( $id ) 00127 { 00128 eZPersistentObject::removeObject( eZISBNGroupRange::definition(), 00129 array( 'id' => $id ) ); 00130 } 00131 00132 /*! 00133 \param $count Will contain the count of objects returned and is sent 00134 back in the reference variable. 00135 \return the group range list for ISBN groups. 00136 */ 00137 static function fetchList( $asObject = true ) 00138 { 00139 $sortArray = array( 'from_number' => 'asc' ); 00140 return eZPersistentObject::fetchObjectList( eZISBNGroupRange::definition(), 00141 null, null, $sortArray, null, 00142 $asObject ); 00143 } 00144 00145 /*! 00146 \static 00147 Will extract the group number based on the different ranges 00148 which is based on the 5 first digits after the Prefix field. 00149 \param $isbnNr Should be a stripped down ISBN number with just the digits (ean number). 00150 \param $groupLength is the length of the RegistrationGroup in the range that was found. 00151 Is sent back in the reference variable. 00152 \return the group range object if found and false if not found. 00153 */ 00154 static function extractGroup( $isbnNr ) 00155 { 00156 $groupRange = false; 00157 $testSegment = substr( $isbnNr, 3, 5 ); 00158 if ( is_numeric( $testSegment ) ) 00159 { 00160 $conditions = array( 'from_number' => array( '<=', $testSegment ), 00161 'to_number' => array( '>=', $testSegment ) ); 00162 $groupRangeArray = eZPersistentObject::fetchObjectList( eZISBNGroupRange::definition(), 00163 null, $conditions ); 00164 if ( count( $groupRangeArray ) == 1 ) 00165 { 00166 $groupRange = $groupRangeArray[0]; 00167 } 00168 } 00169 return $groupRange; 00170 } 00171 00172 /*! 00173 \static 00174 Removes all ISBN group ranges from the database. 00175 */ 00176 static function cleanAll() 00177 { 00178 $db = eZDB::instance(); 00179 $definition = eZISBNGroupRange::definition(); 00180 $table = $definition['name']; 00181 $sql = "TRUNCATE TABLE " . $table; 00182 $db->query( $sql ); 00183 } 00184 00185 } 00186 00187 ?>