[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZDateType class 4 // 5 // Created on: <26-Apr-2002 16:53:04 bf> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! 30 \class eZDateType ezdatetype.php 31 \ingroup eZDatatype 32 \brief Stores a date value 33 34 */ 35 36 include_once ( "kernel/classes/ezdatatype.php" ); 37 38 define( "EZ_DATATYPESTRING_DATE", "ezdate" ); 39 define( 'EZ_DATATYPESTRING_DATE_DEFAULT', 'data_int1' ); 40 define( 'EZ_DATATYPESTRING_DATE_DEFAULT_EMTPY', 0 ); 41 define( 'EZ_DATATYPESTRING_DATE_DEFAULT_CURRENT_DATE', 1 ); 42 include_once ( "lib/ezlocale/classes/ezdate.php" ); 43 44 class eZDateType extends eZDataType 45 { 46 function eZDateType() 47 { 48 $this->eZDataType( EZ_DATATYPESTRING_DATE, ezi18n( 'kernel/classes/datatypes', "Date", 'Datatype name' ), 49 array( 'serialize_supported' => true ) ); 50 } 51 52 53 function validateDateTimeHTTPInput( $day, $month, $year, &$contentObjectAttribute ) 54 { 55 include_once ( 'lib/ezutils/classes/ezdatetimevalidator.php' ); 56 $state = eZDateTimeValidator::validateDate( $day, $month, $year ); 57 if ( $state == EZ_INPUT_VALIDATOR_STATE_INVALID ) 58 { 59 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 60 'Date is not valid.' ) ); 61 return EZ_INPUT_VALIDATOR_STATE_INVALID; 62 } 63 return $state; 64 } 65 /*! 66 Validates the input and returns true if the input was 67 valid for this datatype. 68 */ 69 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute ) 70 { 71 if ( $http->hasPostVariable( $base . '_date_year_' . $contentObjectAttribute->attribute( 'id' ) ) and 72 $http->hasPostVariable( $base . '_date_month_' . $contentObjectAttribute->attribute( 'id' ) ) and 73 $http->hasPostVariable( $base . '_date_day_' . $contentObjectAttribute->attribute( 'id' ) ) ) 74 { 75 $year = $http->postVariable( $base . '_date_year_' . $contentObjectAttribute->attribute( 'id' ) ); 76 $month = $http->postVariable( $base . '_date_month_' . $contentObjectAttribute->attribute( 'id' ) ); 77 $day = $http->postVariable( $base . '_date_day_' . $contentObjectAttribute->attribute( 'id' ) ); 78 $classAttribute =& $contentObjectAttribute->contentClassAttribute(); 79 80 if ( $year == '' or $month == '' or $day == '' ) 81 { 82 if ( !( $year == '' and $month == '' and $day == '' ) or 83 ( !$classAttribute->attribute( 'is_information_collector' ) and 84 $contentObjectAttribute->validateIsRequired() ) ) 85 { 86 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 87 'Missing date input.' ) ); 88 return EZ_INPUT_VALIDATOR_STATE_INVALID; 89 } 90 else 91 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 92 } 93 else 94 { 95 return $this->validateDateTimeHTTPInput( $day, $month, $year, $contentObjectAttribute ); 96 } 97 } 98 else 99 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 100 } 101 102 /*! 103 Fetches the http post var integer input and stores it in the data instance. 104 */ 105 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute ) 106 { 107 if ( $http->hasPostVariable( $base . '_date_year_' . $contentObjectAttribute->attribute( 'id' ) ) and 108 $http->hasPostVariable( $base . '_date_month_' . $contentObjectAttribute->attribute( 'id' ) ) and 109 $http->hasPostVariable( $base . '_date_day_' . $contentObjectAttribute->attribute( 'id' ) ) ) 110 { 111 112 $year = $http->postVariable( $base . '_date_year_' . $contentObjectAttribute->attribute( 'id' ) ); 113 $month = $http->postVariable( $base . '_date_month_' . $contentObjectAttribute->attribute( 'id' ) ); 114 $day = $http->postVariable( $base . '_date_day_' . $contentObjectAttribute->attribute( 'id' ) ); 115 $date = new eZDate(); 116 $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute(); 117 118 if ( ( $year == '' and $month == '' and $day == '' ) or 119 !checkdate( $month, $day, $year ) or 120 $year < 1970 ) 121 { 122 $date->setTimeStamp( 0 ); 123 } 124 else 125 { 126 $date->setMDY( $month, $day, $year ); 127 } 128 129 $contentObjectAttribute->setAttribute( 'data_int', $date->timeStamp() ); 130 return true; 131 } 132 return false; 133 } 134 135 /*! 136 \reimp 137 */ 138 function validateCollectionAttributeHTTPInput( &$http, $base, &$contentObjectAttribute ) 139 { 140 if ( $http->hasPostVariable( $base . '_date_year_' . $contentObjectAttribute->attribute( 'id' ) ) and 141 $http->hasPostVariable( $base . '_date_month_' . $contentObjectAttribute->attribute( 'id' ) ) and 142 $http->hasPostVariable( $base . '_date_day_' . $contentObjectAttribute->attribute( 'id' ) ) ) 143 { 144 $year = $http->postVariable( $base . '_date_year_' . $contentObjectAttribute->attribute( 'id' ) ); 145 $month = $http->postVariable( $base . '_date_month_' . $contentObjectAttribute->attribute( 'id' ) ); 146 $day = $http->postVariable( $base . '_date_day_' . $contentObjectAttribute->attribute( 'id' ) ); 147 $classAttribute =& $contentObjectAttribute->contentClassAttribute(); 148 149 if ( $year == '' or $month == '' or $day == '' ) 150 { 151 if ( !( $year == '' and $month == '' and $day == '' ) or 152 $contentObjectAttribute->validateIsRequired() ) 153 { 154 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 155 'Missing date input.' ) ); 156 return EZ_INPUT_VALIDATOR_STATE_INVALID; 157 } 158 else 159 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 160 } 161 else 162 { 163 return $this->validateDateTimeHTTPInput( $day, $month, $year, $contentObjectAttribute ); 164 } 165 } 166 else 167 return EZ_INPUT_VALIDATOR_STATE_INVALID; 168 } 169 170 /*! 171 Fetches the http post variables for collected information 172 */ 173 function fetchCollectionAttributeHTTPInput( &$collection, &$collectionAttribute, &$http, $base, &$contentObjectAttribute ) 174 { 175 if ( $http->hasPostVariable( $base . '_date_year_' . $contentObjectAttribute->attribute( 'id' ) ) and 176 $http->hasPostVariable( $base . '_date_month_' . $contentObjectAttribute->attribute( 'id' ) ) and 177 $http->hasPostVariable( $base . '_date_day_' . $contentObjectAttribute->attribute( 'id' ) ) ) 178 { 179 180 $year = $http->postVariable( $base . '_date_year_' . $contentObjectAttribute->attribute( 'id' ) ); 181 $month = $http->postVariable( $base . '_date_month_' . $contentObjectAttribute->attribute( 'id' ) ); 182 $day = $http->postVariable( $base . '_date_day_' . $contentObjectAttribute->attribute( 'id' ) ); 183 $date = new eZDate(); 184 $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute(); 185 186 if ( ( $year == '' and $month == '' and $day == '' ) or 187 !checkdate( $month, $day, $year ) or 188 $year < 1970 ) 189 { 190 $date->setTimeStamp( 0 ); 191 } 192 else 193 { 194 $date->setMDY( $month, $day, $year ); 195 } 196 197 $collectionAttribute->setAttribute( 'data_int', $date->timeStamp() ); 198 return true; 199 } 200 return false; 201 } 202 203 /*! 204 Returns the content. 205 */ 206 function &objectAttributeContent( &$contentObjectAttribute ) 207 { 208 $date = new eZDate( ); 209 $stamp = $contentObjectAttribute->attribute( 'data_int' ); 210 $date->setTimeStamp( $stamp ); 211 return $date; 212 } 213 214 /*! 215 Set class attribute value for template version 216 */ 217 function initializeClassAttribute( &$classAttribute ) 218 { 219 if ( $classAttribute->attribute( EZ_DATATYPESTRING_DATE_DEFAULT ) == null ) 220 $classAttribute->setAttribute( EZ_DATATYPESTRING_DATE_DEFAULT, 0 ); 221 $classAttribute->store(); 222 } 223 224 /*! 225 Sets the default value. 226 */ 227 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute ) 228 { 229 if ( $currentVersion != false ) 230 { 231 $dataInt = $originalContentObjectAttribute->attribute( "data_int" ); 232 $contentObjectAttribute->setAttribute( "data_int", $dataInt ); 233 } 234 else 235 { 236 $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute(); 237 $defaultType = $contentClassAttribute->attribute( EZ_DATATYPESTRING_DATE_DEFAULT ); 238 if ( $defaultType == 1 ) 239 $contentObjectAttribute->setAttribute( "data_int", mktime() ); 240 } 241 } 242 243 function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute ) 244 { 245 $default = $base . "_ezdate_default_" . $classAttribute->attribute( 'id' ); 246 if ( $http->hasPostVariable( $default ) ) 247 { 248 $defaultValue = $http->postVariable( $default ); 249 $classAttribute->setAttribute( EZ_DATATYPESTRING_DATE_DEFAULT, $defaultValue ); 250 } 251 return true; 252 } 253 254 /*! 255 \reimp 256 */ 257 function isIndexable() 258 { 259 return true; 260 } 261 262 /*! 263 \reimp 264 */ 265 function isInformationCollector() 266 { 267 return true; 268 } 269 270 /*! 271 Returns the meta data used for storing search indeces. 272 */ 273 function metaData( $contentObjectAttribute ) 274 { 275 return $contentObjectAttribute->attribute( 'data_int' ); 276 } 277 278 /*! 279 \return string representation of an contentobjectattribute data for simplified export 280 281 */ 282 function toString( $contentObjectAttribute ) 283 { 284 return $contentObjectAttribute->attribute( 'data_int' ); 285 } 286 287 function fromString( &$contentObjectAttribute, $string ) 288 { 289 return $contentObjectAttribute->setAttribute( 'data_int', $string ); 290 } 291 292 /*! 293 Returns the date. 294 */ 295 function title( &$contentObjectAttribute ) 296 { 297 $locale =& eZLocale::instance(); 298 $retVal = $contentObjectAttribute->attribute( "data_int" ) == 0 ? '' : $locale->formatDate( $contentObjectAttribute->attribute( "data_int" ) ); 299 return $retVal; 300 } 301 302 function hasObjectAttributeContent( &$contentObjectAttribute ) 303 { 304 return $contentObjectAttribute->attribute( "data_int" ) != 0; 305 } 306 307 /*! 308 \reimp 309 */ 310 function sortKey( &$contentObjectAttribute ) 311 { 312 return (int)$contentObjectAttribute->attribute( 'data_int' ); 313 } 314 315 /*! 316 \reimp 317 */ 318 function sortKeyType() 319 { 320 return 'int'; 321 } 322 323 /*! 324 \reimp 325 */ 326 function serializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode ) 327 { 328 $defaultValue = $classAttribute->attribute( EZ_DATATYPESTRING_DATE_DEFAULT ); 329 switch ( $defaultValue ) 330 { 331 case EZ_DATATYPESTRING_DATE_DEFAULT_EMTPY: 332 { 333 $attributeParametersNode->appendChild( eZDOMDocument::createElementNode( 'default-value', 334 array( 'type' => 'empty' ) ) ); 335 } break; 336 case EZ_DATATYPESTRING_DATE_DEFAULT_CURRENT_DATE: 337 { 338 $attributeParametersNode->appendChild( eZDOMDocument::createElementNode( 'default-value', 339 array( 'type' => 'current-date' ) ) ); 340 } break; 341 } 342 } 343 344 /*! 345 \reimp 346 */ 347 function unserializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode ) 348 { 349 $defaultNode =& $attributeParametersNode->elementByName( 'default-value' ); 350 $defaultValue = strtolower( $defaultNode->attributeValue( 'type' ) ); 351 switch ( $defaultValue ) 352 { 353 case 'empty': 354 { 355 $classAttribute->setAttribute( EZ_DATATYPESTRING_DATE_DEFAULT, EZ_DATATYPESTRING_DATE_DEFAULT_EMTPY ); 356 } break; 357 case 'current-date': 358 { 359 $classAttribute->setAttribute( EZ_DATATYPESTRING_DATE_DEFAULT, EZ_DATATYPESTRING_DATE_DEFAULT_CURRENT_DATE ); 360 } break; 361 } 362 } 363 364 /*! 365 \param package 366 \param content attribute 367 368 \return a DOM representation of the content object attribute 369 */ 370 function serializeContentObjectAttribute( &$package, &$objectAttribute ) 371 { 372 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute ); 373 374 $stamp = $objectAttribute->attribute( 'data_int' ); 375 376 if ( !is_null( $stamp ) ) 377 { 378 include_once ( 'lib/ezlocale/classes/ezdateutils.php' ); 379 $node->appendChild( eZDOMDocument::createElementTextNode( 'date', eZDateUtils::rfc1123Date( $stamp ) ) ); 380 } 381 return $node; 382 } 383 384 /*! 385 \reimp 386 \param package 387 \param contentobject attribute object 388 \param ezdomnode object 389 */ 390 function unserializeContentObjectAttribute( &$package, &$objectAttribute, $attributeNode ) 391 { 392 $timeNode = $attributeNode->elementByName( 'date' ); 393 if ( is_object( $timeNode ) ) 394 $timestampNode = $timeNode->firstChild(); 395 if ( is_object( $timestampNode ) ) 396 { 397 include_once ( 'lib/ezlocale/classes/ezdateutils.php' ); 398 $objectAttribute->setAttribute( 'data_int', eZDateUtils::textToDate( $timestampNode->content() ) ); 399 } 400 } 401 } 402 403 eZDataType::register( EZ_DATATYPESTRING_DATE, "ezdatetype" ); 404 405 ?>
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 |