<?php

/**
 * This file contains the definition for the pdf_formatted_report_generator class.
 *
 * @package CGHTML2PDF
 * @category Utilities
 * @author  calguy1000 <calguy1000@cmsmadesimple.org>
 * @copyright Copyright 2014 by Robert Campbell
 */

namespace CGHTML2PDF;

/**
 * This class generates a PDF file from a formatted report definition.
 */
class pdf_formatted_report_generator extends \CGExtensions\reports\formatted_report_generator
{
    /**
     * Get the PDF output of the report.
     * This method sends the PDF file directly to the browser.
     */
    public function get_output()
    {
        // get the data that has been passed through a template
        $html = parent::get_output();
        if( !$html ) return; // todo: throw an exception

        $obj = new html2pdf(array()); // @todo:  options for this stuff
        $obj->SetTitle($this->report()->get_title()); // this can overridden in the html
        $obj->SetSubject($this->report()->get_description()); // this can be overridden in the html
        $email = \cge_userops::get_uid_email();
        if( $email ) $obj->SetAuthor($email);

        // todo ... stylesheet stuff (prepend to html)
        $obj->writeHTML($html);
        $obj->output('report.pdf','I');
    }

} // end of class

?>

