original_string: public function save_config(array $cfg, $description, $class = 'grid')
    {
      if ( isset($cfg['elements']) ){
        $copy = $cfg;
        unset($copy['elements']);
        $obj_param = [
            'id_project' => 1,
            'class' => $class,
            'description' => $description,
            'configuration' => json_encode($copy)
        ];
        if ( isset($cfg['table']) ){
          $obj_param['table'] = $cfg['table'];
        }
        $this->db->insert($this->admin_db.'.'.$this->prefix.'objects', $obj_param);
        
        $id = $this->db->last_id();
        
        $i = 1;
        
        foreach ( $cfg['elements'] as $name => $ele ){
  
          $table = $column = false;
          if ( !empty($ele['appui']['table']) ){
            $table = $ele['appui']['table'];
          }
          else if ( !empty($ele['table']) ){
            $table = $ele['table'];
          }
          else if ( !empty($cfg['table']) ){
            $table = $cfg['table'];
          }
          
          if ( $table && isset($ele['attr']['name']) ){
            $column = $this->db->tfn($table).'.'.$this->db->csn($ele['attr']['name']);
          }
          $this->db->insert($this->admin_db.'.'.$this->prefix.'fields',[
            'id_obj' => $id,
            'column' => ( $column ?: null ),
            'title' => isset($ele['label']) ? $ele['label'] : null,
            'position' => $i,
            'configuration' => json_encode($ele)
          ]);
          $i++;
        }
        return $id;
      }
    }
code: public function save_config(array $cfg, $description, $class = 'grid')
    {
      if ( isset($cfg['elements']) ){
        $copy = $cfg;
        unset($copy['elements']);
        $obj_param = [
            'id_project' => 1,
            'class' => $class,
            'description' => $description,
            'configuration' => json_encode($copy)
        ];
        if ( isset($cfg['table']) ){
          $obj_param['table'] = $cfg['table'];
        }
        $this->db->insert($this->admin_db.'.'.$this->prefix.'objects', $obj_param);
        
        $id = $this->db->last_id();
        
        $i = 1;
        
        foreach ( $cfg['elements'] as $name => $ele ){
  
          $table = $column = false;
          if ( !empty($ele['appui']['table']) ){
            $table = $ele['appui']['table'];
          }
          else if ( !empty($ele['table']) ){
            $table = $ele['table'];
          }
          else if ( !empty($cfg['table']) ){
            $table = $cfg['table'];
          }
          
          if ( $table && isset($ele['attr']['name']) ){
            $column = $this->db->tfn($table).'.'.$this->db->csn($ele['attr']['name']);
          }
          $this->db->insert($this->admin_db.'.'.$this->prefix.'fields',[
            'id_obj' => $id,
            'column' => ( $column ?: null ),
            'title' => isset($ele['label']) ? $ele['label'] : null,
            'position' => $i,
            'configuration' => json_encode($ele)
          ]);
          $i++;
        }
        return $id;
      }
    }
code_tokens: public function save_config ( array $ cfg , $ description , $ class = 'grid' ) { if ( isset ( $ cfg [ 'elements' ] ) ) { $ copy = $ cfg ; unset ( $ copy [ 'elements' ] ) ; $ obj_param = [ 'id_project' => 1 , 'class' => $ class , 'description' => $ description , 'configuration' => json_encode ( $ copy ) ] ; if ( isset ( $ cfg [ 'table' ] ) ) { $ obj_param [ 'table' ] = $ cfg [ 'table' ] ; } $ this -> db -> insert ( $ this -> admin_db . '.' . $ this -> prefix . 'objects' , $ obj_param ) ; $ id = $ this -> db -> last_id ( ) ; $ i = 1 ; foreach ( $ cfg [ 'elements' ] as $ name => $ ele ) { $ table = $ column = false ; if ( ! empty ( $ ele [ 'appui' ] [ 'table' ] ) ) { $ table = $ ele [ 'appui' ] [ 'table' ] ; } else if ( ! empty ( $ ele [ 'table' ] ) ) { $ table = $ ele [ 'table' ] ; } else if ( ! empty ( $ cfg [ 'table' ] ) ) { $ table = $ cfg [ 'table' ] ; } if ( $ table && isset ( $ ele [ 'attr' ] [ 'name' ] ) ) { $ column = $ this -> db -> tfn ( $ table ) . '.' . $ this -> db -> csn ( $ ele [ 'attr' ] [ 'name' ] ) ; } $ this -> db -> insert ( $ this -> admin_db . '.' . $ this -> prefix . 'fields' , [ 'id_obj' => $ id , 'column' => ( $ column ? : null ) , 'title' => isset ( $ ele [ 'label' ] ) ? $ ele [ 'label' ] : null , 'position' => $ i , 'configuration' => json_encode ( $ ele ) ] ) ; $ i ++ ; } return $ id ; } }
docstring: Saves the given configuration in the database and returns the new ID
  
  @param array $cfg
  @param string $class
  @return int|false
docstring_tokens: Saves the given configuration in the database and returns the new ID