src/Persistence/UI.php
public function _typecastSaveField(\atk4\data\Field $f, $value)
    {
        // serialize if we explicitly want that
        if ($f->serialize) {
            $value = $this->serializeSaveField($f, $value);
        }

        // work only on copied value not real one !!!
        $v = is_object($value) ? clone $value : $value;

        switch ($f->type) {
        case 'boolean':
            return $v ? $this->yes : $this->no;
        case 'money':
            return ($this->currency ? $this->currency.' ' : '').number_format($v, 2);
        case 'date':
        case 'datetime':
        case 'time':
            $dt_class = isset($f->dateTimeClass) ? $f->dateTimeClass : 'DateTime';
            $tz_class = isset($f->dateTimeZoneClass) ? $f->dateTimeZoneClass : 'DateTimeZone';

            if ($v instanceof $dt_class) {
                $format = ['date' => $this->date_format, 'datetime' => $this->datetime_format, 'time' => $this->time_format];
                $format = $f->persist_format ?: $format[$f->type];

                // datetime only - set to persisting timezone
                if ($f->type == 'datetime' && isset($f->persist_timezone)) {
                    $v->setTimezone(new $tz_class($f->persist_timezone));
                }
                $v = $v->format($format);
            }
            break;
        case 'array':
        case 'object':
            // don't encode if we already use some kind of serialization
            $v = $f->serialize ? $v : json_encode($v);
            break;
        }

        return $v;
    }
public function _typecastSaveField(\atk4\data\Field $f, $value)
    {
        // serialize if we explicitly want that
        if ($f->serialize) {
            $value = $this->serializeSaveField($f, $value);
        }

        // work only on copied value not real one !!!
        $v = is_object($value) ? clone $value : $value;

        switch ($f->type) {
        case 'boolean':
            return $v ? $this->yes : $this->no;
        case 'money':
            return ($this->currency ? $this->currency.' ' : '').number_format($v, 2);
        case 'date':
        case 'datetime':
        case 'time':
            $dt_class = isset($f->dateTimeClass) ? $f->dateTimeClass : 'DateTime';
            $tz_class = isset($f->dateTimeZoneClass) ? $f->dateTimeZoneClass : 'DateTimeZone';

            if ($v instanceof $dt_class) {
                $format = ['date' => $this->date_format, 'datetime' => $this->datetime_format, 'time' => $this->time_format];
                $format = $f->persist_format ?: $format[$f->type];

                // datetime only - set to persisting timezone
                if ($f->type == 'datetime' && isset($f->persist_timezone)) {
                    $v->setTimezone(new $tz_class($f->persist_timezone));
                }
                $v = $v->format($format);
            }
            break;
        case 'array':
        case 'object':
            // don't encode if we already use some kind of serialization
            $v = $f->serialize ? $v : json_encode($v);
            break;
        }

        return $v;
    }
public function _typecastSaveField ( \ atk4 \ data \ Field $ f , $ value ) { // serialize if we explicitly want that if ( $ f -> serialize ) { $ value = $ this -> serializeSaveField ( $ f , $ value ) ; } // work only on copied value not real one !!! $ v = is_object ( $ value ) ? clone $ value : $ value ; switch ( $ f -> type ) { case 'boolean' : return $ v ? $ this -> yes : $ this -> no ; case 'money' : return ( $ this -> currency ? $ this -> currency . ' ' : '' ) . number_format ( $ v , 2 ) ; case 'date' : case 'datetime' : case 'time' : $ dt_class = isset ( $ f -> dateTimeClass ) ? $ f -> dateTimeClass : 'DateTime' ; $ tz_class = isset ( $ f -> dateTimeZoneClass ) ? $ f -> dateTimeZoneClass : 'DateTimeZone' ; if ( $ v instanceof $ dt_class ) { $ format = [ 'date' => $ this -> date_format , 'datetime' => $ this -> datetime_format , 'time' => $ this -> time_format ] ; $ format = $ f -> persist_format ? : $ format [ $ f -> type ] ; // datetime only - set to persisting timezone if ( $ f -> type == 'datetime' && isset ( $ f -> persist_timezone ) ) { $ v -> setTimezone ( new $ tz_class ( $ f -> persist_timezone ) ) ; } $ v = $ v -> format ( $ format ) ; } break ; case 'array' : case 'object' : // don't encode if we already use some kind of serialization $ v = $ f -> serialize ? $ v : json_encode ( $ v ) ; break ; } return $ v ; }
This method contains the logic of casting generic values into user-friendly format.
This method contains the logic of casting generic values into user - friendly format .