/**
  * Generate the report for given certificate
  *
  * @param srCertificate $cert
  * @throws ilException
  * @return bool
  */
 public function generate(srCertificate $cert)
 {
     if (!$this->isAvailable()) {
         throw new ilException("Generating certificates with TemplateTypeJasper is only available if the JasperReport service is installed");
     }
     require_once self::JASPER_CLASS;
     $template = $cert->getDefinition()->getType()->getCertificateTemplatesPath(true);
     // A template is required, so quit early if it does not exist for some reason
     if (!is_file($template)) {
         return false;
     }
     $placeholders = $cert->getPlaceholders();
     try {
         $defined_placeholders = $this->parseDefinedPlaceholders($template);
     } catch (Exception $e) {
         // XML is not valid
         return false;
     }
     // Only send defined placeholders to jasper, otherwise the template file is not considered as valid
     $placeholders = array_intersect_key($placeholders, $defined_placeholders);
     $placeholders = $this->nl2br($placeholders);
     $report = new JasperReport($template, $cert->getFilename(false));
     if ($locale = $this->pl->config('jasper_locale')) {
         $report->setLocale($this->pl->config('jasper_locale'));
     }
     if ($java = $this->pl->config('jasper_path_java')) {
         $report->setPathJava($java);
     }
     $report->setDataSource(JasperReport::DATASOURCE_EMPTY);
     $report->setParameters($placeholders);
     try {
         $report->generateOutput();
         $report_file = $report->getOutputFile();
         // Move pdf to correct certificate location
         $cert_path = $cert->getCertificatePath();
         if (!file_exists($cert_path)) {
             ilUtil::makeDirParents($cert_path);
         }
         $from = $report_file . '.pdf';
         $to = $cert->getFilePath();
         return ilUtil::moveUploadedFile($from, '', $to, false, 'rename');
     } catch (JasperReportException $e) {
         $this->log->write("srCertificateTemplyteTypeJasper::generate() Report file of certificate with ID {$cert->getId()} was not created by Jasper: " . implode(', ', $e->getErrors()));
         return false;
     }
 }