Guest User

Untitled

a guest
Mar 6th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. <?php
  2. namespace Kunden\Property\TypeConverter;
  3.  
  4.  
  5. use TYPO3\FLOW3\Annotations as FLOW3;
  6. use TYPO3\FLOW3\Error\Error;
  7.  
  8. /*                                                                        *
  9.  * This script belongs to the FLOW3 package "Kunden".                     *
  10.  *                                                                        *
  11.  *                                                                        */
  12.  
  13.  /**
  14.  * HourMinuteToSecondsConverter for the Kunden package
  15.  *
  16.  * @FLOW3\Scope("singleton")
  17.  */
  18.  
  19. class HourMinuteToSecondsConverter extends \TYPO3\FLOW3\Property\TypeConverter\AbstractTypeConverter {
  20.  
  21.  
  22.     /**
  23.      * @var array<string>
  24.      */
  25.     protected $sourceTypes = array('string');
  26.  
  27.     /**
  28.      * @var string
  29.      */
  30.     protected $targetType = 'integer';
  31.  
  32.     /**
  33.      * @var integer
  34.      */
  35.     protected $priority = 100;
  36.  
  37.  
  38.  
  39.     /**
  40.      * Converts $source to a \DateTime using the configured dateFormat
  41.      *
  42.      * @param string|array $source the string to be converted to a int
  43.      * @param string $targetType must be "Integer"
  44.      * @param array $convertedChildProperties not used currently
  45.      * @param \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration
  46.      * @return \integer
  47.      * @throws \TYPO3\FLOW3\Property\Exception\TypeConverterException
  48.      */
  49.     public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration = NULL) {
  50.  
  51.         if(strlen($source)==0){
  52.             return new Error('No input given' , 1332934124, array($source));
  53.         }
  54.         $inArray = explode(" ", $source);
  55.         if(!is_array($inArray)){
  56.             return new Error('General process error (is_array)' , 1332934124, array($source));
  57.         }
  58.        
  59.         if(count($inArray)==2){
  60.             $hours = (int)$inArray[0] * 60 * 60;
  61.             $minutes = (int)$inArray[1] * 60;
  62.             return (int)($hours + $minutes);
  63.         } else {
  64.             return new Error('No hour or minute given.' , 1332934124, array($source));
  65.         }
  66.  
  67.     }
  68.  
  69.  
  70. }
  71. ?>
Advertisement
Add Comment
Please, Sign In to add comment