|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZDateTimeType class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 /*! 00012 \class eZDateTimeType ezdatetimetype.php 00013 \ingroup eZDatatype 00014 \brief Stores a date and time value 00015 00016 */ 00017 00018 class eZDateTimeType extends eZDataType 00019 { 00020 const DATA_TYPE_STRING = 'ezdatetime'; 00021 00022 const DEFAULT_FIELD = 'data_int1'; 00023 00024 const USE_SECONDS_FIELD = 'data_int2'; 00025 00026 const ADJUSTMENT_FIELD = 'data_text5'; 00027 00028 const DEFAULT_EMTPY = 0; 00029 00030 const DEFAULT_CURRENT_DATE = 1; 00031 00032 const DEFAULT_ADJUSTMENT = 2; 00033 00034 function eZDateTimeType() 00035 { 00036 $this->eZDataType( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', "Date and time", 'Datatype name' ), 00037 array( 'serialize_supported' => true ) ); 00038 } 00039 00040 /*! 00041 Private method only for use inside this class 00042 */ 00043 function validateDateTimeHTTPInput( $day, $month, $year, $hour, $minute, $second, $contentObjectAttribute ) 00044 { 00045 $state = eZDateTimeValidator::validateDate( $day, $month, $year ); 00046 if ( $state == eZInputValidator::STATE_INVALID ) 00047 { 00048 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 00049 'Date is not valid.' ) ); 00050 return eZInputValidator::STATE_INVALID; 00051 } 00052 00053 $state = eZDateTimeValidator::validateTime( $hour, $minute, $second ); 00054 00055 if ( $state == eZInputValidator::STATE_INVALID ) 00056 { 00057 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 00058 'Time is not valid.' ) ); 00059 return eZInputValidator::STATE_INVALID; 00060 } 00061 return $state; 00062 } 00063 00064 /*! 00065 Validates the input and returns true if the input was 00066 valid for this datatype. 00067 */ 00068 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) 00069 { 00070 $classAttribute = $contentObjectAttribute->contentClassAttribute(); 00071 $useSeconds = ( $classAttribute->attribute( self::USE_SECONDS_FIELD ) == 1 ); 00072 00073 if ( $http->hasPostVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ) and 00074 $http->hasPostVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ) and 00075 $http->hasPostVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ) and 00076 $http->hasPostVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ) and 00077 $http->hasPostVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ) and 00078 ( !$useSeconds or $http->hasPostVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) ) ) 00079 { 00080 $year = $http->postVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ); 00081 $month = $http->postVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ); 00082 $day = $http->postVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ); 00083 $hour = $http->postVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ); 00084 $minute = $http->postVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ); 00085 $second = $useSeconds ? $http->postVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) : 0; 00086 00087 if ( $year == '' or 00088 $month == '' or 00089 $day == '' or 00090 $hour == '' or 00091 $minute == '' or 00092 ( $useSeconds and $second == '' ) ) 00093 { 00094 if ( !( $year == '' and 00095 $month == '' and 00096 $day == '' and 00097 $hour == '' and 00098 $minute == '' and 00099 ( !$useSeconds or $second == '' ) ) or 00100 ( !$classAttribute->attribute( 'is_information_collector' ) and 00101 $contentObjectAttribute->validateIsRequired() ) ) 00102 { 00103 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 00104 'Missing datetime input.' ) ); 00105 return eZInputValidator::STATE_INVALID; 00106 } 00107 else 00108 return eZInputValidator::STATE_ACCEPTED; 00109 } 00110 else 00111 { 00112 return $this->validateDateTimeHTTPInput( $day, $month, $year, $hour, $minute, $second, $contentObjectAttribute ); 00113 } 00114 } 00115 else if ( !$classAttribute->attribute( 'is_information_collector' ) and $contentObjectAttribute->validateIsRequired() ) 00116 { 00117 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 'Missing datetime input.' ) ); 00118 return eZInputValidator::STATE_INVALID; 00119 } 00120 else 00121 return eZInputValidator::STATE_ACCEPTED; 00122 } 00123 00124 /*! 00125 Fetches the http post var integer input and stores it in the data instance. 00126 */ 00127 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) 00128 { 00129 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute(); 00130 $useSeconds = ( $contentClassAttribute->attribute( self::USE_SECONDS_FIELD ) == 1 ); 00131 00132 if ( $http->hasPostVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ) and 00133 $http->hasPostVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ) and 00134 $http->hasPostVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ) and 00135 $http->hasPostVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ) and 00136 $http->hasPostVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ) and 00137 ( !$useSeconds or $http->hasPostVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) ) ) 00138 { 00139 $year = $http->postVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ); 00140 $month = $http->postVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ); 00141 $day = $http->postVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ); 00142 $hour = $http->postVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ); 00143 $minute = $http->postVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ); 00144 $second = $useSeconds ? $http->postVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) : 0; 00145 00146 $dateTime = new eZDateTime(); 00147 00148 if ( ( $year == '' and $month == '' and $day == '' and 00149 $hour == '' and $minute == '' and ( !$useSeconds or $second == '' ) ) or 00150 !checkdate( $month, $day, $year ) or $year < 1970 ) 00151 { 00152 $dateTime->setTimeStamp( 0 ); 00153 } 00154 else 00155 { 00156 $dateTime->setMDYHMS( $month, $day, $year, $hour, $minute, $second ); 00157 } 00158 00159 $contentObjectAttribute->setAttribute( 'data_int', $dateTime->timeStamp() ); 00160 return true; 00161 } 00162 return false; 00163 } 00164 00165 function validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttribute ) 00166 { 00167 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute(); 00168 $useSeconds = ( $contentClassAttribute->attribute( self::USE_SECONDS_FIELD ) == 1 ); 00169 00170 if ( $http->hasPostVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ) and 00171 $http->hasPostVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ) and 00172 $http->hasPostVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ) and 00173 $http->hasPostVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ) and 00174 $http->hasPostVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ) and 00175 ( !$useSeconds or $http->hasPostVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) ) ) 00176 00177 { 00178 $year = $http->postVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ); 00179 $month = $http->postVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ); 00180 $day = $http->postVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ); 00181 $hour = $http->postVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ); 00182 $minute = $http->postVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ); 00183 $second = $useSeconds ? $http->postVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) : 0; 00184 00185 if ( $year == '' or 00186 $month == '' or 00187 $day == '' or 00188 $hour == '' or 00189 $minute == '' or 00190 ( $useSeconds and $second == '' ) ) 00191 { 00192 if ( !( $year == '' and 00193 $month == '' and 00194 $day == '' and 00195 $hour == '' and 00196 $minute == '' and 00197 ( !$useSeconds or $second == '' ) ) or 00198 $contentObjectAttribute->validateIsRequired() ) 00199 { 00200 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 00201 'Missing datetime input.' ) ); 00202 return eZInputValidator::STATE_INVALID; 00203 } 00204 else 00205 return eZInputValidator::STATE_ACCEPTED; 00206 } 00207 else 00208 { 00209 return $this->validateDateTimeHTTPInput( $day, $month, $year, $hour, $minute, $second, $contentObjectAttribute ); 00210 } 00211 } 00212 else 00213 return eZInputValidator::STATE_INVALID; 00214 } 00215 00216 /*! 00217 Fetches the http post variables for collected information 00218 */ 00219 function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $contentObjectAttribute ) 00220 { 00221 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute(); 00222 $useSeconds = ( $contentClassAttribute->attribute( self::USE_SECONDS_FIELD ) == 1 ); 00223 00224 if ( $http->hasPostVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ) and 00225 $http->hasPostVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ) and 00226 $http->hasPostVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ) and 00227 $http->hasPostVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ) and 00228 $http->hasPostVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ) and 00229 ( !$useSeconds or $http->hasPostVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) ) ) 00230 { 00231 $year = $http->postVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ); 00232 $month = $http->postVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ); 00233 $day = $http->postVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ); 00234 $hour = $http->postVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ); 00235 $minute = $http->postVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ); 00236 $second = $useSeconds ? $http->postVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) : 0; 00237 00238 $dateTime = new eZDateTime(); 00239 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute(); 00240 if ( ( $year == '' and $month == ''and $day == '' and 00241 $hour == '' and $minute == '' and ( !$useSeconds or $second == '' ) ) or 00242 !checkdate( $month, $day, $year ) or $year < 1970 ) 00243 { 00244 $dateTime->setTimeStamp( 0 ); 00245 } 00246 else 00247 { 00248 $dateTime->setMDYHMS( $month, $day, $year, $hour, $minute, $second ); 00249 } 00250 00251 $collectionAttribute->setAttribute( 'data_int', $dateTime->timeStamp() ); 00252 return true; 00253 } 00254 return false; 00255 } 00256 00257 /*! 00258 Returns the content. 00259 */ 00260 function objectAttributeContent( $contentObjectAttribute ) 00261 { 00262 $dateTime = new eZDateTime(); 00263 $stamp = $contentObjectAttribute->attribute( 'data_int' ); 00264 $dateTime->setTimeStamp( $stamp ); 00265 return $dateTime; 00266 } 00267 00268 function isIndexable() 00269 { 00270 return true; 00271 } 00272 00273 function isInformationCollector() 00274 { 00275 return true; 00276 } 00277 00278 /*! 00279 Returns the meta data used for storing search indeces. 00280 */ 00281 function metaData( $contentObjectAttribute ) 00282 { 00283 return (int)$contentObjectAttribute->attribute( 'data_int' ); 00284 } 00285 /*! 00286 \return string representation of an contentobjectattribute data for simplified export 00287 00288 */ 00289 function toString( $contentObjectAttribute ) 00290 { 00291 return $contentObjectAttribute->attribute( 'data_int' ); 00292 } 00293 00294 function fromString( $contentObjectAttribute, $string ) 00295 { 00296 return $contentObjectAttribute->setAttribute( 'data_int', $string ); 00297 } 00298 00299 /*! 00300 Set class attribute value for template version 00301 */ 00302 function initializeClassAttribute( $classAttribute ) 00303 { 00304 if ( $classAttribute->attribute( self::DEFAULT_FIELD ) == null ) 00305 $classAttribute->setAttribute( self::DEFAULT_FIELD, 0 ); 00306 $classAttribute->store(); 00307 } 00308 00309 function parseXML( $xmlText ) 00310 { 00311 $dom = new DOMDocument; 00312 $success = $dom->loadXML( $xmlText ); 00313 return $dom; 00314 } 00315 00316 function classAttributeContent( $classAttribute ) 00317 { 00318 $xmlText = $classAttribute->attribute( 'data_text5' ); 00319 if ( trim( $xmlText ) == '' ) 00320 { 00321 $classAttrContent = eZDateTimeType::defaultClassAttributeContent(); 00322 return $classAttrContent; 00323 } 00324 $doc = eZDateTimeType::parseXML( $xmlText ); 00325 $root = $doc->documentElement; 00326 $type = $root->getElementsByTagName( 'year' )->item( 0 ); 00327 if ( $type ) 00328 { 00329 $content['year'] = $type->getAttribute( 'value' ); 00330 } 00331 $type = $root->getElementsByTagName( 'month' )->item( 0 ); 00332 if ( $type ) 00333 { 00334 $content['month'] = $type->getAttribute( 'value' ); 00335 } 00336 $type = $root->getElementsByTagName( 'day' )->item( 0 ); 00337 if ( $type ) 00338 { 00339 $content['day'] = $type->getAttribute( 'value' ); 00340 } 00341 $type = $root->getElementsByTagName( 'hour' )->item( 0 ); 00342 if ( $type ) 00343 { 00344 $content['hour'] = $type->getAttribute( 'value' ); 00345 } 00346 $type = $root->getElementsByTagName( 'minute' )->item( 0 ); 00347 if ( $type ) 00348 { 00349 $content['minute'] = $type->getAttribute( 'value' ); 00350 } 00351 $type = $root->getElementsByTagName( 'second' )->item( 0 ); 00352 if ( $type ) 00353 { 00354 $content['second'] = $type->getAttribute( 'value' ); 00355 } 00356 return $content; 00357 } 00358 00359 function defaultClassAttributeContent() 00360 { 00361 return array( 'year' => '', 00362 'month' => '', 00363 'day' => '', 00364 'hour' => '', 00365 'minute' => '', 00366 'second' => '' ); 00367 } 00368 00369 /*! 00370 Sets the default value. 00371 */ 00372 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute ) 00373 { 00374 if ( $currentVersion != false ) 00375 { 00376 $dataInt = $originalContentObjectAttribute->attribute( "data_int" ); 00377 $contentObjectAttribute->setAttribute( "data_int", $dataInt ); 00378 } 00379 else 00380 { 00381 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute(); 00382 $defaultType = $contentClassAttribute->attribute( self::DEFAULT_FIELD ); 00383 if ( $defaultType == self::DEFAULT_CURRENT_DATE ) 00384 { 00385 $contentObjectAttribute->setAttribute( "data_int", time() ); 00386 } 00387 else if ( $defaultType == self::DEFAULT_ADJUSTMENT ) 00388 { 00389 $adjustments = $this->classAttributeContent( $contentClassAttribute ); 00390 $value = new eZDateTime(); 00391 $secondAdjustment = $contentClassAttribute->attribute( self::USE_SECONDS_FIELD ) == 1 ? $adjustments['second'] : 0; 00392 $value->adjustDateTime( $adjustments['hour'], $adjustments['minute'], $secondAdjustment, $adjustments['month'], $adjustments['day'], $adjustments['year'] ); 00393 $contentObjectAttribute->setAttribute( "data_int", $value->timeStamp() ); 00394 } 00395 else 00396 $contentObjectAttribute->setAttribute( "data_int", 0 ); 00397 } 00398 } 00399 00400 function fetchClassAttributeHTTPInput( $http, $base, $classAttribute ) 00401 { 00402 $default = $base . "_ezdatetime_default_" . $classAttribute->attribute( 'id' ); 00403 if ( $http->hasPostVariable( $default ) ) 00404 { 00405 $defaultValue = $http->postVariable( $default ); 00406 $classAttribute->setAttribute( self::DEFAULT_FIELD, $defaultValue ); 00407 if ( $defaultValue == self::DEFAULT_ADJUSTMENT ) 00408 { 00409 $doc = new DOMDocument( '1.0', 'utf-8' ); 00410 $root = $doc->createElement( 'adjustment' ); 00411 $contentList = eZDateTimeType::contentObjectArrayXMLMap(); 00412 foreach ( $contentList as $key => $value ) 00413 { 00414 $postValue = $http->postVariable( $base . '_ezdatetime_' . $value . '_' . $classAttribute->attribute( 'id' ) ); 00415 unset( $elementType ); 00416 $elementType = $doc->createElement( $key ); 00417 $elementType->setAttribute( 'value', $postValue ); 00418 $root->appendChild( $elementType ); 00419 } 00420 $doc->appendChild( $root ); 00421 $docText = $doc->saveXML(); 00422 $classAttribute->setAttribute( self::ADJUSTMENT_FIELD , $docText ); 00423 } 00424 00425 $useSeconds = $base . "_ezdatetime_use_seconds_" . $classAttribute->attribute( 'id' ); 00426 $classAttribute->setAttribute( self::USE_SECONDS_FIELD, $http->hasPostVariable( $useSeconds ) ? 1 : 0 ); 00427 } 00428 00429 return true; 00430 } 00431 00432 function contentObjectArrayXMLMap() 00433 { 00434 return array( 'year' => 'year', 00435 'month' => 'month', 00436 'day' => 'day', 00437 'hour' => 'hour', 00438 'minute' => 'minute', 00439 'second' => 'second' ); 00440 } 00441 00442 00443 /*! 00444 Returns the date. 00445 */ 00446 function title( $contentObjectAttribute, $name = null ) 00447 { 00448 $locale = eZLocale::instance(); 00449 $retVal = $contentObjectAttribute->attribute( "data_int" ) == 0 ? '' : $locale->formatDateTime( $contentObjectAttribute->attribute( "data_int" ) ); 00450 return $retVal; 00451 } 00452 00453 function hasObjectAttributeContent( $contentObjectAttribute ) 00454 { 00455 return $contentObjectAttribute->attribute( "data_int" ) != 0; 00456 } 00457 00458 function sortKey( $contentObjectAttribute ) 00459 { 00460 return (int)$contentObjectAttribute->attribute( 'data_int' ); 00461 } 00462 00463 function sortKeyType() 00464 { 00465 return 'int'; 00466 } 00467 00468 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode ) 00469 { 00470 $dom = $attributeParametersNode->ownerDocument; 00471 $defaultValue = $classAttribute->attribute( self::DEFAULT_FIELD ); 00472 $defaultValueNode = $dom->createElement( 'default-value' ); 00473 00474 switch ( $defaultValue ) 00475 { 00476 case self::DEFAULT_CURRENT_DATE: 00477 { 00478 $defaultValueNode->setAttribute( 'type', 'current-date' ); 00479 } break; 00480 case self::DEFAULT_ADJUSTMENT: 00481 { 00482 $defaultValueNode->setAttribute( 'type', 'adjustment' ); 00483 00484 $adjustDOMValue = new DOMDocument( '1.0', 'utf-8' ); 00485 $adjustValue = $classAttribute->attribute( self::ADJUSTMENT_FIELD ); 00486 $success = $adjustDOMValue->loadXML( $adjustValue ); 00487 00488 if ( $success ) 00489 { 00490 $adjustmentNode = $adjustDOMValue->getElementsByTagName( 'adjustment' )->item( 0 ); 00491 00492 if ( $adjustmentNode ) 00493 { 00494 $importedAdjustmentNode = $dom->importNode( $adjustmentNode, true ); 00495 $defaultValueNode->appendChild( $importedAdjustmentNode ); 00496 } 00497 } 00498 } break; 00499 case self::DEFAULT_EMTPY: 00500 { 00501 $defaultValueNode->setAttribute( 'type', 'empty' ); 00502 } break; 00503 default: 00504 { 00505 eZDebug::writeError( 'Unknown type of DateTime default value. Empty type used instead.', __METHOD__ ); 00506 $defaultValueNode->setAttribute( 'type', 'empty' ); 00507 } break; 00508 } 00509 $attributeParametersNode->appendChild( $defaultValueNode ); 00510 00511 $useSeconds = $classAttribute->attribute( self::USE_SECONDS_FIELD ); 00512 $useSecondsNode = $dom->createElement( 'use-seconds' ); 00513 $useSecondsNode->appendChild( $dom->createTextNode( $useSeconds ) ); 00514 $attributeParametersNode->appendChild( $useSecondsNode ); 00515 } 00516 00517 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode ) 00518 { 00519 $defaultValue = ''; 00520 $defaultNode = $attributeParametersNode->getElementsByTagName( 'default-value' )->item( 0 ); 00521 if ( $defaultNode ) 00522 { 00523 $defaultValue = strtolower( $defaultNode->getAttribute( 'type' ) ); 00524 } 00525 switch ( $defaultValue ) 00526 { 00527 case 'current-date': 00528 { 00529 $classAttribute->setAttribute( self::DEFAULT_FIELD, self::DEFAULT_CURRENT_DATE ); 00530 } break; 00531 case 'adjustment': 00532 { 00533 $adjustmentValue = ''; 00534 $adjustmentNode = $defaultNode->getElementsByTagName( 'adjustment' )->item( 0 ); 00535 if ( $adjustmentNode ) 00536 { 00537 $adjustmentDOMValue = new DOMDocument( '1.0', 'utf-8' ); 00538 $importedAdjustmentNode = $adjustmentDOMValue->importNode( $adjustmentNode, true ); 00539 $adjustmentDOMValue->appendChild( $importedAdjustmentNode ); 00540 $adjustmentValue = $adjustmentDOMValue->saveXML(); 00541 } 00542 00543 $classAttribute->setAttribute( self::DEFAULT_FIELD, self::DEFAULT_ADJUSTMENT ); 00544 $classAttribute->setAttribute( self::ADJUSTMENT_FIELD, $adjustmentValue ); 00545 } break; 00546 case 'empty': 00547 { 00548 $classAttribute->setAttribute( self::DEFAULT_FIELD, self::DEFAULT_EMTPY ); 00549 } break; 00550 default: 00551 { 00552 eZDebug::writeError( 'Type of DateTime default value is not set. Empty type used as default.', __METHOD__ ); 00553 $classAttribute->setAttribute( self::DEFAULT_FIELD, self::DEFAULT_EMTPY ); 00554 } break; 00555 } 00556 00557 $useSecondsNode = $attributeParametersNode->getElementsByTagName( 'use-seconds' )->item( 0 ); 00558 if ( $useSecondsNode && $useSecondsNode->textContent === '1' ) 00559 { 00560 $classAttribute->setAttribute( self::USE_SECONDS_FIELD, 1 ); 00561 } 00562 } 00563 00564 /*! 00565 \return a DOM representation of the content object attribute 00566 */ 00567 function serializeContentObjectAttribute( $package, $objectAttribute ) 00568 { 00569 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute ); 00570 00571 $stamp = $objectAttribute->attribute( 'data_int' ); 00572 00573 if ( $stamp !== null ) 00574 { 00575 $dom = $node->ownerDocument; 00576 $dateTimeNode = $dom->createElement( 'date_time' ); 00577 $dateTimeNode->appendChild( $dom->createTextNode( eZDateUtils::rfc1123Date( $stamp ) ) ); 00578 $node->appendChild( $dateTimeNode ); 00579 } 00580 return $node; 00581 } 00582 00583 function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode ) 00584 { 00585 $dateTimeNode = $attributeNode->getElementsByTagName( 'date_time' )->item( 0 ); 00586 if ( is_object( $dateTimeNode ) ) 00587 { 00588 $timestamp = eZDateUtils::textToDate( $dateTimeNode->textContent ); 00589 $objectAttribute->setAttribute( 'data_int', $timestamp ); 00590 } 00591 } 00592 00593 function supportsBatchInitializeObjectAttribute() 00594 { 00595 return true; 00596 } 00597 00598 function batchInitializeObjectAttributeData( $classAttribute ) 00599 { 00600 $defaultType = $classAttribute->attribute( self::DEFAULT_FIELD ); 00601 00602 switch( $defaultType ) 00603 { 00604 case self::DEFAULT_CURRENT_DATE: 00605 { 00606 $default = time(); 00607 } break; 00608 00609 case self::DEFAULT_ADJUSTMENT: 00610 { 00611 $adjustments = $this->classAttributeContent( $classAttribute ); 00612 $value = new eZDateTime(); 00613 $secondAdjustment = $classAttribute->attribute( self::USE_SECONDS_FIELD ) == 1 ? $adjustments['second'] : 0; 00614 $value->adjustDateTime( $adjustments['hour'], $adjustments['minute'], $secondAdjustment, $adjustments['month'], $adjustments['day'], $adjustments['year'] ); 00615 00616 $default = $value->timeStamp(); 00617 } break; 00618 00619 default: 00620 { 00621 $default = 0; 00622 } 00623 } 00624 00625 return array( 'data_int' => $default, 'sort_key_int' => $default ); 00626 } 00627 } 00628 00629 eZDataType::register( eZDateTimeType::DATA_TYPE_STRING, "eZDateTimeType" ); 00630 00631 ?>