Ejemplo n.º 1
0
 /**
  * @param FieldType $fieldType Document field type.
  * @param mixed $value Field value.
  * @param string $toTypeClass Type class name.
  * @return null|mixed
  */
 public static function convertTo(FieldType $fieldType, $value, $toTypeClass)
 {
     /** @var Base $toTypeClass */
     $type = $toTypeClass::getType();
     switch ($type) {
         case FieldType::BOOL:
             $value = (bool) $value ? 'Y' : 'N';
             break;
         case FieldType::DATE:
             $value = date(Main\Type\Date::convertFormatToPhp(\FORMAT_DATE), (int) $value);
             break;
         case FieldType::DATETIME:
             $value = date(Main\Type\DateTime::convertFormatToPhp(\FORMAT_DATETIME), (int) $value);
             break;
         case FieldType::DOUBLE:
             $value = (double) $value;
             break;
         case FieldType::INT:
             $value = (int) $value;
             break;
         case FieldType::STRING:
         case FieldType::TEXT:
             $value = (string) $value;
             break;
         case FieldType::USER:
             $value = 'user_' . (int) $value;
             break;
         default:
             $value = null;
     }
     return $value;
 }
Ejemplo n.º 2
0
 /**
  * @param FieldType $fieldType Document field type.
  * @param mixed $value Field value.
  * @param string $toTypeClass Type class name.
  * @return null|mixed
  */
 public static function convertTo(FieldType $fieldType, $value, $toTypeClass)
 {
     /** @var Base $toTypeClass */
     $type = $toTypeClass::getType();
     switch ($type) {
         case FieldType::DOUBLE:
         case FieldType::INT:
             $value = $value ? (int) strtotime($value) : 0;
             break;
         case FieldType::DATE:
             $value = date(Type\Date::convertFormatToPhp(\FORMAT_DATE), strtotime($value));
             break;
         case FieldType::DATETIME:
             $value = date(Type\DateTime::convertFormatToPhp(\FORMAT_DATETIME), strtotime($value));
             break;
         case FieldType::STRING:
         case FieldType::TEXT:
             $value = (string) $value;
             if ($value) {
                 $format = static::getType() == FieldType::DATE ? \FORMAT_DATE : \FORMAT_DATETIME;
                 $value = date(Type\DateTime::convertFormatToPhp($format), strtotime($value));
             }
             break;
         default:
             $value = null;
     }
     return $value;
 }
Ejemplo n.º 3
0
 /**
  * @param FieldType $fieldType Document field type.
  * @param mixed $value Field value.
  * @param string $toTypeClass Type class name.
  * @return null|mixed
  */
 public static function convertTo(FieldType $fieldType, $value, $toTypeClass)
 {
     /** @var Base $toTypeClass */
     $type = $toTypeClass::getType();
     switch ($type) {
         case FieldType::BOOL:
             $value = strtolower((string) $value);
             $value = in_array($value, array('y', 'yes', 'true', '1')) ? 'Y' : 'N';
             break;
         case FieldType::DATE:
             $value = date(Main\Type\Date::convertFormatToPhp(\FORMAT_DATE), strtotime($value));
             break;
         case FieldType::DATETIME:
             $value = date(Main\Type\DateTime::convertFormatToPhp(\FORMAT_DATETIME), strtotime($value));
             break;
         case FieldType::DOUBLE:
             $value = str_replace(' ', '', str_replace(',', '.', $value));
             $value = (double) $value;
             break;
         case FieldType::INT:
             $value = str_replace(' ', '', $value);
             $value = (int) $value;
             break;
         case FieldType::STRING:
         case FieldType::TEXT:
             $value = (string) $value;
             break;
         case FieldType::USER:
             $value = trim($value);
             if (strpos($value, 'user_') === false && strpos($value, 'group_') === false && !preg_match('#^[0-9]+$#', $value)) {
                 $value = null;
             }
             break;
         default:
             $value = null;
     }
     return $value;
 }