| | 211 | |
| | 212 | |
| | 213 | |
| | 214 | /** |
| | 215 | * Fonction datetime relative (Aujourd'hui, hier, etc..) |
| | 216 | * |
| | 217 | * @author Guillaume Kulakowski <guillaume_AT_llaumgui_DOT_com> |
| | 218 | * @since 1.0.2 |
| | 219 | * |
| | 220 | * @param integer $operatorValue |
| | 221 | * @param string $class |
| | 222 | * @param string $data |
| | 223 | */ |
| | 224 | static function relatedDatetime( &$operatorValue, $class, $data ) |
| | 225 | { |
| | 226 | $locale = eZLocale::instance(); |
| | 227 | $dateFormat = '%d-%m-%Y'; |
| | 228 | $date = $locale->formatDateTimeType( $dateFormat, $operatorValue); |
| | 229 | $today = $locale->formatDateTimeType( $dateFormat); |
| | 230 | $yesterday = $locale->formatDateTimeType( $dateFormat, time()-86400); |
| | 231 | |
| | 232 | if ( $class === null ) |
| | 233 | { |
| | 234 | return; |
| | 235 | } |
| | 236 | |
| | 237 | if ( $class == 'custom' ) |
| | 238 | { |
| | 239 | $classFormat = $data; |
| | 240 | } |
| | 241 | else |
| | 242 | { |
| | 243 | $dtINI = eZINI::instance( 'datetime.ini' ); |
| | 244 | $formats = $dtINI->variable( 'ClassSettings', 'Formats' ); |
| | 245 | if ( array_key_exists( $class, $formats ) ) |
| | 246 | { |
| | 247 | $classFormat = $formats[$class]; |
| | 248 | } |
| | 249 | else |
| | 250 | { |
| | 251 | $tpl->error( $operatorName, "DateTime class '$class' is not defined", $placement ); |
| | 252 | return; |
| | 253 | } |
| | 254 | } |
| | 255 | |
| | 256 | if ( $date == $today ) |
| | 257 | { |
| | 258 | $classFormat = preg_replace( '#\$\$(.+?)\$\$#', ezi18n( 'myutils/date', 'Today' ), $classFormat ); |
| | 259 | } |
| | 260 | else if ( $date == $yesterday ) |
| | 261 | { |
| | 262 | $classFormat = preg_replace( '#\$\$(.+?)\$\$#', ezi18n( 'myutils/date', 'Yesterday' ), $classFormat ); |
| | 263 | } |
| | 264 | |
| | 265 | $operatorValue = $locale->formatDateTimeType( str_replace('$$', '', $classFormat ), $operatorValue ); |
| | 266 | } |