PodsUI::export PHP Method

export() public method

public export ( )
    public function export()
    {
        $export_type = pods_var('export_type', 'get', 'csv');
        $type = 'sv';
        // covers csv + tsv
        if (in_array($export_type, array('xml', 'json'))) {
            $type = $export_type;
        }
        $delimiter = ',';
        if ('tsv' == $export_type) {
            $delimiter = "\t";
        }
        $columns = array();
        if (empty($this->fields['export'])) {
            $this->fields['export'] = $this->pod->fields;
            $columns = array($this->pod->pod_data['field_id'] => 'ID');
        }
        foreach ($this->fields['export'] as $field) {
            $columns[$field['name']] = $field['label'];
        }
        $params = array('full' => true, 'flatten' => true, 'fields' => array_keys($columns), 'type' => $type, 'delimiter' => $delimiter, 'columns' => $columns);
        $items = $this->get_data($params);
        $data = array('columns' => $columns, 'items' => $items, 'fields' => $this->fields['export']);
        $migrate = pods_migrate($type, $delimiter, $data);
        $migrate->export();
        $export_file = $migrate->save();
        $this->message(sprintf(__('<strong>Success:</strong> Your export is ready, you can download it <a href="%s" target="_blank">here</a>', 'pods'), $export_file));
        //echo '<script type="text/javascript">window.open("' . esc_js( $export_file ) . '");</script>';
        $this->get_data();
    }