GapOrm/Mapper/BaseModel.php
private function convertToDB($obj)
    {
        $o = $this->getEmptyObject();

        foreach ($this->fields as $field) {
            if (!property_exists($obj, $field->identifier()))
                continue;

            if (is_null($obj->{$field->identifier()})) {
                $o->{$field->identifier()} = 'NULL';
                continue;
            }

            $val = $obj->{$field->identifier()};

            switch ($field->type()) {
                case self::FIELD_TYPE_BOOL :
                    $o->{$field->identifier()} = $val ? 1 : 0;
                    break;
                case self::FIELD_TYPE_INT :
                    $o->{$field->identifier()} = (int) $val;
                    break;
                case self::FIELD_TYPE_FLOAT :
                    $o->{$field->identifier()} = (float) $val;
                    break;
                case self::FIELD_TYPE_STR :
                    $o->{$field->identifier()} = $this->escape($val);
                    break;
                case self::FIELD_TYPE_DATETIME :
                    if ($val && !is_null($val)) {
                        $o->{$field->identifier()} = $val->getTimestamp();
                    } else {
                        $o->{$field->identifier()} = 0;
                    }

                    break;
                case self::FIELD_TYPE_STR_ARRAY :
                    $delimiter = '(^!)';
                    $o->{$field->identifier()} = '"' . implode($delimiter, array_map(function($v) use ($delimiter) {
                            str_replace($delimiter, '', $v);
                        }, $val)) . '"';
                    break;
                case self::FIELD_TYPE_INT_ARRAY :
                    $val = array_map(function($v){ return "'" . (int)$v . "'"; }, $val);
                    $o->{$field->identifier()} = '"' . implode(',', $val) . '"';
                    break;
                case self::FIELD_TYPE_OBJ :
                    $o->{$field->identifier()} = '"' . addslashes(json_encode($val)) . '"';
                    break;
                default :
                    throw new TypeNotExistException();
            }
        }

        return $o;
    }
private function convertToDB($obj)
    {
        $o = $this->getEmptyObject();

        foreach ($this->fields as $field) {
            if (!property_exists($obj, $field->identifier()))
                continue;

            if (is_null($obj->{$field->identifier()})) {
                $o->{$field->identifier()} = 'NULL';
                continue;
            }

            $val = $obj->{$field->identifier()};

            switch ($field->type()) {
                case self::FIELD_TYPE_BOOL :
                    $o->{$field->identifier()} = $val ? 1 : 0;
                    break;
                case self::FIELD_TYPE_INT :
                    $o->{$field->identifier()} = (int) $val;
                    break;
                case self::FIELD_TYPE_FLOAT :
                    $o->{$field->identifier()} = (float) $val;
                    break;
                case self::FIELD_TYPE_STR :
                    $o->{$field->identifier()} = $this->escape($val);
                    break;
                case self::FIELD_TYPE_DATETIME :
                    if ($val && !is_null($val)) {
                        $o->{$field->identifier()} = $val->getTimestamp();
                    } else {
                        $o->{$field->identifier()} = 0;
                    }

                    break;
                case self::FIELD_TYPE_STR_ARRAY :
                    $delimiter = '(^!)';
                    $o->{$field->identifier()} = '"' . implode($delimiter, array_map(function($v) use ($delimiter) {
                            str_replace($delimiter, '', $v);
                        }, $val)) . '"';
                    break;
                case self::FIELD_TYPE_INT_ARRAY :
                    $val = array_map(function($v){ return "'" . (int)$v . "'"; }, $val);
                    $o->{$field->identifier()} = '"' . implode(',', $val) . '"';
                    break;
                case self::FIELD_TYPE_OBJ :
                    $o->{$field->identifier()} = '"' . addslashes(json_encode($val)) . '"';
                    break;
                default :
                    throw new TypeNotExistException();
            }
        }

        return $o;
    }
private function convertToDB ( $ obj ) { $ o = $ this -> getEmptyObject ( ) ; foreach ( $ this -> fields as $ field ) { if ( ! property_exists ( $ obj , $ field -> identifier ( ) ) ) continue ; if ( is_null ( $ obj -> { $ field -> identifier ( ) } ) ) { $ o -> { $ field -> identifier ( ) } = 'NULL' ; continue ; } $ val = $ obj -> { $ field -> identifier ( ) } ; switch ( $ field -> type ( ) ) { case self :: FIELD_TYPE_BOOL : $ o -> { $ field -> identifier ( ) } = $ val ? 1 : 0 ; break ; case self :: FIELD_TYPE_INT : $ o -> { $ field -> identifier ( ) } = ( int ) $ val ; break ; case self :: FIELD_TYPE_FLOAT : $ o -> { $ field -> identifier ( ) } = ( float ) $ val ; break ; case self :: FIELD_TYPE_STR : $ o -> { $ field -> identifier ( ) } = $ this -> escape ( $ val ) ; break ; case self :: FIELD_TYPE_DATETIME : if ( $ val && ! is_null ( $ val ) ) { $ o -> { $ field -> identifier ( ) } = $ val -> getTimestamp ( ) ; } else { $ o -> { $ field -> identifier ( ) } = 0 ; } break ; case self :: FIELD_TYPE_STR_ARRAY : $ delimiter = '(^!)' ; $ o -> { $ field -> identifier ( ) } = '"' . implode ( $ delimiter , array_map ( function ( $ v ) use ( $ delimiter ) { str_replace ( $ delimiter , '' , $ v ) ; } , $ val ) ) . '"' ; break ; case self :: FIELD_TYPE_INT_ARRAY : $ val = array_map ( function ( $ v ) { return "'" . ( int ) $ v . "'" ; } , $ val ) ; $ o -> { $ field -> identifier ( ) } = '"' . implode ( ',' , $ val ) . '"' ; break ; case self :: FIELD_TYPE_OBJ : $ o -> { $ field -> identifier ( ) } = '"' . addslashes ( json_encode ( $ val ) ) . '"' ; break ; default : throw new TypeNotExistException ( ) ; } } return $ o ; }
Check & convert Fields for Insert, Update

@param $obj
@return object
@throws \GapOrm\Exceptions\TypeNotExistException
Check & convert Fields for Insert Update