BaseEventTypeController::actionPDFPrint PHP Method

actionPDFPrint() public method

public actionPDFPrint ( $id )
    public function actionPDFPrint($id)
    {
        if (!($event = Event::model()->findByPk($id))) {
            throw new Exception("Event not found: {$id}");
        }
        $event->lock();
        // Ensure exclusivity of PDF to avoid race conditions
        $this->pdf_print_suffix .= Yii::app()->user->id . '_' . rand();
        if (!$event->hasPDF($this->pdf_print_suffix) || @$_GET['html']) {
            if (!$this->pdf_print_html) {
                ob_start();
                $this->actionPrint($id);
                $this->pdf_print_html = ob_get_contents();
                ob_end_clean();
            }
            $wk = new WKHtmlToPDF();
            $wk->setCanvasImagePath($event->imageDirectory);
            $wk->setDocuments($this->pdf_print_documents);
            $wk->setDocref($event->docref);
            $wk->setPatient($event->episode->patient);
            $wk->setBarcode($event->barcodeHTML);
            foreach (array('left', 'middle', 'right') as $section) {
                if (isset(Yii::app()->params['wkhtmltopdf_footer_' . $section . '_' . $this->event_type->class_name])) {
                    $setMethod = 'set' . ucfirst($section);
                    $wk->{$setMethod}(Yii::app()->params['wkhtmltopdf_footer_' . $section . '_' . $this->event_type->class_name]);
                }
            }
            foreach (array('top', 'bottom', 'left', 'right') as $margin) {
                if (isset(Yii::app()->params['wkhtmltopdf_' . $margin . '_margin_' . $this->event_type->class_name])) {
                    $setMethod = 'setMargin' . ucfirst($margin);
                    $wk->{$setMethod}(Yii::app()->params['wkhtmltopdf_' . $margin . '_margin_' . $this->event_type->class_name]);
                }
            }
            foreach (PDFFooterTag::model()->findAll('event_type_id = ?', array($this->event_type->id)) as $pdf_footer_tag) {
                if ($api = Yii::app()->moduleAPI->get($this->event_type->class_name)) {
                    $wk->setCustomTag($pdf_footer_tag->tag_name, $api->{$pdf_footer_tag->method}($event->id));
                }
            }
            $wk->generatePDF($event->imageDirectory, 'event', $this->pdf_print_suffix, $this->pdf_print_html, (bool) @$_GET['html']);
        }
        $event->unlock();
        if (@$_GET['html']) {
            return Yii::app()->end();
        }
        $pdf = $event->getPDF($this->pdf_print_suffix);
        header('Content-Type: application/pdf');
        header('Content-Length: ' . filesize($pdf));
        readfile($pdf);
        @unlink($pdf);
    }

Usage Example

Esempio n. 1
0
 public function actionPDFPrint($id)
 {
     if (@$_GET['vi']) {
         $this->pdf_print_suffix = 'vi';
     }
     return parent::actionPDFPrint($id);
 }
All Usage Examples Of BaseEventTypeController::actionPDFPrint
BaseEventTypeController