345 : void
346 {
350 $this->irss,
351 $this->global_certificate_settings,
352 $this->stakeholder,
353 );
354 $current_template = $this->templateRepository->fetchPreviousCertificate(
$objId);
355 $currentVersion = $current_template->getVersion();
356 $nextVersion = $currentVersion + 1;
357 $current_background_rid = $this->irss->manageContainer()->find(
358 $current_template->getBackgroundImageIdentification()
359 );
360 $current_tile_image_rid = $this->irss->manageContainer()->find(
361 $current_template->getTileImageIdentification()
362 );
363 $old_background_image = $current_background_rid === null
364 ? $current_template->getBackgroundImagePath() :
365 '';
366 $old_tile_image = $current_tile_image_rid === null
367 ? $current_template->getTileImagePath() :
368 '';
369
370 $should_delete_background =
371 $this->httpWrapper->post()->retrieve(
372 'background_delete',
374 $this->refinery->kindlyTo()->bool(),
375 $this->refinery->always(false)
376 ])
377 );
378 $should_delete_tile_image =
379 $this->httpWrapper->post()->retrieve(
380 'certificate_card_tile_image_delete',
382 $this->refinery->kindlyTo()->bool(),
383 $this->refinery->always(false)
384 ])
385 );
386
387 $new_background_rid = $current_background_rid && !$should_delete_background ? $current_background_rid :
388 $this->global_certificate_settings->getBackgroundImageIdentification();
389 if (
390 is_string($new_background_rid) &&
391 is_string($this->global_certificate_settings->getBackgroundImageIdentification()) &&
392 $new_background_rid === $this->global_certificate_settings->getBackgroundImageIdentification()
393 ) {
394 if ($this->file_system->has($new_background_rid)) {
395 $new_background_rid = $this->irss->manage()->stream(
396 $this->file_system->readStream($new_background_rid),
397 $this->stakeholder
398 );
399 } else {
400 $old_background_image = $new_background_rid;
401 $new_background_rid = null;
402 }
403 }
404
405 $new_tile_rid = !$should_delete_tile_image ? $current_tile_image_rid : null;
407 try {
408 $this->settingsFormFactory->save($form_fields);
409
410 $templateValues = $this->placeholderDescriptionObject->getPlaceholderDescriptions();
411
412 if ($this->fileUpload->hasUploads()) {
413 if (!$this->fileUpload->hasBeenProcessed()) {
414 $this->fileUpload->process();
415 }
416 $new_background = $form->
getInput(
'background')[
'tmp_name'] ??
'';
417 $new_tile_image = $form->
getInput(
'certificate_card_tile_image')[
'tmp_name'] ??
'';
418 $results = $this->fileUpload->getResults();
419
420 if ($new_background !== '') {
421 $new_background_rid = $this->irss->manage()->upload(
423 $this->stakeholder
424 );
425 }
426
427 if ($new_tile_image !== '') {
428 $new_tile_rid = $this->irss->manage()->upload(
430 $this->stakeholder
431 );
432 }
433 }
434
435 $jsonEncodedTemplateValues = json_encode($templateValues, JSON_THROW_ON_ERROR);
436
437 if (isset($new_background_rid)) {
438 $old_background_image = '';
439 }
440 if (isset($new_tile_rid)) {
441 $old_tile_image = '';
442 }
443
444 $xslfo = $this->xlsFoParser->parse($form_fields);
445 $newHashValue = hash(
446 'sha256',
447 implode('', [
448 $xslfo,
449 isset($new_background_rid) ? $new_background_rid->serialize() : '',
450 $jsonEncodedTemplateValues,
451 isset($new_tile_rid) ? $new_background_rid->serialize() : '',
452 $old_background_image, $old_tile_image
453 ])
454 );
455
456 $active = (bool) ($form_fields['active'] ?? false);
457
458 if ($newHashValue !== $current_template->getCertificateHash()) {
462 $xslfo,
463 $newHashValue,
464 $jsonEncodedTemplateValues,
465 $nextVersion,
467 time(),
468 $active,
469 $old_background_image,
470 $old_tile_image,
471 isset($new_background_rid) ? $new_background_rid->serialize() : '',
472 isset($new_tile_rid) ? $new_tile_rid->serialize() : '',
473 );
474 $this->templateRepository->save($certificateTemplate);
475
477 $certificate_handler->handleResourceChange($current_background_rid);
478 }
480 $certificate_handler->handleResourceChange($current_tile_image_rid);
481 }
482
483 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
484 $this->
ctrl->redirect($this, self::EDITOR_COMMAND);
485 }
486
487 if (
488 $current_template->getId() !== null &&
489 $current_template->isCurrentlyActive() !== $active
490 ) {
491 $this->templateRepository->updateActivity($current_template, $active);
492 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'certificate_change_active_status'),
true);
493 $this->
ctrl->redirect($this, self::EDITOR_COMMAND);
494 }
495
496 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'certificate_same_not_saved'),
true);
497 $this->
ctrl->redirect($this, self::EDITOR_COMMAND);
498 }
catch (Exception
$e) {
499 $this->tpl->setOnScreenMessage(
500 'failure',
502 );
503 $this->
logger->error($e->getTraceAsString());
504 }
505 }
506
508
509 $this->tpl->setVariable(
'ADM_CONTENT', $form->
getHTML());
510 }
Class ResourceIdentification.
static _lookupType(int $id, bool $reference=false)
const ILIAS_VERSION_NUMERIC