public function exportFromList($definition = null, $options = [])
    {
        $lists = $this->controller->makeLists();

        $widget = $lists[$definition] ?? reset($lists);

        /*
         * Parse options
         */
        $defaultOptions = [
            'fileName' => $this->exportFileName,
            'delimiter' => ',',
            'enclosure' => '"'
        ];

        $options = array_merge($defaultOptions, $options);

        /*
         * Prepare CSV
         */
        $csv = CsvWriter::createFromFileObject(new SplTempFileObject);
        $csv->setDelimiter($options['delimiter']);
        $csv->setEnclosure($options['enclosure']);

        /*
         * Add headers
         */
        $headers = [];
        $columns = $widget->getVisibleColumns();
        foreach ($columns as $column) {
            $headers[] = Lang::get($column->label);
        }
        $csv->insertOne($headers);

        /*
         * Add records
         */
        $getter = $this->getConfig('export[useList][raw]', false)
            ? 'getColumnValueRaw'
            : 'getColumnValue';

        $query = $widget->prepareQuery();
        $results = $query->get();
        foreach ($results as $result) {
            $record = [];
            foreach ($columns as $column) {
                $value = $widget->$getter($result, $column);
                if (is_array($value)) {
                    $value = implode('|', $value);
                }
                $record[] = $value;
            }
            $csv->insertOne($record);
        }

        /*
         * Output
         */
        $csv->output($options['fileName']);
        exit;
    }
public function exportFromList($definition = null, $options = [])
    {
        $lists = $this->controller->makeLists();

        $widget = $lists[$definition] ?? reset($lists);

        /*
         * Parse options
         */
        $defaultOptions = [
            'fileName' => $this->exportFileName,
            'delimiter' => ',',
            'enclosure' => '"'
        ];

        $options = array_merge($defaultOptions, $options);

        /*
         * Prepare CSV
         */
        $csv = CsvWriter::createFromFileObject(new SplTempFileObject);
        $csv->setDelimiter($options['delimiter']);
        $csv->setEnclosure($options['enclosure']);

        /*
         * Add headers
         */
        $headers = [];
        $columns = $widget->getVisibleColumns();
        foreach ($columns as $column) {
            $headers[] = Lang::get($column->label);
        }
        $csv->insertOne($headers);

        /*
         * Add records
         */
        $getter = $this->getConfig('export[useList][raw]', false)
            ? 'getColumnValueRaw'
            : 'getColumnValue';

        $query = $widget->prepareQuery();
        $results = $query->get();
        foreach ($results as $result) {
            $record = [];
            foreach ($columns as $column) {
                $value = $widget->$getter($result, $column);
                if (is_array($value)) {
                    $value = implode('|', $value);
                }
                $record[] = $value;
            }
            $csv->insertOne($record);
        }

        /*
         * Output
         */
        $csv->output($options['fileName']);
        exit;
    }
public function exportFromList ( $ definition = null , $ options = [ ] ) { $ lists = $ this -> controller -> makeLists ( ) ; $ widget = $ lists [ $ definition ] ?? reset ( $ lists ) ; /*
         * Parse options
         */ $ defaultOptions = [ 'fileName' => $ this -> exportFileName , 'delimiter' => ',' , 'enclosure' => '"' ] ; $ options = array_merge ( $ defaultOptions , $ options ) ; /*
         * Prepare CSV
         */ $ csv = CsvWriter :: createFromFileObject ( new SplTempFileObject ) ; $ csv -> setDelimiter ( $ options [ 'delimiter' ] ) ; $ csv -> setEnclosure ( $ options [ 'enclosure' ] ) ; /*
         * Add headers
         */ $ headers = [ ] ; $ columns = $ widget -> getVisibleColumns ( ) ; foreach ( $ columns as $ column ) { $ headers [ ] = Lang :: get ( $ column -> label ) ; } $ csv -> insertOne ( $ headers ) ; /*
         * Add records
         */ $ getter = $ this -> getConfig ( 'export[useList][raw]' , false ) ? 'getColumnValueRaw' : 'getColumnValue' ; $ query = $ widget -> prepareQuery ( ) ; $ results = $ query -> get ( ) ; foreach ( $ results as $ result ) { $ record = [ ] ; foreach ( $ columns as $ column ) { $ value = $ widget -> $ getter ( $ result , $ column ) ; if ( is_array ( $ value ) ) { $ value = implode ( '|' , $ value ) ; } $ record [ ] = $ value ; } $ csv -> insertOne ( $ record ) ; } /*
         * Output
         */ $ csv -> output ( $ options [ 'fileName' ] ) ; exit ; }
Outputs the list results as a CSV export.
@param string $definition
@param array $options
@return void
Outputs the list results as a CSV export .