Example #1
0
 /**
  * Create a pdf from template
  * @param integer $applicantId
  * @param integer $templateId
  */
 public function actionPdftemplate($applicantId, $templateId)
 {
     $applicant = $this->getApplicantById($applicantId);
     if ($template = $this->_application->getTemplateById($templateId)) {
         $pdf = new \Jazzee\TemplatePDF($this->_config->getPdflibLicenseKey(), $template, $this);
         $this->setVar('blob', $pdf->pdf($applicant));
         $this->setVar('filename', $applicant->getFullName() . '.pdf');
         $this->loadView('applicants_single/pdf');
     } else {
         $this->addMessage('error', 'That is not a valid template for this application.');
         $this->setLayoutVar('status', 'error');
     }
 }
Example #2
0
 /**
  * List all applicants
  */
 public function actionDownloadPdfArchive()
 {
     //use a full applicant display where display is needed
     $display = new \Jazzee\Display\FullApplication($this->_application);
     $applicants = empty($this->post['applicantIds']) ? array() : explode(',', $this->post['applicantIds']);
     // ensure garbage collection is on, we need it
     gc_enable();
     $directoryName = $this->_application->getProgram()->getShortName() . '-' . $this->_application->getCycle()->getName() . date('-mdy');
     $zipFile = $this->_config->getVarPath() . '/tmp/' . uniqid() . '.zip';
     $zip = new ZipArchive();
     $zip->open($zipFile, ZipArchive::CREATE);
     $zip->addEmptyDir($directoryName);
     $tmppath = $this->_config->getVarPath() . '/tmp';
     if ($this->post['pdftemplate'] == 'portrait' or $this->post['pdftemplate'] == 'landscape') {
         foreach (array_chunk($applicants, 20) as $limitedIds) {
             $applicantsDisplayArray = $this->_em->getRepository('Jazzee\\Entity\\Applicant')->findDisplayArrayByApplication($this->_application, $display, $limitedIds);
             foreach ($applicantsDisplayArray as $applicantArray) {
                 switch ($this->post['pdftemplate']) {
                     case 'portrait':
                         $pdf = new \Jazzee\ApplicantPDF($this->_config->getPdflibLicenseKey(), \Jazzee\ApplicantPDF::USLETTER_PORTRAIT, $this);
                         break;
                     case 'landscape':
                         $pdf = new \Jazzee\ApplicantPDF($this->_config->getPdflibLicenseKey(), \Jazzee\ApplicantPDF::USLETTER_LANDSCAPE, $this);
                         break;
                 }
                 $temp_file_name = tempnam($tmppath, 'JazzeeTempDL');
                 file_put_contents($temp_file_name, $pdf->pdfFromApplicantArray($this->_application, $applicantArray));
                 $externalIDSuffix = $applicantArray['externalId'] != null ? ' - ' . $applicantArray['externalId'] : "";
                 $zip->addFile($temp_file_name, $directoryName . '/' . $applicantArray['lastName'] . '_' . $applicantArray['firstName'] . $externalIDSuffix . '.pdf');
                 unset($pdf);
             }
         }
     } else {
         if (!($template = $this->_application->getTemplateById($this->post['pdftemplate']))) {
             throw new \Jazzee\Exception("Invalid template ID: " . $this->post['pdftemplate'] . ' for ' . $this->_application->getProgram()->getName());
         }
         foreach (array_chunk($applicants, 20) as $limitedIds) {
             $applicantsPDFTemplateArray = $this->_em->getRepository('Jazzee\\Entity\\Applicant')->findPDFTemplateArrayByApplication($this->_application, $display, $limitedIds);
             foreach ($applicantsPDFTemplateArray as $applicantArray) {
                 $pdf = new \Jazzee\TemplatePDF($this->_config->getPdflibLicenseKey(), $template, $this);
                 $temp_file_name = tempnam($tmppath, 'JazzeeTempDL');
                 file_put_contents($temp_file_name, $pdf->pdfFromApplicantArray($this->_application, $applicantArray));
                 $externalIDSuffix = $applicantArray['externalId'] != null ? ' - ' . $applicantArray['externalId'] : "";
                 $zip->addFile($temp_file_name, $directoryName . '/' . $applicantArray['lastName'] . '_' . $applicantArray['firstName'] . $externalIDSuffix . '.pdf');
                 unset($pdf);
             }
         }
     }
     $zip->close();
     $this->setVar('outputType', 'file');
     $this->setVar('type', 'application/zip');
     $this->setVar('filename', $directoryName . '.zip');
     $this->setVar('filePath', $zipFile);
     $this->loadView('applicants_grid/download');
 }