Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezfloattype.php
Go to the documentation of this file.
1 <?php
18 class eZFloatType extends eZDataType
19 {
20 const DATA_TYPE_STRING = "ezfloat";
21 const MIN_FIELD = "data_float1";
22 const MIN_VARIABLE = "_ezfloat_min_float_value_";
23 const MAX_FIELD = "data_float2";
24 const MAX_VARIABLE = "_ezfloat_max_float_value_";
25 const DEFAULT_FIELD = "data_float3";
26 const DEFAULT_VARIABLE = "_ezfloat_default_value_";
27 const INPUT_STATE_FIELD = "data_float4";
28 const NO_MIN_MAX_VALUE = 0;
29 const HAS_MIN_VALUE = 1;
30 const HAS_MAX_VALUE = 2;
31 const HAS_MIN_MAX_VALUE = 3;
32
33 public function __construct()
34 {
35 parent::__construct( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', "Float", 'Datatype name' ),
36 array( 'serialize_supported' => true,
37 'object_serialize_map' => array( 'data_float' => 'value' ) ) );
38 $this->FloatValidator = new eZFloatValidator();
39 }
40
44 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
45 {
46 if ( $currentVersion != false )
47 {
48 // $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
49 // $currentObjectAttribute = eZContentObjectAttribute::fetch( $contentObjectAttributeID,
50 // $currentVersion );
51 $dataFloat = $originalContentObjectAttribute->attribute( "data_float" );
52 $contentObjectAttribute->setAttribute( "data_float", $dataFloat );
53 }
54 else
55 {
56 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
57 $default = $contentClassAttribute->attribute( "data_float3" );
58 if ( $default !== 0 )
59 {
60 $contentObjectAttribute->setAttribute( "data_float", $default );
61 }
62 }
63 }
64
68 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
69 {
70 if ( $http->hasPostVariable( $base . "_data_float_" . $contentObjectAttribute->attribute( "id" ) ) )
71 {
72 $data = $http->postVariable( $base . "_data_float_" . $contentObjectAttribute->attribute( "id" ) );
73 $contentObjectAttribute->setHTTPValue( $data );
74
75 $locale = eZLocale::instance();
76 $data = $locale->internalNumber( $data );
77
78 $data = str_replace(" ", "", $data);
79
80 $contentObjectAttribute->setAttribute( "data_float", $data );
81 return true;
82 }
83 return false;
84 }
85
95 function validateFloatHTTPInput( $data, $contentObjectAttribute, $classAttribute )
96 {
97 $min = $classAttribute->attribute( self::MIN_FIELD );
98 $max = $classAttribute->attribute( self::MAX_FIELD );
99 $inputState = $classAttribute->attribute( self::INPUT_STATE_FIELD );
100 switch( $inputState )
101 {
102 case self::NO_MIN_MAX_VALUE:
103 $state = $this->FloatValidator->validate( $data );
104 if ( $state === eZInputValidator::STATE_ACCEPTED )
105 {
106 return eZInputValidator::STATE_ACCEPTED;
107 }
108 else
109 {
110 $contentObjectAttribute->setValidationError(
111 ezpI18n::tr(
112 'kernel/classes/datatypes',
113 'The given input is not a floating point number.'
114 )
115 );
116 }
117 break;
118 case self::HAS_MIN_VALUE:
119 $this->FloatValidator->setRange( $min, false );
120 $state = $this->FloatValidator->validate( $data );
121 if ( $state === eZInputValidator::STATE_ACCEPTED )
122 {
123 return eZInputValidator::STATE_ACCEPTED;
124 }
125 else
126 {
127 $contentObjectAttribute->setValidationError(
128 ezpI18n::tr(
129 'kernel/classes/datatypes',
130 'The input must be greater than %1'
131 ),
132 $min
133 );
134 }
135 break;
136 case self::HAS_MAX_VALUE:
137 $this->FloatValidator->setRange( false, $max );
138 $state = $this->FloatValidator->validate( $data );
139 if ( $state === eZInputValidator::STATE_ACCEPTED )
140 {
141 return eZInputValidator::STATE_ACCEPTED;
142 }
143 else
144 {
145 $contentObjectAttribute->setValidationError(
146 ezpI18n::tr(
147 'kernel/classes/datatypes',
148 'The input must be less than %1'
149 ),
150 $max
151 );
152 }
153 break;
154 case self::HAS_MIN_MAX_VALUE:
155 $this->FloatValidator->setRange( $min, $max );
156 $state = $this->FloatValidator->validate( $data );
157 if ( $state === eZInputValidator::STATE_ACCEPTED )
158 {
159 return eZInputValidator::STATE_ACCEPTED;
160 }
161 else
162 {
163 $contentObjectAttribute->setValidationError(
164 ezpI18n::tr(
165 'kernel/classes/datatypes',
166 'The input is not in defined range %1 - %2'
167 ),
168 $min, $max
169 );
170 }
171 break;
172 }
173 return eZInputValidator::STATE_INVALID;
174 }
175
180 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
181 {
182 if ( $http->hasPostVariable( $base . "_data_float_" . $contentObjectAttribute->attribute( "id" ) ) )
183 {
184 $data = $http->postVariable( $base . "_data_float_" . $contentObjectAttribute->attribute( "id" ) );
185 $data = str_replace(" ", "", $data );
186
187 if ( !$contentObjectAttribute->validateIsRequired() && ( $data == "" ) )
188 {
189 return eZInputValidator::STATE_ACCEPTED;
190 }
191
192 $locale = eZLocale::instance();
193 $data = $locale->internalNumber( $data );
194
195 return $this->validateFloatHTTPInput(
196 $data, $contentObjectAttribute,
197 $contentObjectAttribute->contentClassAttribute()
198 );
199 }
200 return eZInputValidator::STATE_INVALID;
201 }
202
203 function fixupObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
204 {
205 }
206
207 function storeObjectAttribute( $attribute )
208 {
209 }
210
211 function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
212 {
213 $minValueName = $base . self::MIN_VARIABLE . $classAttribute->attribute( "id" );
214 $maxValueName = $base . self::MAX_VARIABLE . $classAttribute->attribute( "id" );
215 $defaultValueName = $base . self::DEFAULT_VARIABLE . $classAttribute->attribute( "id" );
216
217 if ( $http->hasPostVariable( $minValueName ) and
218 $http->hasPostVariable( $maxValueName ) and
219 $http->hasPostVariable( $defaultValueName ) )
220 {
221 $locale = eZLocale::instance();
222
223 $minValueValue = $http->postVariable( $minValueName );
224 $minValueValue = str_replace(" ", "", $minValueValue );
225 $minValueValue = $locale->internalNumber( $minValueValue );
226 $maxValueValue = $http->postVariable( $maxValueName );
227 $maxValueValue = str_replace(" ", "", $maxValueValue );
228 $maxValueValue = $locale->internalNumber( $maxValueValue );
229 $defaultValueValue = $http->postVariable( $defaultValueName );
230 $defaultValueValue = str_replace(" ", "", $defaultValueValue );
231 $defaultValueValue = $locale->internalNumber( $defaultValueValue );
232
233 $classAttribute->setAttribute( self::MIN_FIELD, $minValueValue );
234 $classAttribute->setAttribute( self::MAX_FIELD, $maxValueValue );
235 $classAttribute->setAttribute( self::DEFAULT_FIELD, $defaultValueValue );
236
237 if ( ( $minValueValue == "" ) && ( $maxValueValue == "") ){
238 $input_state = self::NO_MIN_MAX_VALUE;
239 $classAttribute->setAttribute( self::INPUT_STATE_FIELD, $input_state );
240 }
241 else if ( ( $minValueValue == "" ) && ( $maxValueValue !== "") )
242 {
243 $input_state = self::HAS_MAX_VALUE;
244 $classAttribute->setAttribute( self::INPUT_STATE_FIELD, $input_state );
245 }
246 else if ( ( $minValueValue !== "" ) && ( $maxValueValue == "") )
247 {
248 $input_state = self::HAS_MIN_VALUE;
249 $classAttribute->setAttribute( self::INPUT_STATE_FIELD, $input_state );
250 }
251 else
252 {
253 $input_state = self::HAS_MIN_MAX_VALUE;
254 $classAttribute->setAttribute( self::INPUT_STATE_FIELD, $input_state );
255 }
256 return true;
257 }
258 return false;
259 }
260
261 function validateClassAttributeHTTPInput( $http, $base, $classAttribute )
262 {
263 $minValueName = $base . self::MIN_VARIABLE . $classAttribute->attribute( "id" );
264 $maxValueName = $base . self::MAX_VARIABLE . $classAttribute->attribute( "id" );
265 $defaultValueName = $base . self::DEFAULT_VARIABLE . $classAttribute->attribute( "id" );
266
267 if ( $http->hasPostVariable( $minValueName ) and
268 $http->hasPostVariable( $maxValueName ) and
269 $http->hasPostVariable( $defaultValueName ) )
270 {
271 $locale = eZLocale::instance();
272
273 $minValueValue = $http->postVariable( $minValueName );
274 $minValueValue = str_replace(" ", "", $minValueValue );
275 $minValueValue = $locale->internalNumber( $minValueValue );
276 $maxValueValue = $http->postVariable( $maxValueName );
277 $maxValueValue = str_replace(" ", "", $maxValueValue );
278 $maxValueValue = $locale->internalNumber( $maxValueValue );
279 $defaultValueValue = $http->postVariable( $defaultValueName );
280 $defaultValueValue = str_replace(" ", "", $defaultValueValue );
281 $defaultValueValue = $locale->internalNumber( $defaultValueValue );
282
283 if ( ( $minValueValue == "" ) && ( $maxValueValue == "") ){
284 return eZInputValidator::STATE_ACCEPTED;
285 }
286 else if ( ( $minValueValue == "" ) && ( $maxValueValue !== "") )
287 {
288 $max_state = $this->FloatValidator->validate( $maxValueValue );
289 return $max_state;
290 }
291 else if ( ( $minValueValue !== "" ) && ( $maxValueValue == "") )
292 {
293 $min_state = $this->FloatValidator->validate( $minValueValue );
294 return $min_state;
295 }
296 else
297 {
298 $min_state = $this->FloatValidator->validate( $minValueValue );
299 $max_state = $this->FloatValidator->validate( $maxValueValue );
300 if ( ( $min_state == eZInputValidator::STATE_ACCEPTED ) and
301 ( $max_state == eZInputValidator::STATE_ACCEPTED ) )
302 {
303 if ($minValueValue <= $maxValueValue)
304 return eZInputValidator::STATE_ACCEPTED;
305 else
306 {
307 $state = eZInputValidator::STATE_INTERMEDIATE;
308 eZDebug::writeNotice( "Integer minimum value great than maximum value." );
309 return $state;
310 }
311 }
312 }
313
314 if ($defaultValueValue == ""){
315 $default_state = eZInputValidator::STATE_ACCEPTED;
316 }
317 else
318 $default_state = $this->FloatValidator->validate( $defaultValueValue );
319 }
320 return eZInputValidator::STATE_INVALID;
321 }
322
323 function fixupClassAttributeHTTPInput( $http, $base, $classAttribute )
324 {
325 $minValueName = $base . self::MIN_VARIABLE . $classAttribute->attribute( "id" );
326 $maxValueName = $base . self::MAX_VARIABLE . $classAttribute->attribute( "id" );
327 if ( $http->hasPostVariable( $minValueName ) and $http->hasPostVariable( $maxValueName ) )
328 {
329 $locale = eZLocale::instance();
330
331 $minValueValue = $http->postVariable( $minValueName );
332 $minValueValue = str_replace(" ", "", $minValueValue );
333 $minValueValue = $locale->internalNumber( $minValueValue );
334 $maxValueValue = $http->postVariable( $maxValueName );
335 $maxValueValue = str_replace(" ", "", $maxValueValue );
336 $maxValueValue = $locale->internalNumber( $maxValueValue );
337
338 if ($minValueValue > $maxValueValue)
339 {
340 $this->FloatValidator->setRange( $minValueValue, false );
341 $maxValueValue = $this->FloatValidator->fixup( $maxValueValue );
342 $http->setPostVariable( $maxValueName, $maxValueValue );
343 }
344 }
345 }
346
347 function storeClassAttribute( $attribute, $version )
348 {
349 }
350
351 function metaData( $contentObjectAttribute )
352 {
353 return (float)$contentObjectAttribute->attribute( "data_float" );
354 }
355
359 function objectAttributeContent( $contentObjectAttribute )
360 {
361 return $contentObjectAttribute->attribute( 'data_float' );
362 }
363
368 function title( $contentObjectAttribute, $name = null )
369 {
370 return $contentObjectAttribute->attribute( "data_float" );
371 }
372
373 function hasObjectAttributeContent( $contentObjectAttribute )
374 {
375 return $contentObjectAttribute->attribute( 'data_float' ) !== null;
376 }
381 function toString( $contentObjectAttribute )
382 {
383 return $contentObjectAttribute->attribute( 'data_float' );
384 }
385
386 function fromString( $contentObjectAttribute, $string )
387 {
388 return $contentObjectAttribute->setAttribute( 'data_float', $string );
389 }
390
391 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
392 {
393 $defaultValue = $classAttribute->attribute( self::DEFAULT_FIELD );
394 $minValue = $classAttribute->attribute( self::MIN_FIELD );
395 $maxValue = $classAttribute->attribute( self::MAX_FIELD );
396 $minMaxState = $classAttribute->attribute( self::INPUT_STATE_FIELD );
397
398 $dom = $attributeParametersNode->ownerDocument;
399 $defaultValueNode = $dom->createElement( 'default-value' );
400 $defaultValueNode->appendChild( $dom->createTextNode( $defaultValue ) );
401 $attributeParametersNode->appendChild( $defaultValueNode );
402 if ( $minMaxState == self::HAS_MIN_VALUE or $minMaxState == self::HAS_MIN_MAX_VALUE )
403 {
404 $minValueNode = $dom->createElement( 'min-value' );
405 $minValueNode->appendChild( $dom->createTextNode( $minValue ) );
406 $attributeParametersNode->appendChild( $minValueNode );
407 }
408 if ( $minMaxState == self::HAS_MAX_VALUE or $minMaxState == self::HAS_MIN_MAX_VALUE )
409 {
410 $maxValueNode = $dom->createElement( 'max-value' );
411 $maxValueNode->appendChild( $dom->createTextNode( $maxValue ) );
412 $attributeParametersNode->appendChild( $maxValueNode );
413 }
414 }
415
416 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
417 {
418 $defaultValue = $attributeParametersNode->getElementsByTagName( 'default-value' )->item( 0 )->textContent;
419 $minValue = $attributeParametersNode->getElementsByTagName( 'min-value' )->item( 0 )->textContent;
420 $maxValue = $attributeParametersNode->getElementsByTagName( 'max-value' )->item( 0 )->textContent;
421
422 if ( strlen( $minValue ) > 0 and strlen( $maxValue ) > 0 )
423 $minMaxState = self::HAS_MIN_MAX_VALUE;
424 else if ( strlen( $minValue ) > 0 )
425 $minMaxState = self::HAS_MIN_VALUE;
426 else if ( strlen( $maxValue ) > 0 )
427 $minMaxState = self::HAS_MAX_VALUE;
428 else
429 $minMaxState = self::NO_MIN_MAX_VALUE;
430
431 $classAttribute->setAttribute( self::DEFAULT_FIELD, $defaultValue );
432 $classAttribute->setAttribute( self::MIN_FIELD, $minValue );
433 $classAttribute->setAttribute( self::MAX_FIELD, $maxValue );
434 $classAttribute->setAttribute( self::INPUT_STATE_FIELD, $minMaxState );
435 }
436
437 function supportsBatchInitializeObjectAttribute()
438 {
439 return true;
440 }
441
442 function batchInitializeObjectAttributeData( $classAttribute )
443 {
444 $default = $classAttribute->attribute( 'data_float3' );
445 if ( $default !== 0 )
446 {
447 return array( 'data_float' => $default );
448 }
449
450 return array();
451 }
452
455 public $FloatValidator;
456 }
457
458 eZDataType::register( eZFloatType::DATA_TYPE_STRING, "eZFloatType" );
459
460 ?>
eZDataType
Base class for content datatypes.
Definition: ezdatatype.php:46
eZDataType\register
static register( $dataTypeString, $className)
Definition: ezdatatype.php:203
eZDebug\writeNotice
static writeNotice( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:459
eZFloatType
Stores a float value.
Definition: ezfloattype.php:19
eZFloatType\INPUT_STATE_FIELD
const INPUT_STATE_FIELD
Definition: ezfloattype.php:27
eZFloatType\fetchObjectAttributeHTTPInput
fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezfloattype.php:68
eZFloatType\MIN_FIELD
const MIN_FIELD
Definition: ezfloattype.php:21
eZFloatType\fromString
fromString( $contentObjectAttribute, $string)
Definition: ezfloattype.php:386
eZFloatType\$FloatValidator
$FloatValidator
Definition: ezfloattype.php:455
eZFloatType\unserializeContentClassAttribute
unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezfloattype.php:416
eZFloatType\storeObjectAttribute
storeObjectAttribute( $attribute)
Definition: ezfloattype.php:207
eZFloatType\validateFloatHTTPInput
validateFloatHTTPInput( $data, $contentObjectAttribute, $classAttribute)
Definition: ezfloattype.php:95
eZFloatType\metaData
metaData( $contentObjectAttribute)
Definition: ezfloattype.php:351
eZFloatType\storeClassAttribute
storeClassAttribute( $attribute, $version)
Definition: ezfloattype.php:347
eZFloatType\__construct
__construct()
Definition: ezfloattype.php:33
eZFloatType\NO_MIN_MAX_VALUE
const NO_MIN_MAX_VALUE
Definition: ezfloattype.php:28
eZFloatType\HAS_MIN_MAX_VALUE
const HAS_MIN_MAX_VALUE
Definition: ezfloattype.php:31
eZFloatType\MAX_VARIABLE
const MAX_VARIABLE
Definition: ezfloattype.php:24
eZFloatType\HAS_MIN_VALUE
const HAS_MIN_VALUE
Definition: ezfloattype.php:29
eZFloatType\MAX_FIELD
const MAX_FIELD
Definition: ezfloattype.php:23
eZFloatType\validateClassAttributeHTTPInput
validateClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezfloattype.php:261
eZFloatType\batchInitializeObjectAttributeData
batchInitializeObjectAttributeData( $classAttribute)
Definition: ezfloattype.php:442
eZFloatType\MIN_VARIABLE
const MIN_VARIABLE
Definition: ezfloattype.php:22
eZFloatType\fetchClassAttributeHTTPInput
fetchClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezfloattype.php:211
eZFloatType\objectAttributeContent
objectAttributeContent( $contentObjectAttribute)
Definition: ezfloattype.php:359
eZFloatType\initializeObjectAttribute
initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute)
Definition: ezfloattype.php:44
eZFloatType\supportsBatchInitializeObjectAttribute
supportsBatchInitializeObjectAttribute()
Definition: ezfloattype.php:437
eZFloatType\fixupObjectAttributeHTTPInput
fixupObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezfloattype.php:203
eZFloatType\HAS_MAX_VALUE
const HAS_MAX_VALUE
Definition: ezfloattype.php:30
eZFloatType\validateObjectAttributeHTTPInput
validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezfloattype.php:180
eZFloatType\DEFAULT_VARIABLE
const DEFAULT_VARIABLE
Definition: ezfloattype.php:26
eZFloatType\serializeContentClassAttribute
serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezfloattype.php:391
eZFloatType\DATA_TYPE_STRING
const DATA_TYPE_STRING
Definition: ezfloattype.php:20
eZFloatType\toString
toString( $contentObjectAttribute)
Definition: ezfloattype.php:381
eZFloatType\fixupClassAttributeHTTPInput
fixupClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezfloattype.php:323
eZFloatType\DEFAULT_FIELD
const DEFAULT_FIELD
Definition: ezfloattype.php:25
eZFloatType\hasObjectAttributeContent
hasObjectAttributeContent( $contentObjectAttribute)
Definition: ezfloattype.php:373
eZFloatType\title
title( $contentObjectAttribute, $name=null)
Definition: ezfloattype.php:368
eZFloatValidator
The class eZFloatValidator does.
Definition: ezfloatvalidator.php:18
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
eZLocale\instance
static instance( $localeString=false)
Definition: ezlocale.php:1536
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+.