Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace FacturaScripts\Core\Lib;
- use FacturaScripts\Core\Base\ExportInterface;
- class CSVExport implements ExportInterface
- {
- use \FacturaScripts\Core\Base\Utils;
- public function newDoc($model)
- {
- $tableData = [];
- foreach ((array) $model as $key => $value) {
- if (is_string($value)) {
- $tableData[] = [$key, $this->fixHtml($value)];
- }
- }
- $fp = fopen('doc.csv', 'w');
- // Encabezado
- fputcsv($fp, ['key', 'value']);
- // Cuerpo
- foreach ($tableData as $tableRow) {
- fputcsv($fp, $tableRow);
- }
- fclose($fp);
- }
- public function newListDoc($cursor, $columns)
- {
- $tableCols = [];
- $tableData = [];
- if (!empty($cursor)) {
- // obtenemos las columnas
- foreach ($columns as $col) {
- $tableCols[$col->widget->fieldName] = $col->widget->fieldName;
- }
- foreach ($cursor as $key => $row) {
- foreach ($tableCols as $col) {
- $value = $row->{$col};
- if (is_string($value)) {
- $value = $this->fixHtml($value);
- }
- $tableData[$key][] = $value;
- }
- }
- $fp = fopen('list.csv', 'w');
- // Encabezado
- fputcsv($fp, $tableCols);
- // Cuerpo
- foreach ($tableData as $tableRow) {
- fputcsv($fp, $tableRow);
- }
- fclose($fp);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement