00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 include_once( "kernel/classes/ezdatatype.php" );
00042 include_once( "lib/ezutils/classes/ezintegervalidator.php" );
00043
00044 define( "EZ_DATATYPESTRING_PRETEXT_FIELD", "data_text1" );
00045 define( "EZ_DATATYPESTRING_PRETEXT_VARIABLE", "_ezidentifier_pretext_value_" );
00046
00047 define( "EZ_DATATYPESTRING_POSTTEXT_FIELD", "data_text2" );
00048 define( "EZ_DATATYPESTRING_POSTTEXT_VARIABLE", "_ezidentifier_posttext_value_" );
00049
00050 define( "EZ_DATATYPESTRING_START_VALUE_FIELD", "data_int1" );
00051 define( "EZ_DATATYPESTRING_START_VALUE_VARIABLE", "_ezidentifier_start_integer_value_" );
00052
00053 define( "EZ_DATATYPESTRING_DIGITS_FIELD", "data_int2" );
00054 define( "EZ_DATATYPESTRING_DIGITS_VARIABLE", "_ezidentifier_digits_integer_value_" );
00055
00056 define( "EZ_DATATYPESTRING_IDENTIFIER_FIELD", "data_int3" );
00057 define( "EZ_DATATYPESTRING_IDENTIFIER_VARIABLE", "_ezidentifier_identifier_value_" );
00058
00059 define( "EZ_DATATYPESTRING_IDENTIFIER", "ezidentifier" );
00060
00061 class eZIdentifierType extends eZDataType
00062 {
00063
00064
00065
00066 function eZIdentifierType()
00067 {
00068 $this->eZDataType( EZ_DATATYPESTRING_IDENTIFIER,
00069 ezi18n( 'kernel/classes/datatypes', "Identifier", 'Datatype name' ),
00070 array( 'serialize_supported' => true,
00071 'object_serialize_map' => array( 'data_text' => 'identifier',
00072 'data_int' => 'number' ) ) );
00073 $this->IntegerValidator = new eZIntegerValidator( 1 );
00074 }
00075
00076
00077
00078
00079
00080 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00081 {
00082 }
00083
00084 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00085 {
00086 }
00087
00088
00089
00090
00091
00092 function storeObjectAttribute( &$contentObjectattribute )
00093 {
00094 }
00095
00096
00097
00098
00099 function &objectAttributeContent( &$contentObjectAttribute )
00100 {
00101 $content = $contentObjectAttribute->attribute( "data_text" );
00102 if ( trim( $content ) == '' )
00103 {
00104 $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
00105 $content = eZIdentifierType::generateIdentifierString( $contentClassAttribute, false );
00106 }
00107 return $content;
00108 }
00109
00110 function toString( $contentObjectAttribute )
00111 {
00112 return $contentObjectAttribute->attribute( 'data_text' );
00113 }
00114
00115
00116 function fromString( &$contentObjectAttribute, $string )
00117 {
00118 if ( $string == '' )
00119 return true;
00120 $contentObjectAttribute->setAttribute( 'data_text', $string );
00121 return true;
00122 }
00123 function hasObjectAttributeContent( &$contentObjectAttribute )
00124 {
00125 $content = $contentObjectAttribute->attribute( "data_text" );
00126 return ( trim( $content ) != '' );
00127 }
00128
00129 function initializeClassAttribute( &$classAttribute )
00130 {
00131 if ( $classAttribute->attribute( EZ_DATATYPESTRING_START_VALUE_FIELD ) == null
00132 && $classAttribute->attribute( EZ_DATATYPESTRING_DIGITS_FIELD ) == null
00133 && $classAttribute->attribute( EZ_DATATYPESTRING_IDENTIFIER_FIELD ) == null )
00134 {
00135 $classAttribute->setAttribute( EZ_DATATYPESTRING_START_VALUE_FIELD, 1 );
00136 $classAttribute->setAttribute( EZ_DATATYPESTRING_IDENTIFIER_FIELD, 1 );
00137 $classAttribute->setAttribute( EZ_DATATYPESTRING_DIGITS_FIELD, 1 );
00138 }
00139 }
00140
00141
00142
00143
00144
00145 function validateClassAttributeHTTPInput( &$http, $base, &$classAttribute )
00146 {
00147 $startValueName = $base . EZ_DATATYPESTRING_START_VALUE_VARIABLE . $classAttribute->attribute( "id" );
00148 $digitsName = $base . EZ_DATATYPESTRING_DIGITS_VARIABLE . $classAttribute->attribute( "id" );
00149
00150 if ( $http->hasPostVariable( $startValueName ) and
00151 $http->hasPostVariable( $digitsName ) )
00152 {
00153 $startValueValue = str_replace( " ", "", $http->postVariable( $startValueName ) );
00154 $digitsValue = str_replace( " ", "", $http->postVariable( $digitsName ) );
00155
00156 $startValueValueState = $this->IntegerValidator->validate( $startValueValue );
00157 $digitsValueState = $this->IntegerValidator->validate( $digitsValue );
00158
00159 if ( ( $startValueValueState == EZ_INPUT_VALIDATOR_STATE_ACCEPTED ) and
00160 ( $digitsValueState == EZ_INPUT_VALIDATOR_STATE_ACCEPTED ) )
00161 {
00162 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00163 }
00164 return EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE;
00165 }
00166 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00167 }
00168
00169
00170
00171
00172 function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute )
00173 {
00174 $startValueName = $base . EZ_DATATYPESTRING_START_VALUE_VARIABLE . $classAttribute->attribute( "id" );
00175 $digitsName = $base . EZ_DATATYPESTRING_DIGITS_VARIABLE . $classAttribute->attribute( "id" );
00176 $preTextName = $base . EZ_DATATYPESTRING_PRETEXT_VARIABLE . $classAttribute->attribute( "id" );
00177 $postTextName = $base . EZ_DATATYPESTRING_POSTTEXT_VARIABLE . $classAttribute->attribute( "id" );
00178
00179 if ( $http->hasPostVariable( $startValueName ) and
00180 $http->hasPostVariable( $digitsName ) and
00181 $http->hasPostVariable( $preTextName ) and
00182 $http->hasPostVariable( $postTextName ) )
00183 {
00184 $startValueValue = str_replace( " ", "", $http->postVariable( $startValueName ) );
00185 $startValueValue = ( int ) $startValueValue;
00186 if ( $startValueValue < 1 )
00187 {
00188 $startValueValue = 1;
00189 }
00190 $digitsValue = str_replace( " ", "", $http->postVariable( $digitsName ) );
00191 $digitsValue = ( int ) $digitsValue;
00192 if ( $digitsValue < 1 )
00193 {
00194 $digitsValue = 1;
00195 }
00196
00197 $preTextValue = $http->postVariable( $preTextName );
00198 $postTextValue = $http->postVariable( $postTextName );
00199
00200 $classAttribute->setAttribute( EZ_DATATYPESTRING_DIGITS_FIELD, $digitsValue );
00201 $classAttribute->setAttribute( EZ_DATATYPESTRING_PRETEXT_FIELD, $preTextValue );
00202 $classAttribute->setAttribute( EZ_DATATYPESTRING_POSTTEXT_FIELD, $postTextValue );
00203
00204 $classAttribute->setAttribute( EZ_DATATYPESTRING_START_VALUE_FIELD, $startValueValue );
00205 $classAttribute->setAttribute( EZ_DATATYPESTRING_IDENTIFIER_FIELD,
00206 $classAttribute->attribute( EZ_DATATYPESTRING_START_VALUE_FIELD ) );
00207
00208 $originalClassAttribute = eZContentClassAttribute::fetch( $classAttribute->attribute( 'id' ), true, 0 );
00209 if ( $originalClassAttribute )
00210 {
00211 if ( $originalClassAttribute->attribute( EZ_DATATYPESTRING_DIGITS_FIELD ) == $digitsValue
00212 && $originalClassAttribute->attribute( EZ_DATATYPESTRING_PRETEXT_FIELD ) == $preTextValue
00213 && $originalClassAttribute->attribute( EZ_DATATYPESTRING_POSTTEXT_FIELD ) == $postTextValue
00214 && $originalClassAttribute->attribute( EZ_DATATYPESTRING_IDENTIFIER_FIELD ) >= $startValueValue )
00215 {
00216 $classAttribute->setAttribute( EZ_DATATYPESTRING_START_VALUE_FIELD, $originalClassAttribute->attribute( EZ_DATATYPESTRING_START_VALUE_FIELD ) );
00217 $classAttribute->setAttribute( EZ_DATATYPESTRING_IDENTIFIER_FIELD, $originalClassAttribute->attribute( EZ_DATATYPESTRING_IDENTIFIER_FIELD ) );
00218 }
00219 }
00220 }
00221 return true;
00222 }
00223
00224
00225
00226
00227 function metaData( $contentObjectAttribute )
00228 {
00229 return $contentObjectAttribute->attribute( "data_text" );
00230 }
00231
00232
00233
00234
00235 function title( &$contentObjectAttribute )
00236 {
00237 return $contentObjectAttribute->attribute( "data_text" );
00238 }
00239
00240
00241
00242
00243 function isIndexable()
00244 {
00245 return true;
00246 }
00247
00248
00249
00250
00251
00252 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
00253 {
00254 $contentObjectAttributeID = $originalContentObjectAttribute->attribute( "id" );
00255 $version = $contentObjectAttribute->attribute( "version" );
00256 if ( $currentVersion == false )
00257 {
00258
00259
00260 $contentClassAttribute =& $contentObjectAttribute->attribute( 'contentclass_attribute' );
00261 $ret = eZIdentifierType::assignValue( $contentClassAttribute, $contentObjectAttribute );
00262 }
00263 }
00264
00265
00266
00267
00268
00269 function onPublish( &$contentObjectAttribute, &$contentObject, &$publishedNodes )
00270 {
00271 $contentClassAttribute = $contentObjectAttribute->attribute( 'contentclass_attribute' );
00272 $ret = eZIdentifierType::assignValue( $contentClassAttribute, $contentObjectAttribute );
00273
00274 return $ret;
00275 }
00276
00277
00278
00279
00280
00281 function assignValue( &$contentClassAttribute, &$contentObjectAttribute )
00282 {
00283
00284 $retValue = false;
00285 $ret = array();
00286 $version = $contentObjectAttribute->attribute( 'version' );
00287 $contentClassID = $contentClassAttribute->attribute( 'id' );
00288 $objectID = (int)$contentObjectAttribute->attribute( 'contentobject_id' );
00289 $classAttributeID = (int)$contentObjectAttribute->attribute( 'contentclassattribute_id' );
00290
00291 $db =& eZDB::instance();
00292
00293 $existingIDs = $db->arrayQuery( "SELECT data_int\n" .
00294 "FROM ezcontentobject_attribute\n" .
00295 "WHERE contentobject_id = $objectID AND\n" .
00296 " contentclassattribute_id = $classAttributeID AND\n" .
00297 " data_type_string = 'ezidentifier' AND\n" .
00298 " data_int != 0" );
00299 if ( count( $existingIDs ) > 0 )
00300 {
00301 $identifierValue = $existingIDs[0]['data_int'];
00302 $ret[] = eZIdentifierType::storeIdentifierValue( $contentClassAttribute, $contentObjectAttribute, $identifierValue );
00303 }
00304 else
00305 {
00306 $db->begin();
00307
00308
00309 $db->lock( array( array( "table" => "ezcontentobject_attribute" ),
00310 array( "table" => "ezcontentclass_attribute" ) ) );
00311
00312 $selectQuery = "SELECT data_int3 FROM ezcontentclass_attribute WHERE " .
00313 "id='$contentClassID' AND version='0'";
00314 $result = $db->arrayQuery( $selectQuery );
00315 $identifierValue = $result[0]['data_int3'];
00316
00317
00318 $updateQuery = "UPDATE ezcontentclass_attribute SET data_int3=data_int3 + 1 WHERE " .
00319 "id='$contentClassID' AND version='0'";
00320
00321 $ret[] = $db->query( $updateQuery );
00322 $ret[] = eZIdentifierType::storeIdentifierValue( $contentClassAttribute, $contentObjectAttribute, $identifierValue );
00323
00324 if ( !in_array( false, $ret ) )
00325 {
00326
00327 $dataText = $db->escapeString( $contentObjectAttribute->attribute( 'data_text' ) );
00328 $dataInt = (int)$contentObjectAttribute->attribute( 'data_int' );
00329
00330 include_once( 'lib/ezi18n/classes/ezchartransform.php' );
00331 $trans =& eZCharTransform::instance();
00332 $sortText = $db->escapeString( $trans->transformByGroup( $contentObjectAttribute->attribute( 'data_text' ),
00333 'lowercase' ) );
00334
00335 $db->query( "UPDATE ezcontentobject_attribute\n" .
00336 "SET data_text = '$dataText', data_int = $dataInt, sort_key_string = '$sortText'\n" .
00337 "WHERE contentobject_id = $objectID AND\n" .
00338 " contentclassattribute_id = $classAttributeID AND\n" .
00339 " data_type_string = 'ezidentifier'" );
00340 }
00341
00342 if ( !in_array( false, $ret ) )
00343 $db->commit();
00344 else
00345 $db->rollback();
00346
00347 $db->unlock();
00348 }
00349
00350 if ( !in_array( false, $ret ) )
00351 $retValue = true;
00352
00353 return $retValue;
00354 }
00355
00356
00357
00358
00359 function sortKey( &$contentObjectAttribute )
00360 {
00361 include_once( 'lib/ezi18n/classes/ezchartransform.php' );
00362 $trans =& eZCharTransform::instance();
00363 return $trans->transformByGroup( $contentObjectAttribute->attribute( 'data_text' ), 'lowercase' );
00364 }
00365
00366
00367
00368
00369 function sortKeyType()
00370 {
00371 return 'string';
00372 }
00373
00374
00375
00376
00377
00378 function storeIdentifierValue( &$contentClassAttribute, &$contentObjectAttribute, $identifierValue )
00379 {
00380 $value = eZIdentifierType::generateIdentifierString( $contentClassAttribute, $identifierValue );
00381 $contentObjectAttribute->setAttribute( 'data_text', $value );
00382 $contentObjectAttribute->setAttribute( 'data_int', $identifierValue );
00383 return true;
00384 }
00385
00386 function generateIdentifierString( &$contentClassAttribute, $identifierValue = false )
00387 {
00388 $preText = $contentClassAttribute->attribute( EZ_DATATYPESTRING_PRETEXT_FIELD );
00389 $postText = $contentClassAttribute->attribute( EZ_DATATYPESTRING_POSTTEXT_FIELD );
00390 $digits = $contentClassAttribute->attribute( EZ_DATATYPESTRING_DIGITS_FIELD );
00391
00392 if ( $identifierValue !== false )
00393 $midText = str_pad( $identifierValue, $digits, '0', STR_PAD_LEFT );
00394 else
00395 $midText = str_repeat( 'x', $digits );
00396
00397 $value = $preText . $midText . $postText;
00398 return $value;
00399 }
00400
00401 function customClassAttributeHTTPAction( &$http, $action, &$contentClassAttribute )
00402 {
00403 }
00404
00405 function preStoreClassAttribute( &$classAttribute, $version )
00406 {
00407 }
00408
00409 function preStoreDefinedClassAttribute( &$classAttribute )
00410 {
00411 }
00412
00413
00414
00415
00416 function serializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
00417 {
00418 $digits = $classAttribute->attribute( EZ_DATATYPESTRING_DIGITS_FIELD );
00419 $preText = $classAttribute->attribute( EZ_DATATYPESTRING_PRETEXT_FIELD );
00420 $postText = $classAttribute->attribute( EZ_DATATYPESTRING_POSTTEXT_FIELD );
00421 $startValue = $classAttribute->attribute( EZ_DATATYPESTRING_START_VALUE_FIELD );
00422 $identifier = $classAttribute->attribute( EZ_DATATYPESTRING_IDENTIFIER_FIELD );
00423
00424 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'digits', $digits ) );
00425 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'pre-text', $preText ) );
00426 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'post-text', $postText ) );
00427 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'start-value', $startValue ) );
00428 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'identifier', $identifier ) );
00429 }
00430
00431
00432
00433
00434 function unserializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
00435 {
00436 $digits = $attributeParametersNode->elementTextContentByName( 'digits' );
00437 $preText = $attributeParametersNode->elementTextContentByName( 'pre-text' );
00438 $postText = $attributeParametersNode->elementTextContentByName( 'post-text' );
00439 $startValue = $attributeParametersNode->elementTextContentByName( 'start-value' );
00440 $identifier = $attributeParametersNode->elementTextContentByName( 'identifier' );
00441
00442 if ( $digits !== false )
00443 $classAttribute->setAttribute( EZ_DATATYPESTRING_DIGITS_FIELD, $digits );
00444
00445 if ( $preText !== false )
00446 $classAttribute->setAttribute( EZ_DATATYPESTRING_PRETEXT_FIELD, $preText );
00447
00448 if ( $postText !== false )
00449 $classAttribute->setAttribute( EZ_DATATYPESTRING_POSTTEXT_FIELD, $postText );
00450
00451 if ( $startValue !== false )
00452 $classAttribute->setAttribute( EZ_DATATYPESTRING_START_VALUE_FIELD, $startValue );
00453
00454 if ( $identifier !== false )
00455 $classAttribute->setAttribute( EZ_DATATYPESTRING_IDENTIFIER_FIELD, $identifier );
00456 }
00457
00458 var $IntegerValidator;
00459 }
00460
00461 eZDataType::register( EZ_DATATYPESTRING_IDENTIFIER, "ezidentifiertype" );
00462
00463 ?>