jeudi 28 février 2019

Print selected backend rows to Dynamic PDF

I've built a backend list in OctoberCMS and I have a button to create a PDF with alle the rows of this list. Each row produces one PDF page. But now I want to print only the selected rows? Does anyone know how to do this?

This is my code at the moment:

   public function export()
{
    $lists = $this->makeLists();
    $widget = reset($lists);

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

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

    $model = $widget->prepareModel();
    $results = $model->get();
    $records = [];
    foreach ($results as $result) {
        $record = [];
        foreach ($columns as $column) {
            $value = $widget->$getter($result, $column);
            if (is_array($value)) {
                $value = implode('|', $value);
            }
            $record[] = $value;
        }
        $records[] = $record;
    }
    return \Renatio\DynamicPDF\Classes\PDF::loadTemplate('export-data-pdf',
        ['headers' => $headers, 'records' => $records])->stream('export.pdf');
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire