diff --git a/dibi/libs/DibiResult.php b/dibi/libs/DibiResult.php index be016051..10a7944c 100644 --- a/dibi/libs/DibiResult.php +++ b/dibi/libs/DibiResult.php @@ -493,7 +493,10 @@ class DibiResult extends DibiObject implements IDataSource /** * Converts value to specified type and format. - * @return array ($type, $format) + * @param mixed value + * @param int type + * @param string format + * @return mixed */ final public function convert($value, $type, $format = NULL) { diff --git a/dibi/libs/DibiRow.php b/dibi/libs/DibiRow.php index fcdd5a8a..78fff7b3 100644 --- a/dibi/libs/DibiRow.php +++ b/dibi/libs/DibiRow.php @@ -40,6 +40,44 @@ class DibiRow extends ArrayObject + /** + * Converts value to date-time format. + * @param string key + * @param string format + * @return mixed + */ + public function asDate($key, $format = NULL) + { + $value = $this[$key]; + if ($value === NULL || $value === FALSE) { + return $value; + + } else { + $value = is_numeric($value) ? (int) $value : strtotime($value); + return $format === NULL ? $value : date($format, $value); + } + } + + + + /** + * Converts value to boolean. + * @param string key + * @return mixed + */ + public function asBool($key) + { + $value = $this[$key]; + if ($value === NULL || $value === FALSE) { + return $value; + + } else { + return ((bool) $value) && $value !== 'f' && $value !== 'F'; + } + } + + + /** * PHP < 5.3 workaround * @return void diff --git a/dibi/libs/DibiTranslator.php b/dibi/libs/DibiTranslator.php index b06b6d64..6bb16f24 100644 --- a/dibi/libs/DibiTranslator.php +++ b/dibi/libs/DibiTranslator.php @@ -319,6 +319,10 @@ final class DibiTranslator extends DibiObject case 'sn': // string or NULL return $value == '' ? 'NULL' : $this->driver->escape($value, dibi::TEXT); // notice two equal signs + case 'in': // signed int or NULL + if ($value == '') $value = NULL; + // intentionally break omitted + case 'i': // signed int case 'u': // unsigned int, ignored // support for long numbers - keep them unchanged