OphCoTherapyapplication_Processor::createAndSavePdfForSide PHP Method

createAndSavePdfForSide() protected method

create the PDF file as a ProtectedFile for the given side.
protected createAndSavePdfForSide ( CController $controller, array $template_data, string $side ) : ProtectedFile | null
$controller CController
$template_data array
$side string
return ProtectedFile | null
    protected function createAndSavePdfForSide(CController $controller, array $template_data, $side)
    {
        if ($html = $this->getPDFContentForSide($controller, $template_data, $side)) {
            $html = '<link rel="stylesheet" type="text/css" href="' . $controller->assetPath . '/css/print.css" />' . "\n" . $html;
            $this->event->lock();
            if (!$this->event->hasPDF('therapy_application')) {
                $wk = new WKHtmlToPDF();
                $wk->setDocuments(1);
                $wk->setDocRef($this->event->docref);
                $wk->setPatient($this->event->episode->patient);
                $wk->setBarcode($this->event->barcodeHTML);
                $wk->generatePDF($this->event->imageDirectory, 'event', 'therapy_application', $html, false, false);
            }
            $this->event->unlock();
            if (@$_GET['html']) {
                return Yii::app()->end();
            }
            $pfile = ProtectedFile::createForWriting('ECForm - ' . $side . ' - ' . $template_data['patient']->hos_num . '.pdf');
            if (!@copy($this->event->getPDF('therapy_application'), $pfile->getPath())) {
                throw new Exception('Unable to write to file: ' . $pfile->getPath());
            }
            if (!$pfile->save()) {
                throw new Exception('Unable to save file: ' . print_r($pfile->errors, true));
            }
            return $pfile;
        }
        return;
    }