<?php

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

namespace CGHTML2PDF;

/**
 * A class to generate a PDF tabular report given a tabular report definition.
 */
class pdf_tabular_report_generator extends \CGExtensions\reports\html_report_generator
{
    /**
     * @ignore
     */
    private $_orientation;

    /**
     * Set the page orientation.
     *
     * @param char $char Either L or P
     */
    public function set_orientation($char)
    {
        $char = strtoupper($char);
        switch( $char ) {
        case 'L':
        case 'P':
            $this->_orientation = $char;
            break;

        default:
            throw new \CmsInvalidDataException($char.' is not a valid orientation (P or L are accepted)');
        }
    }

    /**
     * Get report output.
     * this method outputs 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

        $parms = array();
        if( $this->_orientation ) $parms['orientation'] = $this->_orientation;
        $obj = new html2pdf($parms); // @todo:  options for this stuff
        $obj->SetTitle($this->report()->get_title());
        $obj->SetSubject($this->report()->get_description());
        $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

?>
