/** * Generate the preview certificate * * @throws srCertificateException * @return bool|void */ public function generate() { if (!$this->getDefinitionId()) { throw new srCertificateException("srCertificatePreview needs definition id before generating preview file"); } $cert_type = $this->definition->getType(); $template_type = srCertificateTemplateTypeFactory::getById($cert_type->getTemplateTypeId()); return $template_type->generate($this); }
/** * @param array $a_set */ public function fillRow($a_set) { $this->tpl->setVariable('TITLE', $a_set['title']); $this->tpl->setVariable('DESCRIPTION', $a_set['description']); $this->tpl->setVariable('LANGUAGES', implode(', ', $a_set['languages'])); $template_type = srCertificateTemplateTypeFactory::getById((int) $a_set['template_type_id']); $this->tpl->setVariable('TEMPLATE_TYPE_ID', $template_type->getTitle()); $this->tpl->setVariable('ROLES', is_array($a_set['roles']) ? implode(',', $a_set['roles']) : ''); $this->tpl->setVariable('AVAILABLE_OBJECTS', implode(',', $a_set['available_objects'])); $this->tpl->setVariable('ACTIONS', $this->buildActionMenu($a_set)->getHTML()); }
/** * Download template file */ public function downloadTemplate() { if (is_file($this->type->getCertificateTemplatesPath(true))) { $filename = srCertificateTemplateTypeFactory::getById($this->type->getTemplateTypeId())->getTemplateFilename(); ilUtil::deliverFile($this->type->getCertificateTemplatesPath(true), $filename); } $this->editTemplate(); }
/** * Get an array of all assets stored along with the certificate * * @return array */ public function getAssets() { if (!is_dir($this->getCertificateTemplatesPath())) { ilUtil::makeDirParents($this->getCertificateTemplatesPath()); } $files = scandir($this->getCertificateTemplatesPath()); $tpl_filename = srCertificateTemplateTypeFactory::getById($this->getTemplateTypeId())->getTemplateFilename(); $ignore = array('.', '..', '.DS_Store', $tpl_filename); foreach ($files as $k => $file) { if (in_array($file, $ignore)) { unset($files[$k]); } } return $files; }
/** * Init form */ protected function initForm() { $this->setFormAction($this->ctrl->getFormAction($this->parent_gui)); $this->setTitle($this->pl->txt('edit_type_template')); $types_available = array(); $types = array(srCertificateTemplateTypeFactory::getById(srCertificateTemplateType::TEMPLATE_TYPE_HTML), srCertificateTemplateTypeFactory::getById(srCertificateTemplateType::TEMPLATE_TYPE_JASPER)); /** @var $type srCertificateTemplateType */ foreach ($types as $type) { if ($type->isAvailable()) { $types_available[$type->getId()] = $type->getTitle(); } } if (!count($types_available)) { ilUtil::sendInfo($this->pl->txt('msg_no_template_types')); } $item = new ilSelectInputGUI($this->pl->txt('template_type_id'), 'template_type_id'); $item->setOptions($types_available); $item->setRequired(true); $item->setValue($this->type->getTemplateTypeId()); $this->addItem($item); $item = new ilFileInputGUI($this->pl->txt('template_file'), 'template_file'); $template_file = $this->type->getCertificateTemplatesPath(true); if (is_file($template_file)) { $item->setValue($template_file); } $item->setFilename($template_file); $item->setInfo($this->pl->txt('template_file_info')); $item->setRequired(!is_file($template_file)); $this->addItem($item); $assets = $this->type->getAssets(); if (count($assets)) { $item = new ilMultiSelectInputGUI($this->pl->txt('assets'), 'remove_assets'); $options = array(); foreach ($assets as $asset) { $options[$asset] = $asset; } $item->setOptions($options); $item->setInfo($this->pl->txt('assets_info')); $this->addItem($item); } $item = new ilFileWizardInputGUI($this->pl->txt('add_assets'), 'add_assets'); $item->setFilenames(array(0 => '')); $this->addItem($item); $this->addCommandButton('downloadDefaultTemplate', $this->pl->txt('download_default_template')); if (is_file($this->type->getCertificateTemplatesPath(true))) { $this->addCommandButton('downloadTemplate', $this->pl->txt('download_template')); } $this->addCommandButton('updateTemplate', $this->lng->txt('save')); }
/** * Generate certificate pdf * * @param bool $force If true, recreates the PDF if already existing * @return bool */ public function generate($force = false) { // Don't generate certificate if a PDF is already existing, unless $force is set to true if ($this->getStatus() == self::STATUS_PROCESSED && is_file($this->getFilePath()) && !$force) { return false; } $cert_type = $this->getDefinition()->getType(); $template_type = srCertificateTemplateTypeFactory::getById($cert_type->getTemplateTypeId()); $this->setStatus(self::STATUS_WORKING); $this->update(); $generated = $template_type->generate($this); // Only set the status to processed if generating was successful if ($generated) { $this->setStatus(self::STATUS_PROCESSED); $this->update(); return true; } else { $this->setStatus(self::STATUS_FAILED); $this->update(); $this->log->write("srCertificate::generate() Failed to generate certificate with ID {$this->getId()}"); return false; } }