public function addTableWithoutEmptyCols($titles, $data, $options = [], $html = true)
    {
        $cols_empty = [];
        foreach ($data as $row) {
            foreach ($row as $col => $value) {
                if (empty($value)) {
                    if (!array_key_exists($col, $cols_empty))
                        $cols_empty[$col] = 0;
                    $cols_empty[$col]++;
                }
            }
        }
        $n_rows = count($data);
        $titles_keys = array_flip(array_keys($titles));
        foreach ($cols_empty as $col => $rows) {
            if ($rows==$n_rows) {
                unset($titles[$col]);
                foreach ($data as &$row) {
                    unset($row[$col]);
                }
                if (isset($options['width']))
                    unset($options['width'][$titles_keys[$col]]);
                if (isset($options['align']))
                    unset($options['align'][$titles_keys[$col]]);
            }
        }
        if (isset($options['width'])) {
            $options['width'] = array_slice($options['width'], 0);
            $key_0 = null;
            $suma = 0;
            foreach ($options['width'] as $key => $val) {
                if ($val===0)
                    $key_0 = $key;
                $suma += $val;
            }
            if ($key_0!==null) {
                $options['width'][$key_0] = 190 - $suma;
            }
        }
        if (isset($options['align']))
            $options['align'] = array_slice($options['align'], 0);
        $this->addTable($titles, $data, $options, $html);
    }
public function addTableWithoutEmptyCols($titles, $data, $options = [], $html = true)
    {
        $cols_empty = [];
        foreach ($data as $row) {
            foreach ($row as $col => $value) {
                if (empty($value)) {
                    if (!array_key_exists($col, $cols_empty))
                        $cols_empty[$col] = 0;
                    $cols_empty[$col]++;
                }
            }
        }
        $n_rows = count($data);
        $titles_keys = array_flip(array_keys($titles));
        foreach ($cols_empty as $col => $rows) {
            if ($rows==$n_rows) {
                unset($titles[$col]);
                foreach ($data as &$row) {
                    unset($row[$col]);
                }
                if (isset($options['width']))
                    unset($options['width'][$titles_keys[$col]]);
                if (isset($options['align']))
                    unset($options['align'][$titles_keys[$col]]);
            }
        }
        if (isset($options['width'])) {
            $options['width'] = array_slice($options['width'], 0);
            $key_0 = null;
            $suma = 0;
            foreach ($options['width'] as $key => $val) {
                if ($val===0)
                    $key_0 = $key;
                $suma += $val;
            }
            if ($key_0!==null) {
                $options['width'][$key_0] = 190 - $suma;
            }
        }
        if (isset($options['align']))
            $options['align'] = array_slice($options['align'], 0);
        $this->addTable($titles, $data, $options, $html);
    }
public function addTableWithoutEmptyCols ( $ titles , $ data , $ options = [ ] , $ html = true ) { $ cols_empty = [ ] ; foreach ( $ data as $ row ) { foreach ( $ row as $ col => $ value ) { if ( empty ( $ value ) ) { if ( ! array_key_exists ( $ col , $ cols_empty ) ) $ cols_empty [ $ col ] = 0 ; $ cols_empty [ $ col ] ++ ; } } } $ n_rows = count ( $ data ) ; $ titles_keys = array_flip ( array_keys ( $ titles ) ) ; foreach ( $ cols_empty as $ col => $ rows ) { if ( $ rows == $ n_rows ) { unset ( $ titles [ $ col ] ) ; foreach ( $ data as & $ row ) { unset ( $ row [ $ col ] ) ; } if ( isset ( $ options [ 'width' ] ) ) unset ( $ options [ 'width' ] [ $ titles_keys [ $ col ] ] ) ; if ( isset ( $ options [ 'align' ] ) ) unset ( $ options [ 'align' ] [ $ titles_keys [ $ col ] ] ) ; } } if ( isset ( $ options [ 'width' ] ) ) { $ options [ 'width' ] = array_slice ( $ options [ 'width' ] , 0 ) ; $ key_0 = null ; $ suma = 0 ; foreach ( $ options [ 'width' ] as $ key => $ val ) { if ( $ val === 0 ) $ key_0 = $ key ; $ suma += $ val ; } if ( $ key_0 !== null ) { $ options [ 'width' ] [ $ key_0 ] = 190 - $ suma ; } } if ( isset ( $ options [ 'align' ] ) ) $ options [ 'align' ] = array_slice ( $ options [ 'align' ] , 0 ) ; $ this -> addTable ( $ titles , $ data , $ options , $ html ) ; }
Agregar una tabla al PDF removiendo aquellas columnas donde no existen
datos en la columna para todas las filas
@author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl)
@version 2016-10-06
Agregar una tabla al PDF removiendo aquellas columnas donde no existen datos en la columna para todas las filas