protected function processExportData($columns, $results, $options)
    {
        /*
         * Validate
         */
        if (!$results) {
            throw new ApplicationException(Lang::get('backend::lang.import_export.empty_error'));
        }

        /*
         * Parse options
         */
        $defaultOptions = [
            'firstRowTitles' => true,
            'useOutput' => false,
            'fileName' => 'export.csv',
            'delimiter' => null,
            'enclosure' => null,
            'escape' => null
        ];

        $options = array_merge($defaultOptions, $options);
        $columns = $this->exportExtendColumns($columns);

        /*
         * Prepare CSV
         */
        $csv = CsvWriter::createFromFileObject(new SplTempFileObject);
        
        $csv->setOutputBOM(CsvWriter::BOM_UTF8);

        if ($options['delimiter'] !== null) {
            $csv->setDelimiter($options['delimiter']);
        }

        if ($options['enclosure'] !== null) {
            $csv->setEnclosure($options['enclosure']);
        }

        if ($options['escape'] !== null) {
            $csv->setEscape($options['escape']);
        }

        /*
         * Add headers
         */
        if ($options['firstRowTitles']) {
            $headers = $this->getColumnHeaders($columns);
            $csv->insertOne($headers);
        }

        /*
         * Add records
         */
        foreach ($results as $result) {
            $data = $this->matchDataToColumns($result, $columns);
            $csv->insertOne($data);
        }

        /*
         * Output
         */
        if ($options['useOutput']) {
            $csv->output($options['fileName']);
        }

        /*
         * Save for download
         */
        $csvName = uniqid('oc');
        $csvPath = temp_path().'/'.$csvName;
        $output = $csv->__toString();

        File::put($csvPath, $output);

        return $csvName;
    }
protected function processExportData($columns, $results, $options)
    {
        /*
         * Validate
         */
        if (!$results) {
            throw new ApplicationException(Lang::get('backend::lang.import_export.empty_error'));
        }

        /*
         * Parse options
         */
        $defaultOptions = [
            'firstRowTitles' => true,
            'useOutput' => false,
            'fileName' => 'export.csv',
            'delimiter' => null,
            'enclosure' => null,
            'escape' => null
        ];

        $options = array_merge($defaultOptions, $options);
        $columns = $this->exportExtendColumns($columns);

        /*
         * Prepare CSV
         */
        $csv = CsvWriter::createFromFileObject(new SplTempFileObject);
        
        $csv->setOutputBOM(CsvWriter::BOM_UTF8);

        if ($options['delimiter'] !== null) {
            $csv->setDelimiter($options['delimiter']);
        }

        if ($options['enclosure'] !== null) {
            $csv->setEnclosure($options['enclosure']);
        }

        if ($options['escape'] !== null) {
            $csv->setEscape($options['escape']);
        }

        /*
         * Add headers
         */
        if ($options['firstRowTitles']) {
            $headers = $this->getColumnHeaders($columns);
            $csv->insertOne($headers);
        }

        /*
         * Add records
         */
        foreach ($results as $result) {
            $data = $this->matchDataToColumns($result, $columns);
            $csv->insertOne($data);
        }

        /*
         * Output
         */
        if ($options['useOutput']) {
            $csv->output($options['fileName']);
        }

        /*
         * Save for download
         */
        $csvName = uniqid('oc');
        $csvPath = temp_path().'/'.$csvName;
        $output = $csv->__toString();

        File::put($csvPath, $output);

        return $csvName;
    }
protected function processExportData ( $ columns , $ results , $ options ) { /*
         * Validate
         */ if ( ! $ results ) { throw new ApplicationException ( Lang :: get ( 'backend::lang.import_export.empty_error' ) ) ; } /*
         * Parse options
         */ $ defaultOptions = [ 'firstRowTitles' => true , 'useOutput' => false , 'fileName' => 'export.csv' , 'delimiter' => null , 'enclosure' => null , 'escape' => null ] ; $ options = array_merge ( $ defaultOptions , $ options ) ; $ columns = $ this -> exportExtendColumns ( $ columns ) ; /*
         * Prepare CSV
         */ $ csv = CsvWriter :: createFromFileObject ( new SplTempFileObject ) ; $ csv -> setOutputBOM ( CsvWriter :: BOM_UTF8 ) ; if ( $ options [ 'delimiter' ] !== null ) { $ csv -> setDelimiter ( $ options [ 'delimiter' ] ) ; } if ( $ options [ 'enclosure' ] !== null ) { $ csv -> setEnclosure ( $ options [ 'enclosure' ] ) ; } if ( $ options [ 'escape' ] !== null ) { $ csv -> setEscape ( $ options [ 'escape' ] ) ; } /*
         * Add headers
         */ if ( $ options [ 'firstRowTitles' ] ) { $ headers = $ this -> getColumnHeaders ( $ columns ) ; $ csv -> insertOne ( $ headers ) ; } /*
         * Add records
         */ foreach ( $ results as $ result ) { $ data = $ this -> matchDataToColumns ( $ result , $ columns ) ; $ csv -> insertOne ( $ data ) ; } /*
         * Output
         */ if ( $ options [ 'useOutput' ] ) { $ csv -> output ( $ options [ 'fileName' ] ) ; } /*
         * Save for download
         */ $ csvName = uniqid ( 'oc' ) ; $ csvPath = temp_path ( ) . '/' . $ csvName ; $ output = $ csv -> __toString ( ) ; File :: put ( $ csvPath , $ output ) ; return $ csvName ; }
Converts a data collection to a CSV file.
Converts a data collection to a CSV file .