public function __construct($invoice) { parent::__construct(); $this->setTo($invoice->customer_email, $invoice->customer_name); // To get all the properties loaded for the template foreach ($invoice->Items as $it) { $it->refreshRelated(); } $data[] = $invoice; $model = get_class($invoice); $printer = new Printer($model, TemplateTable::getTemplateForModel($model)->getId()); try { $body = $printer->render($data); $pdf = $printer->renderPdf($data)->output(); $attachment = new Swift_Attachment($pdf, $model . '-' . $invoice->getId() . '.pdf', 'application/pdf'); $this->setSubject(PropertyTable::get('company_name') . ' [' . $model . ': ' . $invoice . ']')->setBody($printer->render($data), 'text/html')->attach($attachment); $this->setReadyState(true); } catch (LogicException $e) { $this->setReadyState(false); } }
private function render($model = 'Invoice', $pdf = false) { sfConfig::set('sf_web_debug', false); $template = TemplateTable::getTemplateForModel($model); $printer = new Printer($model, $template->getId()); $data = $this->getInvoiceDataFromRequest($this->getRequest()); return $pdf ? $printer->renderPdf($data) : $printer->render($data); }