Skip to content

Commit

Permalink
Fix Certificate Template Saving with not migrated global Certificate …
Browse files Browse the repository at this point in the history
…Background

Signed Image Paths
  • Loading branch information
fhelfer authored and mjansenDatabay committed Oct 29, 2024
1 parent c455f3e commit b838342
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private function createPDFScalar(ilUserCertificate $certificate): string
$background_rid = $this->irss->manage()->find($certificate->getCurrentBackgroundImageUsed());
$background_src = '';
if ($background_rid instanceof ResourceIdentification) {
$background_src = $this->irss->consume()->src($background_rid)->getSrc();
$background_src = $this->irss->consume()->src($background_rid)->getSrc(true);

$certificateContent = str_replace(
['[BACKGROUND_IMAGE]'],
Expand All @@ -124,8 +124,6 @@ private function createPDFScalar(ilUserCertificate $certificate): string
);
}



$pdf_base64 = $this->rpcHelper->ilFO2PDF('RPCTransformationHandler', $certificateContent);

return $pdf_base64->scalar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function createForm(ilCertificateGUI $certificateGUI): ilPropertyFormGUI
$this->card_thumbnail_definition
);
$flavour_urls = $this->irss->consume()->flavourUrls($background_flavour);
foreach ($flavour_urls->getURLs() as $url) {
foreach ($flavour_urls->getURLs(true) as $url) {
/** @var string $url */
$bgimage->setImage($url);
}
Expand Down Expand Up @@ -245,7 +245,7 @@ public function createForm(ilCertificateGUI $certificateGUI): ilPropertyFormGUI
if ('' !== $thumbnail_image_identification) {
$identification = $this->irss->manage()->find($thumbnail_image_identification);
if ($identification instanceof ResourceIdentification) {
$thumbnailImage->setImage($this->irss->consume()->src($identification)->getSrc());
$thumbnailImage->setImage($this->irss->consume()->src($identification)->getSrc(true));
$allowThumbnailDeletion = true;
}
} elseif ($old_thumbnail_image_path !== '' && $this->filesystem->has($old_thumbnail_image_path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function exchangeCertificateVariables(

$identification = $this->irss->manage()->find($template->getBackgroundImageIdentification());
if ($identification instanceof ResourceIdentification) {
$backgroundImagePath = $this->irss->consume()->src($identification)->getSrc();
$backgroundImagePath = $this->irss->consume()->src($identification)->getSrc(true);
}

return str_replace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ public function listCertificates(): void
if ($thumbnail_image_identification === '' || $thumbnail_image_identification === '-') {
$thumbnail_image_identification = $certificateData['thumbnail_image_path'] ?? '';
if ($thumbnail_image_identification !== '' && $this->filesystem->has($thumbnail_image_identification)) {
$imagePath = ilFileUtils::getWebspaceDir() . $thumbnail_image_identification;
$imagePath = ilWACSignedPath::signFile(
ilFileUtils::getWebspaceDir() . $thumbnail_image_identification
);
}
} else {
$thumb_rid = $this->irss->manage()->find($thumbnail_image_identification);
Expand All @@ -179,7 +181,7 @@ public function listCertificates(): void
}

if ($imagePath === '') {
$imagePath = ilUtil::getImagePath('standard/icon_cert.svg');
$imagePath = ilWACSignedPath::signFile(ilUtil::getImagePath('standard/icon_cert.svg'));
}

$cardImage = $this->uiFactory->image()->standard(
Expand Down
20 changes: 19 additions & 1 deletion components/ILIAS/Certificate/classes/class.ilCertificateGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ilCertificateGUI
private readonly ilCertificateTemplateExportAction $exportAction;
private readonly ilCertificateTemplatePreviewAction $previewAction;
private readonly FileUpload $fileUpload;
private readonly Filesystem $file_system;
private readonly string $certificatePath;
private readonly ilPageFormats $pageFormats;
private readonly ilLogger $logger;
Expand All @@ -79,7 +80,7 @@ public function __construct(
ilCertificateTemplatePreviewAction $previewAction = null,
FileUpload $fileUpload = null,
private readonly ilSetting $settings = new ilSetting('certificate'),
Filesystem $fileSystem = null,
Filesystem $file_system = null,
Filesystem $tmp_file_system = null
) {
global $DIC;
Expand Down Expand Up @@ -138,6 +139,7 @@ public function __construct(
$this->irss
);
$this->fileUpload = $fileUpload ?? $DIC->upload();
$this->file_system = $file_system ?? $DIC->filesystem()->web();
$this->database = $DIC->database();
}

Expand Down Expand Up @@ -390,6 +392,22 @@ private function saveCertificate(ilPropertyFormGUI $form, array $form_fields, in
) {
$new_background_rid = null;
}
if (
is_string($new_background_rid) &&
is_string($this->global_certificate_settings->getBackgroundImageIdentification()) &&
$new_background_rid === $this->global_certificate_settings->getBackgroundImageIdentification()
) {
if ($this->file_system->has($new_background_rid)) {
$new_background_rid = $this->irss->manage()->stream(
$this->file_system->readStream($new_background_rid),
$this->stakeholder
);
} else {
$old_background_image = $new_background_rid;
$new_background_rid = null;
}
}

$new_thumbnail_rid = !$should_delete_thumbnail ? $current_thumbnail_rid : null;
if ($form->checkInput()) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ public function settings(): void
}
}
}
}#
}

if ($this->object->hasBackgroundImage()) {
$rid = $this->object->getBackgroundImageIdentification();
if ($rid instanceof ResourceIdentification) {
$bgimage->setImage($this->irss->consume()->src($rid)->getSrc());
$bgimage->setImage($this->irss->consume()->src($rid)->getSrc(true));
} elseif (is_string($rid)) {
$bgimage->setImage($rid);
}
Expand Down

0 comments on commit b838342

Please sign in to comment.