[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZIntegerType class 4 // 5 // SOFTWARE NAME: eZ publish 6 // SOFTWARE RELEASE: 3.9.0 7 // BUILD VERSION: 17785 8 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 9 // SOFTWARE LICENSE: GNU General Public License v2.0 10 // NOTICE: > 11 // This program is free software; you can redistribute it and/or 12 // modify it under the terms of version 2.0 of the GNU General 13 // Public License as published by the Free Software Foundation. 14 // 15 // This program is distributed in the hope that it will be useful, 16 // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 // GNU General Public License for more details. 19 // 20 // You should have received a copy of version 2.0 of the GNU General 21 // Public License along with this program; if not, write to the Free 22 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 // MA 02110-1301, USA. 24 // 25 // 26 27 /*! 28 \class eZIntegerType ezintegertype.php 29 \ingroup eZDatatype 30 \brief A content datatype which handles integers 31 32 It provides the functionality to work as an integer and handles 33 class definition input, object definition input and object viewing. 34 35 It uses the spare field data_int in a content object attribute for storing 36 the attribute data. 37 */ 38 39 include_once ( "kernel/classes/ezdatatype.php" ); 40 include_once ( "lib/ezutils/classes/ezintegervalidator.php" ); 41 42 define( "EZ_DATATYPESTRING_INTEGER", "ezinteger" ); 43 define( "EZ_DATATYPESTRING_MIN_VALUE_FIELD", "data_int1" ); 44 define( "EZ_DATATYPESTRING_MIN_VALUE_VARIABLE", "_ezinteger_min_integer_value_" ); 45 define( "EZ_DATATYPESTRING_MAX_VALUE_FIELD", "data_int2" ); 46 define( "EZ_DATATYPESTRING_MAX_VALUE_VARIABLE", "_ezinteger_max_integer_value_" ); 47 define( "EZ_DATATYPESTRING_DEFAULT_VALUE_FIELD", "data_int3" ); 48 define( "EZ_DATATYPESTRING_DEFAULT_VALUE_VARIABLE", "_ezinteger_default_value_" ); 49 define( "EZ_DATATYPESTRING_INTEGER_INPUT_STATE_FIELD", "data_int4" ); 50 define( "EZ_INTEGER_NO_MIN_MAX_VALUE", 0 ); 51 define( "EZ_INTEGER_HAS_MIN_VALUE", 1 ); 52 define( "EZ_INTEGER_HAS_MAX_VALUE", 2 ); 53 define( "EZ_INTEGER_HAS_MIN_MAX_VALUE", 3 ); 54 55 56 class eZIntegerType extends eZDataType 57 { 58 function eZIntegerType() 59 { 60 $this->eZDataType( EZ_DATATYPESTRING_INTEGER, ezi18n( 'kernel/classes/datatypes', "Integer", 'Datatype name' ), 61 array( 'serialize_supported' => true, 62 'object_serialize_map' => array( 'data_int' => 'value' ) ) ); 63 $this->IntegerValidator = new eZIntegerValidator(); 64 } 65 66 /*! 67 Private method, only for using inside this class. 68 */ 69 function validateIntegerHTTPInput( $data, &$contentObjectAttribute, &$classAttribute ) 70 { 71 $min = $classAttribute->attribute( EZ_DATATYPESTRING_MIN_VALUE_FIELD ); 72 $max = $classAttribute->attribute( EZ_DATATYPESTRING_MAX_VALUE_FIELD ); 73 $input_state = $classAttribute->attribute( EZ_DATATYPESTRING_INTEGER_INPUT_STATE_FIELD ); 74 75 switch( $input_state ) 76 { 77 case EZ_INTEGER_NO_MIN_MAX_VALUE: 78 { 79 $this->IntegerValidator->setRange( false, false ); 80 $state = $this->IntegerValidator->validate( $data ); 81 if( $state === EZ_INPUT_VALIDATOR_STATE_INVALID || $state === EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE ) 82 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 83 'The input is not a valid integer.' ) ); 84 else 85 return $state; 86 } break; 87 case EZ_INTEGER_HAS_MIN_VALUE: 88 { 89 $this->IntegerValidator->setRange( $min, false ); 90 $state = $this->IntegerValidator->validate( $data ); 91 if( $state === EZ_INPUT_VALIDATOR_STATE_ACCEPTED ) 92 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 93 else 94 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 95 'The number must be greater than %1' ), 96 $min ); 97 } break; 98 case EZ_INTEGER_HAS_MAX_VALUE: 99 { 100 $this->IntegerValidator->setRange( false, $max ); 101 $state = $this->IntegerValidator->validate( $data ); 102 if( $state===1 ) 103 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 104 else 105 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 106 'The number must be less than %1' ), 107 $max ); 108 } break; 109 case EZ_INTEGER_HAS_MIN_MAX_VALUE: 110 { 111 $this->IntegerValidator->setRange( $min, $max ); 112 $state = $this->IntegerValidator->validate( $data ); 113 if( $state===1 ) 114 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 115 else 116 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 117 'The number is not within the required range %1 - %2' ), 118 $min, $max ); 119 } break; 120 } 121 122 return EZ_INPUT_VALIDATOR_STATE_INVALID; 123 124 } 125 126 /*! 127 Validates the input and returns true if the input was 128 valid for this datatype. 129 */ 130 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute ) 131 { 132 if ( $http->hasPostVariable( $base . "_data_integer_" . $contentObjectAttribute->attribute( "id" ) ) ) 133 { 134 $data = $http->postVariable( $base . "_data_integer_" . $contentObjectAttribute->attribute( "id" ) ); 135 $data = str_replace(" ", "", $data ); 136 $classAttribute =& $contentObjectAttribute->contentClassAttribute(); 137 138 if ( $data == "" ) 139 { 140 if ( !$classAttribute->attribute( 'is_information_collector' ) and 141 $contentObjectAttribute->validateIsRequired() ) 142 { 143 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 144 'Input required.' ) ); 145 return EZ_INPUT_VALIDATOR_STATE_INVALID; 146 } 147 else 148 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 149 } 150 else 151 { 152 return $this->validateIntegerHTTPInput( $data, $contentObjectAttribute, $classAttribute ); 153 } 154 } 155 else 156 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 157 } 158 159 function fixupObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute ) 160 { 161 } 162 163 /*! 164 Sets the default value. 165 */ 166 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute ) 167 { 168 if ( $currentVersion != false ) 169 { 170 // $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" ); 171 // $currentObjectAttribute = eZContentObjectAttribute::fetch( $contentObjectAttributeID, 172 // $currentVersion ); 173 $dataInt = $originalContentObjectAttribute->attribute( "data_int" ); 174 $contentObjectAttribute->setAttribute( "data_int", $dataInt ); 175 } 176 else 177 { 178 $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute(); 179 $default = $contentClassAttribute->attribute( "data_int3" ); 180 if ( $default !== 0 ) 181 { 182 $contentObjectAttribute->setAttribute( "data_int", $default ); 183 } 184 } 185 } 186 187 /*! 188 Fetches the http post var integer input and stores it in the data instance. 189 */ 190 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute ) 191 { 192 if ( $http->hasPostVariable( $base . "_data_integer_" . $contentObjectAttribute->attribute( "id" ) ) ) 193 { 194 $data = $http->postVariable( $base . "_data_integer_" . $contentObjectAttribute->attribute( "id" ) ); 195 $data = trim( $data ) != '' ? $data : null; 196 $contentObjectAttribute->setAttribute( "data_int", $data ); 197 return true; 198 } 199 return false; 200 } 201 202 /*! 203 \reimp 204 */ 205 function validateCollectionAttributeHTTPInput( &$http, $base, &$contentObjectAttribute ) 206 { 207 if ( $http->hasPostVariable( $base . "_data_integer_" . $contentObjectAttribute->attribute( "id" ) ) ) 208 { 209 $data = $http->postVariable( $base . "_data_integer_" . $contentObjectAttribute->attribute( "id" ) ); 210 $data = str_replace(" ", "", $data ); 211 $classAttribute =& $contentObjectAttribute->contentClassAttribute(); 212 213 if ( $data == "" ) 214 { 215 if ( $contentObjectAttribute->validateIsRequired() ) 216 { 217 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 218 'Input required.' ) ); 219 return EZ_INPUT_VALIDATOR_STATE_INVALID; 220 } 221 else 222 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 223 } 224 else 225 { 226 return $this->validateIntegerHTTPInput( $data, $contentObjectAttribute, $classAttribute ); 227 } 228 } 229 else 230 return EZ_INPUT_VALIDATOR_STATE_INVALID; 231 } 232 233 /*! 234 Fetches the http post variables for collected information 235 */ 236 function fetchCollectionAttributeHTTPInput( &$collection, &$collectionAttribute, &$http, $base, &$contentObjectAttribute ) 237 { 238 if ( $http->hasPostVariable( $base . "_data_integer_" . $contentObjectAttribute->attribute( "id" ) ) ) 239 { 240 $data = $http->postVariable( $base . "_data_integer_" . $contentObjectAttribute->attribute( "id" ) ); 241 $collectionAttribute->setAttribute( "data_int", $data ); 242 return true; 243 } 244 return false; 245 } 246 247 /*! 248 Does nothing, the data is already present in the attribute. 249 */ 250 function storeObjectAttribute( &$object_attribute ) 251 { 252 } 253 254 function storeClassAttribute( &$attribute, $version ) 255 { 256 } 257 258 /*! 259 \reimp 260 */ 261 function validateClassAttributeHTTPInput( &$http, $base, &$classAttribute ) 262 { 263 $minValueName = $base . EZ_DATATYPESTRING_MIN_VALUE_VARIABLE . $classAttribute->attribute( "id" ); 264 $maxValueName = $base . EZ_DATATYPESTRING_MAX_VALUE_VARIABLE . $classAttribute->attribute( "id" ); 265 $defaultValueName = $base . EZ_DATATYPESTRING_DEFAULT_VALUE_VARIABLE . $classAttribute->attribute( "id" ); 266 267 if ( $http->hasPostVariable( $minValueName ) and 268 $http->hasPostVariable( $maxValueName ) and 269 $http->hasPostVariable( $defaultValueName ) ) 270 { 271 $minValueValue = $http->postVariable( $minValueName ); 272 $minValueValue = str_replace(" ", "", $minValueValue ); 273 $maxValueValue = $http->postVariable( $maxValueName ); 274 $maxValueValue = str_replace(" ", "", $maxValueValue ); 275 $defaultValueValue = $http->postVariable( $defaultValueName ); 276 $defaultValueValue = str_replace(" ", "", $defaultValueValue ); 277 278 if ( ( $minValueValue == "" ) && ( $maxValueValue == "") ){ 279 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 280 } 281 else if ( ( $minValueValue == "" ) && ( $maxValueValue !== "") ) 282 { 283 $max_state = $this->IntegerValidator->validate( $maxValueValue ); 284 return $max_state; 285 } 286 else if ( ( $minValueValue !== "" ) && ( $maxValueValue == "") ) 287 { 288 $min_state = $this->IntegerValidator->validate( $minValueValue ); 289 return $min_state; 290 } 291 else 292 { 293 $min_state = $this->IntegerValidator->validate( $minValueValue ); 294 $max_state = $this->IntegerValidator->validate( $maxValueValue ); 295 if ( ( $min_state == EZ_INPUT_VALIDATOR_STATE_ACCEPTED ) and 296 ( $max_state == EZ_INPUT_VALIDATOR_STATE_ACCEPTED ) ) 297 { 298 if ($minValueValue <= $maxValueValue) 299 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 300 else 301 { 302 $state = EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE; 303 eZDebug::writeNotice( "Integer minimum value great than maximum value." ); 304 return $state; 305 } 306 } 307 } 308 309 if ($defaultValueValue == ""){ 310 $default_state = EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 311 } 312 else 313 $default_state = $this->IntegerValidator->validate( $defaultValueValue ); 314 } 315 316 return EZ_INPUT_VALIDATOR_STATE_INVALID; 317 } 318 319 /*! 320 \reimp 321 */ 322 function fixupClassAttributeHTTPInput( &$http, $base, &$classAttribute ) 323 { 324 $minValueName = $base . EZ_DATATYPESTRING_MIN_VALUE_VARIABLE . $classAttribute->attribute( "id" ); 325 $maxValueName = $base . EZ_DATATYPESTRING_MAX_VALUE_VARIABLE . $classAttribute->attribute( "id" ); 326 if ( $http->hasPostVariable( $minValueName ) and $http->hasPostVariable( $maxValueName ) ) 327 { 328 $minValueValue = $http->postVariable( $minValueName ); 329 $minValueValue = $this->IntegerValidator->fixup( $minValueValue ); 330 $http->setPostVariable( $minValueName, $minValueValue ); 331 332 $maxValueValue = $http->postVariable( $maxValueName ); 333 $maxValueValue = $this->IntegerValidator->fixup( $maxValueValue ); 334 $http->setPostVariable( $maxValueName, $maxValueValue ); 335 336 if ($minValueValue > $maxValueValue) 337 { 338 $this->IntegerValidator->setRange( $minValueValue, false ); 339 $maxValueValue = $this->IntegerValidator->fixup( $maxValueValue ); 340 $http->setPostVariable( $maxValueName, $maxValueValue ); 341 } 342 } 343 } 344 345 /*! 346 \reimp 347 */ 348 function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute ) 349 { 350 $minValueName = $base . EZ_DATATYPESTRING_MIN_VALUE_VARIABLE . $classAttribute->attribute( "id" ); 351 $maxValueName = $base . EZ_DATATYPESTRING_MAX_VALUE_VARIABLE . $classAttribute->attribute( "id" ); 352 $defaultValueName = $base . EZ_DATATYPESTRING_DEFAULT_VALUE_VARIABLE . $classAttribute->attribute( "id" ); 353 354 if ( $http->hasPostVariable( $minValueName ) and 355 $http->hasPostVariable( $maxValueName ) and 356 $http->hasPostVariable( $defaultValueName ) ) 357 { 358 $minValueValue = $http->postVariable( $minValueName ); 359 $minValueValue = str_replace(" ", "", $minValueValue ); 360 $maxValueValue = $http->postVariable( $maxValueName ); 361 $maxValueValue = str_replace(" ", "", $maxValueValue ); 362 $defaultValueValue = $http->postVariable( $defaultValueName ); 363 $defaultValueValue = str_replace(" ", "", $defaultValueValue ); 364 365 $classAttribute->setAttribute( EZ_DATATYPESTRING_MIN_VALUE_FIELD, $minValueValue ); 366 $classAttribute->setAttribute( EZ_DATATYPESTRING_MAX_VALUE_FIELD, $maxValueValue ); 367 $classAttribute->setAttribute( EZ_DATATYPESTRING_DEFAULT_VALUE_FIELD, $defaultValueValue ); 368 369 if ( ( $minValueValue == "" ) && ( $maxValueValue == "") ){ 370 $input_state = EZ_INTEGER_NO_MIN_MAX_VALUE; 371 $classAttribute->setAttribute( EZ_DATATYPESTRING_INTEGER_INPUT_STATE_FIELD, $input_state ); 372 } 373 else if ( ( $minValueValue == "" ) && ( $maxValueValue !== "") ) 374 { 375 $input_state = EZ_INTEGER_HAS_MAX_VALUE; 376 $classAttribute->setAttribute( EZ_DATATYPESTRING_INTEGER_INPUT_STATE_FIELD, $input_state ); 377 } 378 else if ( ( $minValueValue !== "" ) && ( $maxValueValue == "") ) 379 { 380 $input_state = EZ_INTEGER_HAS_MIN_VALUE; 381 $classAttribute->setAttribute( EZ_DATATYPESTRING_INTEGER_INPUT_STATE_FIELD, $input_state ); 382 } 383 else 384 { 385 $input_state = EZ_INTEGER_HAS_MIN_MAX_VALUE; 386 $classAttribute->setAttribute( EZ_DATATYPESTRING_INTEGER_INPUT_STATE_FIELD, $input_state ); 387 } 388 return true; 389 } 390 return false; 391 } 392 393 /*! 394 Returns the content. 395 */ 396 function &objectAttributeContent( &$contentObjectAttribute ) 397 { 398 return $contentObjectAttribute->attribute( "data_int" ); 399 } 400 401 402 /*! 403 Returns the meta data used for storing search indeces. 404 */ 405 function metaData( $contentObjectAttribute ) 406 { 407 return $contentObjectAttribute->attribute( "data_int" ); 408 } 409 /*! 410 \return string representation of an contentobjectattribute data for simplified export 411 412 */ 413 function toString( $contentObjectAttribute ) 414 { 415 return $contentObjectAttribute->attribute( 'data_int' ); 416 } 417 418 function fromString( &$contentObjectAttribute, $string ) 419 { 420 return $contentObjectAttribute->setAttribute( 'data_int', $string ); 421 } 422 423 /*! 424 Returns the integer value. 425 */ 426 function title( &$contentObjectAttribute ) 427 { 428 return $contentObjectAttribute->attribute( "data_int" ); 429 } 430 431 function hasObjectAttributeContent( &$contentObjectAttribute ) 432 { 433 return true; 434 } 435 436 /*! 437 \reimp 438 */ 439 function isInformationCollector() 440 { 441 return true; 442 } 443 444 /*! 445 \return true if the datatype can be indexed 446 */ 447 function isIndexable() 448 { 449 return true; 450 } 451 452 /*! 453 \reimp 454 */ 455 function sortKey( &$contentObjectAttribute ) 456 { 457 return $contentObjectAttribute->attribute( 'data_int' ); 458 } 459 460 /*! 461 \reimp 462 */ 463 function sortKeyType() 464 { 465 return 'int'; 466 } 467 468 /*! 469 \reimp 470 */ 471 function serializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode ) 472 { 473 $defaultValue = $classAttribute->attribute( EZ_DATATYPESTRING_DEFAULT_VALUE_FIELD ); 474 $minValue = $classAttribute->attribute( EZ_DATATYPESTRING_MIN_VALUE_FIELD ); 475 $maxValue = $classAttribute->attribute( EZ_DATATYPESTRING_MAX_VALUE_FIELD ); 476 $minMaxState = $classAttribute->attribute( EZ_DATATYPESTRING_INTEGER_INPUT_STATE_FIELD ); 477 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'default-value', $defaultValue ) ); 478 if ( $minMaxState == EZ_INTEGER_HAS_MIN_VALUE or $minMaxState == EZ_INTEGER_HAS_MIN_MAX_VALUE ) 479 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'min-value', $minValue ) ); 480 if ( $minMaxState == EZ_INTEGER_HAS_MAX_VALUE or $minMaxState == EZ_INTEGER_HAS_MIN_MAX_VALUE ) 481 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'max-value', $maxValue ) ); 482 } 483 484 /*! 485 \reimp 486 */ 487 function unserializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode ) 488 { 489 $defaultValue = $attributeParametersNode->elementTextContentByName( 'default-value' ); 490 $minValue = $attributeParametersNode->elementTextContentByName( 'min-value' ); 491 $maxValue = $attributeParametersNode->elementTextContentByName( 'max-value' ); 492 493 if ( strlen( $minValue ) > 0 and strlen( $maxValue ) > 0 ) 494 $minMaxState = EZ_INTEGER_HAS_MIN_MAX_VALUE; 495 else if ( strlen( $minValue ) > 0 ) 496 $minMaxState = EZ_INTEGER_HAS_MIN_VALUE; 497 else if ( strlen( $maxValue ) > 0 ) 498 $minMaxState = EZ_INTEGER_HAS_MAX_VALUE; 499 else 500 $minMaxState = EZ_INTEGER_NO_MIN_MAX_VALUE; 501 502 $classAttribute->setAttribute( EZ_DATATYPESTRING_DEFAULT_VALUE_FIELD, $defaultValue ); 503 $classAttribute->setAttribute( EZ_DATATYPESTRING_MIN_VALUE_FIELD, $minValue ); 504 $classAttribute->setAttribute( EZ_DATATYPESTRING_MAX_VALUE_FIELD, $maxValue ); 505 $classAttribute->setAttribute( EZ_DATATYPESTRING_INTEGER_INPUT_STATE_FIELD, $minMaxState ); 506 } 507 508 /// \privatesection 509 /// The integer value validator 510 var $IntegerValidator; 511 } 512 513 eZDataType::register( EZ_DATATYPESTRING_INTEGER, "ezintegertype" ); 514 515 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |