public function insert(\Berthe\VO $object)
    {
        $this->validateTableAndIdentityColumn();

        $mappings = $this->getSaveMappings();

        if (empty($mappings)) {
            $mappings = $this->getDefaultMappings($object);
        }

        $valueElements = array();
        $columnElements = array();
        $params = array();

        $values = $object->__toArray();

        foreach ($mappings as $column => $property) {
            if ($column != $this->identityColumn) {
                $value = in_array($property, $object->getTranslatableFields()) ?
                    $object->getAttribute($property) :
                    $values[$property];
                $columnElements[] = $column;
                $params[$column] = $value;

                if ($value instanceof \Berthe\Translation\Translation) {
                    $this->translator->saveTranslation($value);
                }
            }
        }

        $columnAssignment = $this->escapeCharacter .
            implode($this->escapeCharacter . ', ' . $this->escapeCharacter, $columnElements) .
            $this->escapeCharacter;
        $valueAssignment = '%s' . str_repeat(', %s', count($columnElements) -1);

        $query = <<<EOQ
INSERT INTO {$this->getTableName()} ({$columnAssignment})
VALUES ({$valueAssignment});
EOQ;

        if ((bool)$this->db->query($query, $params)) {
            $id = (int)$this->db->lastInsertId($this->getTableName(), $this->identityColumn);
            $object->setId($id);
        }

        return $object->getId() > 0;
    }
public function insert(\Berthe\VO $object)
    {
        $this->validateTableAndIdentityColumn();

        $mappings = $this->getSaveMappings();

        if (empty($mappings)) {
            $mappings = $this->getDefaultMappings($object);
        }

        $valueElements = array();
        $columnElements = array();
        $params = array();

        $values = $object->__toArray();

        foreach ($mappings as $column => $property) {
            if ($column != $this->identityColumn) {
                $value = in_array($property, $object->getTranslatableFields()) ?
                    $object->getAttribute($property) :
                    $values[$property];
                $columnElements[] = $column;
                $params[$column] = $value;

                if ($value instanceof \Berthe\Translation\Translation) {
                    $this->translator->saveTranslation($value);
                }
            }
        }

        $columnAssignment = $this->escapeCharacter .
            implode($this->escapeCharacter . ', ' . $this->escapeCharacter, $columnElements) .
            $this->escapeCharacter;
        $valueAssignment = '%s' . str_repeat(', %s', count($columnElements) -1);

        $query = <<<EOQ
INSERT INTO {$this->getTableName()} ({$columnAssignment})
VALUES ({$valueAssignment});
EOQ;

        if ((bool)$this->db->query($query, $params)) {
            $id = (int)$this->db->lastInsertId($this->getTableName(), $this->identityColumn);
            $object->setId($id);
        }

        return $object->getId() > 0;
    }
public function insert ( \ Berthe \ VO $ object ) { $ this -> validateTableAndIdentityColumn ( ) ; $ mappings = $ this -> getSaveMappings ( ) ; if ( empty ( $ mappings ) ) { $ mappings = $ this -> getDefaultMappings ( $ object ) ; } $ valueElements = array ( ) ; $ columnElements = array ( ) ; $ params = array ( ) ; $ values = $ object -> __toArray ( ) ; foreach ( $ mappings as $ column => $ property ) { if ( $ column != $ this -> identityColumn ) { $ value = in_array ( $ property , $ object -> getTranslatableFields ( ) ) ? $ object -> getAttribute ( $ property ) : $ values [ $ property ] ; $ columnElements [ ] = $ column ; $ params [ $ column ] = $ value ; if ( $ value instanceof \ Berthe \ Translation \ Translation ) { $ this -> translator -> saveTranslation ( $ value ) ; } } } $ columnAssignment = $ this -> escapeCharacter . implode ( $ this -> escapeCharacter . ', ' . $ this -> escapeCharacter , $ columnElements ) . $ this -> escapeCharacter ; $ valueAssignment = '%s' . str_repeat ( ', %s' , count ( $ columnElements ) - 1 ) ; $ query =  <<<EOQ
INSERT INTO {$this->getTableName()} ({$columnAssignment})
VALUES ({$valueAssignment});
EOQ ; if ( ( bool ) $ this -> db -> query ( $ query , $ params ) ) { $ id = ( int ) $ this -> db -> lastInsertId ( $ this -> getTableName ( ) , $ this -> identityColumn ) ; $ object -> setId ( $ id ) ; } return $ object -> getId ( ) > 0 ; }
Insert the object in database
@param \Berthe\VO $object the object to insert
@return boolean
Insert the object in database