Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezstringtype.php
Go to the documentation of this file.
1 <?php
26 class eZStringType extends eZDataType
27 {
28 const DATA_TYPE_STRING = 'ezstring';
29 const MAX_LEN_FIELD = 'data_int1';
30 const MAX_LEN_VARIABLE = '_ezstring_max_string_length_';
31 const DEFAULT_STRING_FIELD = "data_text1";
32 const DEFAULT_STRING_VARIABLE = "_ezstring_default_value_";
33
37 public function __construct()
38 {
39 parent::__construct( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', 'Text line', 'Datatype name' ),
40 array( 'serialize_supported' => true,
41 'object_serialize_map' => array( 'data_text' => 'text' ) ) );
42 $this->MaxLenValidator = new eZIntegerValidator();
43 }
44
48 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
49 {
50 if ( $currentVersion != false )
51 {
52 // $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
53 // $currentObjectAttribute = eZContentObjectAttribute::fetch( $contentObjectAttributeID,
54 // $currentVersion );
55 $dataText = $originalContentObjectAttribute->attribute( "data_text" );
56 $contentObjectAttribute->setAttribute( "data_text", $dataText );
57 }
58 else
59 {
60 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
61 $default = $contentClassAttribute->attribute( 'data_text1' );
62 if ( $default !== '' && $default !== NULL )
63 {
64 $contentObjectAttribute->setAttribute( 'data_text', $default );
65 }
66 }
67 }
68
78 function validateStringHTTPInput( $data, $contentObjectAttribute, $classAttribute )
79 {
80 $maxLen = $classAttribute->attribute( self::MAX_LEN_FIELD );
81 $textCodec = eZTextCodec::instance( false );
82 if ( $textCodec->strlen( $data ) > $maxLen and
83 $maxLen > 0 )
84 {
85 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
86 'The input text is too long. The maximum number of characters allowed is %1.' ),
87 $maxLen );
88 return eZInputValidator::STATE_INVALID;
89 }
90 return eZInputValidator::STATE_ACCEPTED;
91 }
92
93
94 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
95 {
96 $classAttribute = $contentObjectAttribute->contentClassAttribute();
97
98 if ( $http->hasPostVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
99 {
100 $data = trim( $http->postVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) );
101
102 if ( $data == "" )
103 {
104 if ( !$classAttribute->attribute( 'is_information_collector' ) and
105 $contentObjectAttribute->validateIsRequired() )
106 {
107 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
108 'Input required.' ) );
109 return eZInputValidator::STATE_INVALID;
110 }
111 }
112 else
113 {
114 return $this->validateStringHTTPInput( $data, $contentObjectAttribute, $classAttribute );
115 }
116 }
117 else if ( !$classAttribute->attribute( 'is_information_collector' ) and $contentObjectAttribute->validateIsRequired() )
118 {
119 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 'Input required.' ) );
120 return eZInputValidator::STATE_INVALID;
121 }
122 return eZInputValidator::STATE_ACCEPTED;
123 }
124
125 function validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttribute )
126 {
127 if ( $http->hasPostVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
128 {
129 $data = $http->postVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
130 $classAttribute = $contentObjectAttribute->contentClassAttribute();
131
132 if ( $data == "" )
133 {
134 if ( $contentObjectAttribute->validateIsRequired() )
135 {
136 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
137 'Input required.' ) );
138 return eZInputValidator::STATE_INVALID;
139 }
140 else
141 return eZInputValidator::STATE_ACCEPTED;
142 }
143 else
144 {
145 return $this->validateStringHTTPInput( $data, $contentObjectAttribute, $classAttribute );
146 }
147 }
148 else
149 return eZInputValidator::STATE_INVALID;
150 }
151
155 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
156 {
157 if ( $http->hasPostVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
158 {
159 $data = $http->postVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
160 $contentObjectAttribute->setAttribute( 'data_text', $data );
161 return true;
162 }
163 return false;
164 }
165
169 function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $contentObjectAttribute )
170 {
171 if ( $http->hasPostVariable( $base . "_ezstring_data_text_" . $contentObjectAttribute->attribute( "id" ) ) )
172 {
173 $dataText = $http->postVariable( $base . "_ezstring_data_text_" . $contentObjectAttribute->attribute( "id" ) );
174 $collectionAttribute->setAttribute( 'data_text', $dataText );
175 return true;
176 }
177 return false;
178 }
179
184 function storeObjectAttribute( $attribute )
185 {
186 }
187
191 function isSimpleStringInsertionSupported()
192 {
193 return true;
194 }
195
199 function insertSimpleString( $object, $objectVersion, $objectLanguage,
200 $objectAttribute, $string,
201 &$result )
202 {
203 $result = array( 'errors' => array(),
204 'require_storage' => true );
205 $objectAttribute->setContent( $string );
206 $objectAttribute->setAttribute( 'data_text', $string );
207 return true;
208 }
209
210 function storeClassAttribute( $attribute, $version )
211 {
212 }
213
214 function storeDefinedClassAttribute( $attribute )
215 {
216 }
217
218 function validateClassAttributeHTTPInput( $http, $base, $classAttribute )
219 {
220 $maxLenName = $base . self::MAX_LEN_VARIABLE . $classAttribute->attribute( 'id' );
221 if ( $http->hasPostVariable( $maxLenName ) )
222 {
223 $maxLenValue = $http->postVariable( $maxLenName );
224 $maxLenValue = str_replace(" ", "", $maxLenValue );
225 if( ( $maxLenValue == "" ) || ( $maxLenValue == 0 ) )
226 {
227 $maxLenValue = 0;
228 $http->setPostVariable( $maxLenName, $maxLenValue );
229 return eZInputValidator::STATE_ACCEPTED;
230 }
231 else
232 {
233 $this->MaxLenValidator->setRange( 1, false );
234 return $this->MaxLenValidator->validate( $maxLenValue );
235 }
236 }
237 return eZInputValidator::STATE_INVALID;
238 }
239
240 function fixupClassAttributeHTTPInput( $http, $base, $classAttribute )
241 {
242 $maxLenName = $base . self::MAX_LEN_VARIABLE . $classAttribute->attribute( 'id' );
243 if ( $http->hasPostVariable( $maxLenName ) )
244 {
245 $maxLenValue = $http->postVariable( $maxLenName );
246 $this->MaxLenValidator->setRange( 1, false );
247 $maxLenValue = $this->MaxLenValidator->fixup( $maxLenValue );
248 $http->setPostVariable( $maxLenName, $maxLenValue );
249 }
250 }
251
252 function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
253 {
254 $maxLenName = $base . self::MAX_LEN_VARIABLE . $classAttribute->attribute( 'id' );
255 $defaultValueName = $base . self::DEFAULT_STRING_VARIABLE . $classAttribute->attribute( 'id' );
256 if ( $http->hasPostVariable( $maxLenName ) )
257 {
258 $maxLenValue = $http->postVariable( $maxLenName );
259 $classAttribute->setAttribute( self::MAX_LEN_FIELD, $maxLenValue );
260 }
261 if ( $http->hasPostVariable( $defaultValueName ) )
262 {
263 $defaultValueValue = $http->postVariable( $defaultValueName );
264
265 $classAttribute->setAttribute( self::DEFAULT_STRING_FIELD, $defaultValueValue );
266 }
267 return true;
268 }
269
273 function objectAttributeContent( $contentObjectAttribute )
274 {
275 return $contentObjectAttribute->attribute( 'data_text' );
276 }
277
281 function metaData( $contentObjectAttribute )
282 {
283 return $contentObjectAttribute->attribute( 'data_text' );
284 }
289 function toString( $contentObjectAttribute )
290 {
291 return $contentObjectAttribute->attribute( 'data_text' );
292 }
293
294 function fromString( $contentObjectAttribute, $string )
295 {
296 return $contentObjectAttribute->setAttribute( 'data_text', $string );
297 }
298
299
303 function title( $contentObjectAttribute, $name = null )
304 {
305 return $contentObjectAttribute->attribute( 'data_text' );
306 }
307
308 function hasObjectAttributeContent( $contentObjectAttribute )
309 {
310 return trim( $contentObjectAttribute->attribute( 'data_text' ) ) != '';
311 }
312
313 function isIndexable()
314 {
315 return true;
316 }
317
318 function isInformationCollector()
319 {
320 return true;
321 }
322
323 function sortKey( $contentObjectAttribute )
324 {
325 $trans = eZCharTransform::instance();
326 return $trans->transformByGroup( $contentObjectAttribute->attribute( 'data_text' ), 'lowercase' );
327 }
328
329 function sortKeyType()
330 {
331 return 'string';
332 }
333
334 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
335 {
336 $maxLength = $classAttribute->attribute( self::MAX_LEN_FIELD );
337 $defaultString = $classAttribute->attribute( self::DEFAULT_STRING_FIELD );
338 $dom = $attributeParametersNode->ownerDocument;
339 $maxLengthNode = $dom->createElement( 'max-length' );
340 $maxLengthNode->appendChild( $dom->createTextNode( $maxLength ) );
341 $attributeParametersNode->appendChild( $maxLengthNode );
342 $defaultStringNode = $dom->createElement( 'default-string' );
343 if ( $defaultString )
344 {
345 $defaultStringNode->appendChild( $dom->createTextNode( $defaultString ) );
346 }
347 $attributeParametersNode->appendChild( $defaultStringNode );
348 }
349
350 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
351 {
352 $maxLength = $attributeParametersNode->getElementsByTagName( 'max-length' )->item( 0 )->textContent;
353 $defaultString = $attributeParametersNode->getElementsByTagName( 'default-string' )->item( 0 )->textContent;
354 $classAttribute->setAttribute( self::MAX_LEN_FIELD, $maxLength );
355 $classAttribute->setAttribute( self::DEFAULT_STRING_FIELD, $defaultString );
356 }
357
358 function diff( $old, $new, $options = false )
359 {
360 $diff = new eZDiff();
361 $diff->setDiffEngineType( $diff->engineType( 'text' ) );
362 $diff->initDiffEngine();
363 $diffObject = $diff->diff( $old->content(), $new->content() );
364 return $diffObject;
365 }
366
367 function supportsBatchInitializeObjectAttribute()
368 {
369 return true;
370 }
371
372 function batchInitializeObjectAttributeData( $classAttribute )
373 {
374 $default = $classAttribute->attribute( 'data_text1' );
375 if ( $default !== '' && $default !== NULL )
376 {
377 $db = eZDB::instance();
378 $default = "'" . $db->escapeString( $default ) . "'";
379 $trans = eZCharTransform::instance();
380 $lowerCasedDefault = $trans->transformByGroup( $default, 'lowercase' );
381 return array( 'data_text' => $default, 'sort_key_string' => $lowerCasedDefault );
382 }
383
384 return array();
385 }
386
389 public $MaxLenValidator;
390 }
391
392 eZDataType::register( eZStringType::DATA_TYPE_STRING, 'eZStringType' );
393
394 ?>
eZCharTransform\instance
static instance()
Definition: ezchartransform.php:434
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
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
eZStringType
A content datatype which handles text lines.
Definition: ezstringtype.php:27
eZStringType\validateCollectionAttributeHTTPInput
validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezstringtype.php:125
eZStringType\DEFAULT_STRING_VARIABLE
const DEFAULT_STRING_VARIABLE
Definition: ezstringtype.php:32
eZStringType\metaData
metaData( $contentObjectAttribute)
Definition: ezstringtype.php:281
eZStringType\initializeObjectAttribute
initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute)
Definition: ezstringtype.php:48
eZStringType\storeDefinedClassAttribute
storeDefinedClassAttribute( $attribute)
Definition: ezstringtype.php:214
eZStringType\storeObjectAttribute
storeObjectAttribute( $attribute)
Definition: ezstringtype.php:184
eZStringType\$MaxLenValidator
$MaxLenValidator
Definition: ezstringtype.php:389
eZStringType\hasObjectAttributeContent
hasObjectAttributeContent( $contentObjectAttribute)
Definition: ezstringtype.php:308
eZStringType\unserializeContentClassAttribute
unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezstringtype.php:350
eZStringType\isInformationCollector
isInformationCollector()
Definition: ezstringtype.php:318
eZStringType\batchInitializeObjectAttributeData
batchInitializeObjectAttributeData( $classAttribute)
Definition: ezstringtype.php:372
eZStringType\DEFAULT_STRING_FIELD
const DEFAULT_STRING_FIELD
Definition: ezstringtype.php:31
eZStringType\diff
diff( $old, $new, $options=false)
Definition: ezstringtype.php:358
eZStringType\supportsBatchInitializeObjectAttribute
supportsBatchInitializeObjectAttribute()
Definition: ezstringtype.php:367
eZStringType\MAX_LEN_VARIABLE
const MAX_LEN_VARIABLE
Definition: ezstringtype.php:30
eZStringType\fixupClassAttributeHTTPInput
fixupClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezstringtype.php:240
eZStringType\fromString
fromString( $contentObjectAttribute, $string)
Definition: ezstringtype.php:294
eZStringType\sortKey
sortKey( $contentObjectAttribute)
Definition: ezstringtype.php:323
eZStringType\fetchCollectionAttributeHTTPInput
fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $contentObjectAttribute)
Definition: ezstringtype.php:169
eZStringType\validateObjectAttributeHTTPInput
validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezstringtype.php:94
eZStringType\isSimpleStringInsertionSupported
isSimpleStringInsertionSupported()
Definition: ezstringtype.php:191
eZStringType\validateStringHTTPInput
validateStringHTTPInput( $data, $contentObjectAttribute, $classAttribute)
Definition: ezstringtype.php:78
eZStringType\title
title( $contentObjectAttribute, $name=null)
Definition: ezstringtype.php:303
eZStringType\MAX_LEN_FIELD
const MAX_LEN_FIELD
Definition: ezstringtype.php:29
eZStringType\insertSimpleString
insertSimpleString( $object, $objectVersion, $objectLanguage, $objectAttribute, $string, &$result)
Definition: ezstringtype.php:199
eZStringType\isIndexable
isIndexable()
Definition: ezstringtype.php:313
eZStringType\storeClassAttribute
storeClassAttribute( $attribute, $version)
Definition: ezstringtype.php:210
eZStringType\sortKeyType
sortKeyType()
Definition: ezstringtype.php:329
eZStringType\toString
toString( $contentObjectAttribute)
Definition: ezstringtype.php:289
eZStringType\DATA_TYPE_STRING
const DATA_TYPE_STRING
Definition: ezstringtype.php:28
eZStringType\objectAttributeContent
objectAttributeContent( $contentObjectAttribute)
Definition: ezstringtype.php:273
eZStringType\fetchObjectAttributeHTTPInput
fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezstringtype.php:155
eZStringType\validateClassAttributeHTTPInput
validateClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezstringtype.php:218
eZStringType\serializeContentClassAttribute
serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezstringtype.php:334
eZStringType\fetchClassAttributeHTTPInput
fetchClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezstringtype.php:252
eZStringType\__construct
__construct()
Definition: ezstringtype.php:37
eZTextCodec\instance
static instance( $inputCharsetCode, $outputCharsetCode=false, $alwaysReturn=true)
Definition: eztextcodec.php:446
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+.