Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezidentifiertype.php
Go to the documentation of this file.
1 <?php
18 class eZIdentifierType extends eZDataType
19 {
20 const PRETEXT_FIELD = "data_text1";
21 const PRETEXT_VARIABLE = "_ezidentifier_pretext_value_";
22
23 const POSTTEXT_FIELD = "data_text2";
24 const POSTTEXT_VARIABLE = "_ezidentifier_posttext_value_";
25
26 const START_VALUE_FIELD = "data_int1";
27 const START_VALUE_VARIABLE = "_ezidentifier_start_integer_value_";
28
29 const DIGITS_FIELD = "data_int2";
30 const DIGITS_VARIABLE = "_ezidentifier_digits_integer_value_";
31
32 const IDENTIFIER_FIELD = "data_int3";
33 const IDENTIFIER_VARIABLE = "_ezidentifier_identifier_value_";
34
35 const DATA_TYPE_STRING = "ezidentifier";
36
40 public function __construct()
41 {
42 parent::__construct( self::DATA_TYPE_STRING,
43 ezpI18n::tr( 'kernel/classes/datatypes', "Identifier", 'Datatype name' ),
44 array( 'serialize_supported' => true,
45 'object_serialize_map' => array( 'data_text' => 'identifier',
46 'data_int' => 'number' ) ) );
47 $this->IntegerValidator = new eZIntegerValidator( 1 );
48 }
49
54 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
55 {
56 }
57
58 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
59 {
60 }
61
66 function storeObjectAttribute( $contentObjectattribute )
67 {
68 }
69
73 function objectAttributeContent( $contentObjectAttribute )
74 {
75 $content = $contentObjectAttribute->attribute( "data_text" );
76 if ( trim( $content ) == '' )
77 {
78 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
79 $content = eZIdentifierType::generateIdentifierString( $contentClassAttribute, false );
80 }
81 return $content;
82 }
83
84 function toString( $contentObjectAttribute )
85 {
86 return $contentObjectAttribute->attribute( 'data_text' );
87 }
88
89
90 function fromString( $contentObjectAttribute, $string )
91 {
92 if ( $string == '' )
93 return true;
94 $contentObjectAttribute->setAttribute( 'data_text', $string );
95 return true;
96 }
97 function hasObjectAttributeContent( $contentObjectAttribute )
98 {
99 $content = $contentObjectAttribute->attribute( "data_text" );
100 return ( trim( $content ) != '' );
101 }
102
103 function initializeClassAttribute( $classAttribute )
104 {
105 if ( $classAttribute->attribute( self::START_VALUE_FIELD ) == null
106 && $classAttribute->attribute( self::DIGITS_FIELD ) == null
107 && $classAttribute->attribute( self::IDENTIFIER_FIELD ) == null )
108 {
109 $classAttribute->setAttribute( self::START_VALUE_FIELD, 1 );
110 $classAttribute->setAttribute( self::IDENTIFIER_FIELD, 1 );
111 $classAttribute->setAttribute( self::DIGITS_FIELD, 1 );
112 }
113 }
114
119 function validateClassAttributeHTTPInput( $http, $base, $classAttribute )
120 {
121 $startValueName = $base . self::START_VALUE_VARIABLE . $classAttribute->attribute( "id" );
122 $digitsName = $base . self::DIGITS_VARIABLE . $classAttribute->attribute( "id" );
123
124 if ( $http->hasPostVariable( $startValueName ) and
125 $http->hasPostVariable( $digitsName ) )
126 {
127 $startValueValue = str_replace( " ", "", $http->postVariable( $startValueName ) );
128 $digitsValue = str_replace( " ", "", $http->postVariable( $digitsName ) );
129
130 $startValueValueState = $this->IntegerValidator->validate( $startValueValue );
131 $digitsValueState = $this->IntegerValidator->validate( $digitsValue );
132
133 if ( ( $startValueValueState == eZInputValidator::STATE_ACCEPTED ) and
134 ( $digitsValueState == eZInputValidator::STATE_ACCEPTED ) )
135 {
136 return eZInputValidator::STATE_ACCEPTED;
137 }
138 return eZInputValidator::STATE_INTERMEDIATE;
139 }
140 return eZInputValidator::STATE_INVALID;
141 }
142
143 function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
144 {
145 $startValueName = $base . self::START_VALUE_VARIABLE . $classAttribute->attribute( "id" );
146 $digitsName = $base . self::DIGITS_VARIABLE . $classAttribute->attribute( "id" );
147 $preTextName = $base . self::PRETEXT_VARIABLE . $classAttribute->attribute( "id" );
148 $postTextName = $base . self::POSTTEXT_VARIABLE . $classAttribute->attribute( "id" );
149
150 if ( $http->hasPostVariable( $startValueName ) and
151 $http->hasPostVariable( $digitsName ) and
152 $http->hasPostVariable( $preTextName ) and
153 $http->hasPostVariable( $postTextName ) )
154 {
155 $startValueValue = str_replace( " ", "", $http->postVariable( $startValueName ) );
156 $startValueValue = ( int ) $startValueValue;
157 if ( $startValueValue < 1 )
158 {
159 $startValueValue = 1;
160 }
161 $digitsValue = str_replace( " ", "", $http->postVariable( $digitsName ) );
162 $digitsValue = ( int ) $digitsValue;
163 if ( $digitsValue < 1 )
164 {
165 $digitsValue = 1;
166 }
167
168 $preTextValue = $http->postVariable( $preTextName );
169 $postTextValue = $http->postVariable( $postTextName );
170
171 $classAttribute->setAttribute( self::DIGITS_FIELD, $digitsValue );
172 $classAttribute->setAttribute( self::PRETEXT_FIELD, $preTextValue );
173 $classAttribute->setAttribute( self::POSTTEXT_FIELD, $postTextValue );
174
175 $classAttribute->setAttribute( self::START_VALUE_FIELD, $startValueValue );
176 $classAttribute->setAttribute( self::IDENTIFIER_FIELD,
177 $classAttribute->attribute( self::START_VALUE_FIELD ) );
178
179 $originalClassAttribute = eZContentClassAttribute::fetch( $classAttribute->attribute( 'id' ), true, 0 );
180 if ( $originalClassAttribute )
181 {
182 if ( $originalClassAttribute->attribute( self::DIGITS_FIELD ) == $digitsValue
183 && $originalClassAttribute->attribute( self::PRETEXT_FIELD ) == $preTextValue
184 && $originalClassAttribute->attribute( self::POSTTEXT_FIELD ) == $postTextValue
185 && $originalClassAttribute->attribute( self::IDENTIFIER_FIELD ) >= $startValueValue )
186 {
187 $classAttribute->setAttribute( self::START_VALUE_FIELD, $originalClassAttribute->attribute( self::START_VALUE_FIELD ) );
188 $classAttribute->setAttribute( self::IDENTIFIER_FIELD, $originalClassAttribute->attribute( self::IDENTIFIER_FIELD ) );
189 }
190 }
191 }
192 return true;
193 }
194
198 function metaData( $contentObjectAttribute )
199 {
200 return $contentObjectAttribute->attribute( "data_text" );
201 }
202
206 function title( $contentObjectAttribute, $name = null )
207 {
208 return $contentObjectAttribute->attribute( "data_text" );
209 }
210
211 function isIndexable()
212 {
213 return true;
214 }
215
216
217 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
218 {
219 $contentObjectAttributeID = $originalContentObjectAttribute->attribute( "id" );
220 $version = $contentObjectAttribute->attribute( "version" );
221 if ( $currentVersion == false )
222 {
223 // If this is not a copy we need to see if a unique ID must be
224 // assigned. This is handled in assignValue().
225 $contentClassAttribute = $contentObjectAttribute->attribute( 'contentclass_attribute' );
226 $ret = eZIdentifierType::assignValue( $contentClassAttribute, $contentObjectAttribute );
227 }
228 }
229
234 function onPublish( $contentObjectAttribute, $contentObject, $publishedNodes )
235 {
236 $contentClassAttribute = $contentObjectAttribute->attribute( 'contentclass_attribute' );
237 $ret = eZIdentifierType::assignValue( $contentClassAttribute, $contentObjectAttribute );
238
239 return $ret;
240 }
241
246 function assignValue( $contentClassAttribute, $contentObjectAttribute )
247 {
248
249 $retValue = false;
250 $ret = array();
251 $version = $contentObjectAttribute->attribute( 'version' );
252 $contentClassAttributeID = $contentClassAttribute->attribute( 'id' );
253 $objectID = (int)$contentObjectAttribute->attribute( 'contentobject_id' );
254 $classAttributeID = (int)$contentObjectAttribute->attribute( 'contentclassattribute_id' );
255
256 $db = eZDB::instance();
257
258 $existingIDs = $db->arrayQuery( "SELECT data_int " .
259 "FROM ezcontentobject_attribute " .
260 "WHERE contentobject_id = $objectID AND" .
261 " contentclassattribute_id = $classAttributeID AND" .
262 " data_type_string = 'ezidentifier' AND" .
263 " data_int != 0" );
264 if ( count( $existingIDs ) > 0 )
265 {
266 $identifierValue = $existingIDs[0]['data_int'];
267 $ret[] = eZIdentifierType::storeIdentifierValue( $contentClassAttribute, $contentObjectAttribute, $identifierValue );
268 }
269 else
270 {
271 $db->begin();
272
273 // Ensure that we don't get another identifier with the same id, so lock ezcontentclass_attribute
274 $db->lock( array( array( 'table' => 'ezcontentclass_attribute' ) ) );
275
276 $selectQuery = "SELECT data_int3 FROM ezcontentclass_attribute WHERE " .
277 "id=$contentClassAttributeID AND version=0";
278 $result = $db->arrayQuery( $selectQuery );
279 $identifierValue = $result[0]['data_int3'];
280
281 // should only increment when we don't have the first version
282 $updateQuery = "UPDATE ezcontentclass_attribute SET data_int3=data_int3 + 1 WHERE " .
283 "id=$contentClassAttributeID AND version=0";
284
285 $ret[] = $db->query( $updateQuery );
286
287 $db->unlock();
288 // unlock before we start to update the ezcontentobject_attribute table
289
290 $ret[] = eZIdentifierType::storeIdentifierValue( $contentClassAttribute, $contentObjectAttribute, $identifierValue );
291
292 if ( !in_array( false, $ret ) )
293 {
294 // Now make sure all existing versions (if any) gets the same identifier
295 $dataText = $db->escapeString( $contentObjectAttribute->attribute( 'data_text' ) );
296 $dataInt = (int)$contentObjectAttribute->attribute( 'data_int' );
297
298 $trans = eZCharTransform::instance();
299 $sortText = $db->escapeString( $trans->transformByGroup( $contentObjectAttribute->attribute( 'data_text' ),
300 'lowercase' ) );
301
302 $db->query( "UPDATE ezcontentobject_attribute " .
303 "SET data_text = '$dataText', data_int = $dataInt, sort_key_string = '$sortText' " .
304 "WHERE contentobject_id = $objectID AND" .
305 " contentclassattribute_id = $classAttributeID AND" .
306 " data_type_string = 'ezidentifier'" );
307 }
308
309 if ( !in_array( false, $ret ) )
310 $db->commit();
311 else
312 $db->rollback();
313 }
314
315 if ( !in_array( false, $ret ) )
316 $retValue = true;
317
318 return $retValue;
319 }
320
321 function sortKey( $contentObjectAttribute )
322 {
323 $trans = eZCharTransform::instance();
324 return $trans->transformByGroup( $contentObjectAttribute->attribute( 'data_text' ), 'lowercase' );
325 }
326
327 function sortKeyType()
328 {
329 return 'string';
330 }
331
336 function storeIdentifierValue( $contentClassAttribute, $contentObjectAttribute, $identifierValue )
337 {
338 $value = eZIdentifierType::generateIdentifierString( $contentClassAttribute, $identifierValue );
339 $contentObjectAttribute->setAttribute( 'data_text', $value );
340 $contentObjectAttribute->setAttribute( 'data_int', $identifierValue );
341 return true;
342 }
343
344 function generateIdentifierString( $contentClassAttribute, $identifierValue = false )
345 {
346 $preText = $contentClassAttribute->attribute( self::PRETEXT_FIELD );
347 $postText = $contentClassAttribute->attribute( self::POSTTEXT_FIELD );
348 $digits = $contentClassAttribute->attribute( self::DIGITS_FIELD );
349
350 if ( $identifierValue !== false )
351 $midText = str_pad( $identifierValue, $digits, '0', STR_PAD_LEFT );
352 else
353 $midText = str_repeat( 'x', $digits );
354
355 $value = $preText . $midText . $postText;
356 return $value;
357 }
358
359 function customClassAttributeHTTPAction( $http, $action, $contentClassAttribute )
360 {
361 }
362
363 function preStoreClassAttribute( $classAttribute, $version )
364 {
365 }
366
367 function preStoreDefinedClassAttribute( $classAttribute )
368 {
369 }
370
371 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
372 {
373 $digits = $classAttribute->attribute( self::DIGITS_FIELD );
374 $preText = $classAttribute->attribute( self::PRETEXT_FIELD );
375 $postText = $classAttribute->attribute( self::POSTTEXT_FIELD );
376 $startValue = $classAttribute->attribute( self::START_VALUE_FIELD );
377 $identifier = $classAttribute->attribute( self::IDENTIFIER_FIELD );
378
379 $dom = $attributeParametersNode->ownerDocument;
380
381 $digitsNode = $dom->createElement( 'digits' );
382 $digitsNode->appendChild( $dom->createTextNode( $digits ) );
383 $attributeParametersNode->appendChild( $digitsNode );
384 $preTextNode = $dom->createElement( 'pre-text' );
385 $preTextNode->appendChild( $dom->createTextNode( $preText ) );
386 $attributeParametersNode->appendChild( $preTextNode );
387 $postTextNode = $dom->createElement( 'post-text' );
388 $postTextNode->appendChild( $dom->createTextNode( $postText ) );
389 $attributeParametersNode->appendChild( $postTextNode );
390 $startValueNode = $dom->createElement( 'start-value' );
391 $startValueNode->appendChild( $dom->createTextNode( $startValue ) );
392 $attributeParametersNode->appendChild( $startValueNode );
393 $identifierNode = $dom->createElement( 'identifier' );
394 $identifierNode->appendChild( $dom->createTextNode( $identifier ) );
395 $attributeParametersNode->appendChild( $identifierNode );
396 }
397
398 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
399 {
400 $digitsNode = $attributeParametersNode->getElementsByTagName( 'digits' )->item( 0 );
401 $preTextNode = $attributeParametersNode->getElementsByTagName( 'pre-text' )->item( 0 );
402 $postTextNode = $attributeParametersNode->getElementsByTagName( 'post-text' )->item( 0 );
403 $startValueNode = $attributeParametersNode->getElementsByTagName( 'start-value' )->item( 0 );
404 $identifierNode = $attributeParametersNode->getElementsByTagName( 'identifier' )->item( 0 );
405 $digits = $digitsNode ? $digitsNode->textContent : '';
406 $preText = $preTextNode ? $preTextNode->textContent : '';
407 $postText = $postTextNode ? $postTextNode->textContent : '';
408 $startValue = $startValueNode ? $startValueNode->textContent : '';
409 $identifier = $identifierNode ? $identifierNode->textContent : '';
410
411 if ( $digits !== false )
412 $classAttribute->setAttribute( self::DIGITS_FIELD, $digits );
413
414 if ( $preText !== false )
415 $classAttribute->setAttribute( self::PRETEXT_FIELD, $preText );
416
417 if ( $postText !== false )
418 $classAttribute->setAttribute( self::POSTTEXT_FIELD, $postText );
419
420 if ( $startValue !== false )
421 $classAttribute->setAttribute( self::START_VALUE_FIELD, $startValue );
422
423 if ( $identifier !== false )
424 $classAttribute->setAttribute( self::IDENTIFIER_FIELD, $identifier );
425 }
426
427 public $IntegerValidator;
428 }
429
430 eZDataType::register( eZIdentifierType::DATA_TYPE_STRING, "ezidentifiertype" );
431
432 ?>
eZCharTransform\instance
static instance()
Definition: ezchartransform.php:434
eZContentClassAttribute\fetch
static fetch( $id, $asObject=true, $version=eZContentClass::VERSION_STATUS_DEFINED, $field_filters=null)
Definition: ezcontentclassattribute.php:380
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDataType
Base class for content datatypes.
Definition: ezdatatype.php:46
eZDataType\register
static register( $dataTypeString, $className)
Definition: ezdatatype.php:203
eZIdentifierType
The class eZIdentifierType does.
Definition: ezidentifiertype.php:19
eZIdentifierType\fromString
fromString( $contentObjectAttribute, $string)
Definition: ezidentifiertype.php:90
eZIdentifierType\validateClassAttributeHTTPInput
validateClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezidentifiertype.php:119
eZIdentifierType\objectAttributeContent
objectAttributeContent( $contentObjectAttribute)
Definition: ezidentifiertype.php:73
eZIdentifierType\PRETEXT_VARIABLE
const PRETEXT_VARIABLE
Definition: ezidentifiertype.php:21
eZIdentifierType\START_VALUE_VARIABLE
const START_VALUE_VARIABLE
Definition: ezidentifiertype.php:27
eZIdentifierType\assignValue
assignValue( $contentClassAttribute, $contentObjectAttribute)
Definition: ezidentifiertype.php:246
eZIdentifierType\fetchClassAttributeHTTPInput
fetchClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezidentifiertype.php:143
eZIdentifierType\metaData
metaData( $contentObjectAttribute)
Definition: ezidentifiertype.php:198
eZIdentifierType\storeObjectAttribute
storeObjectAttribute( $contentObjectattribute)
Definition: ezidentifiertype.php:66
eZIdentifierType\DIGITS_VARIABLE
const DIGITS_VARIABLE
Definition: ezidentifiertype.php:30
eZIdentifierType\$IntegerValidator
$IntegerValidator
Definition: ezidentifiertype.php:427
eZIdentifierType\storeIdentifierValue
storeIdentifierValue( $contentClassAttribute, $contentObjectAttribute, $identifierValue)
Definition: ezidentifiertype.php:336
eZIdentifierType\customClassAttributeHTTPAction
customClassAttributeHTTPAction( $http, $action, $contentClassAttribute)
Definition: ezidentifiertype.php:359
eZIdentifierType\generateIdentifierString
generateIdentifierString( $contentClassAttribute, $identifierValue=false)
Definition: ezidentifiertype.php:344
eZIdentifierType\sortKeyType
sortKeyType()
Definition: ezidentifiertype.php:327
eZIdentifierType\onPublish
onPublish( $contentObjectAttribute, $contentObject, $publishedNodes)
Definition: ezidentifiertype.php:234
eZIdentifierType\IDENTIFIER_VARIABLE
const IDENTIFIER_VARIABLE
Definition: ezidentifiertype.php:33
eZIdentifierType\DATA_TYPE_STRING
const DATA_TYPE_STRING
Definition: ezidentifiertype.php:35
eZIdentifierType\initializeObjectAttribute
initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute)
Definition: ezidentifiertype.php:217
eZIdentifierType\hasObjectAttributeContent
hasObjectAttributeContent( $contentObjectAttribute)
Definition: ezidentifiertype.php:97
eZIdentifierType\__construct
__construct()
Definition: ezidentifiertype.php:40
eZIdentifierType\PRETEXT_FIELD
const PRETEXT_FIELD
Definition: ezidentifiertype.php:20
eZIdentifierType\START_VALUE_FIELD
const START_VALUE_FIELD
Definition: ezidentifiertype.php:26
eZIdentifierType\fetchObjectAttributeHTTPInput
fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezidentifiertype.php:58
eZIdentifierType\DIGITS_FIELD
const DIGITS_FIELD
Definition: ezidentifiertype.php:29
eZIdentifierType\IDENTIFIER_FIELD
const IDENTIFIER_FIELD
Definition: ezidentifiertype.php:32
eZIdentifierType\initializeClassAttribute
initializeClassAttribute( $classAttribute)
Definition: ezidentifiertype.php:103
eZIdentifierType\isIndexable
isIndexable()
Definition: ezidentifiertype.php:211
eZIdentifierType\POSTTEXT_FIELD
const POSTTEXT_FIELD
Definition: ezidentifiertype.php:23
eZIdentifierType\sortKey
sortKey( $contentObjectAttribute)
Definition: ezidentifiertype.php:321
eZIdentifierType\toString
toString( $contentObjectAttribute)
Definition: ezidentifiertype.php:84
eZIdentifierType\serializeContentClassAttribute
serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezidentifiertype.php:371
eZIdentifierType\POSTTEXT_VARIABLE
const POSTTEXT_VARIABLE
Definition: ezidentifiertype.php:24
eZIdentifierType\preStoreDefinedClassAttribute
preStoreDefinedClassAttribute( $classAttribute)
Definition: ezidentifiertype.php:367
eZIdentifierType\unserializeContentClassAttribute
unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezidentifiertype.php:398
eZIdentifierType\preStoreClassAttribute
preStoreClassAttribute( $classAttribute, $version)
Definition: ezidentifiertype.php:363
eZIdentifierType\title
title( $contentObjectAttribute, $name=null)
Definition: ezidentifiertype.php:206
eZIdentifierType\validateObjectAttributeHTTPInput
validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezidentifiertype.php:54
eZInputValidator\STATE_INTERMEDIATE
const STATE_INTERMEDIATE
Definition: ezinputvalidator.php:80
eZInputValidator\STATE_ACCEPTED
const STATE_ACCEPTED
Definition: ezinputvalidator.php:79
eZInputValidator\STATE_INVALID
const STATE_INVALID
Definition: ezinputvalidator.php:81
eZIntegerValidator
The class eZIntegerValidator does.
Definition: ezintegervalidator.php:18
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.