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