pdfOptions = $config['pdfOptions']; } } // custom implementations protected function initialize() { // output method must be passed into parent through user state if (isset($this->pdfOptions['out'])) { $this->app->setUserState('pdf.out', $this->pdfOptions['out']); } else { $this->app->setUserState('pdf.out', 'D'); } parent::initialize(); // when we create if (isset($this->pdfOptions['templateId'])) { $this->id = $this->pdfOptions['templateId']; } else { $this->id = $this->app->getUserState('visforms'. $this->fid . '.pdf.tmplid'); } if (isset($this->pdfOptions['fid'])) { $this->fid = $this->pdfOptions['fid']; } } protected function initializeModels() { // get pdf model $this->pdfModel = new VispdfModel(array('ignore_request' => true)); $this->pdfItem = $this->pdfModel->getItem($this->id); $this->pdfForm = $this->pdfModel->getForm(); // get form model $this->formModel = new VisformModel(array('ignore_request' => true)); $this->formItem = $this->formModel->getItem($this->fid); // formForm is not used but trying it from the model twices causes errors //$this->formForm = $this->formModel->getForm(); // get data // only data, which the user has permission to export are set to user state in controller (Check permission is done in the ocntroller) $this->pdfData = $this->pdfItem->data; $this->dataItems = $this->app->getUserState('visforms'. $this->fid . '.pdf.datas'); $this->dataFields = $this->app->getUserState('visforms'. $this->fid . '.pdf.datafields'); $this->prepareDataFields(); if ($this->app->getUserState('visforms'. $this->fid . '.pdf.pdftask', '') === 'renderPdfFromRequestData') { // Clear data from user state; uncomment to following 3 lines $this->app->setUserState('visforms'. $this->fid . '.pdf.tmplid', null); $this->app->setUserState('visforms'. $this->fid . '.pdf.datas', null); $this->app->setUserState('visforms'. $this->fid . '.pdf.datafields', null); $this->app->setUserState('visforms'. $this->fid . '.pdf.pdftask', null); } } protected function initializePayLoad() { parent::initializePayLoad(); // use pdf title as default file name // base implementation uses form name // as we can attach/download multiple templates for one submission, this would be confusing $this->pdfOutputName = $this->pdfItem->title . '.pdf'; } // view can be called from frontend // make sure that we only render a pdf document if the pdf id is set in the user state or via config['pdfOptions'] // the user permissions are already check at the point, where the tmplId is set in the user state/config['pdfOptions'] public function display($tpl = null) { if (!AefHelper::checkAEF()) { return false; } $tmplId = $this->app->getUserState('visforms'. ($this->input->get('fid', '0')) . '.pdf.tmplid', 0); if (isset($this->pdfOptions['templateId'])) { $tmplId = (int) $this->pdfOptions['templateId']; } if (empty($tmplId)) { return false; } $model = New VisrenderpdfModel(array()); $this->setModel($model, true); return parent::display($tpl); } }